Changeset 653 for abuse/trunk/src/imlib/palette.cpp
- Timestamp:
- May 14, 2011, 4:00:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/palette.cpp
r555 r653 56 56 } 57 57 58 int palette::find_closest(u nsigned char r, unsigned char g, unsigned charb)58 int palette::find_closest(uint8_t r, uint8_t g, uint8_t b) 59 59 { 60 60 unsigned char *cl=(unsigned char *)addr(); … … 71 71 } 72 72 73 74 int palette::find_closest_non0(unsigned char r, unsigned char g, unsigned char b) 75 { 76 unsigned char *cl=(unsigned char *)addr()+3; 77 int c=1,d=0x7fffffff,i,nd; 78 for (i=1; i<256; i++) 79 { 80 nd=((int)r-(int)(*cl))*((int)r-(int)(*cl)); cl++; 81 nd+=((int)g-(int)(*cl))*((int)g-(int)(*cl)); cl++; 82 nd+=((int)b-(int)(*cl))*((int)b-(int)(*cl)); cl++; 83 if (nd<d) 84 { c=i; d=nd; } 85 } 86 return c; 87 } 88 89 90 int palette::find_color(unsigned char r, unsigned char g, unsigned char b) 73 int palette::find_color(uint8_t r, uint8_t g, uint8_t b) 91 74 { 92 75 int i,ub,mask,find; … … 210 193 b=color_num%8; 211 194 return (usd[x]&(128>>b)); 212 }213 214 int palette::add_color(unsigned int r, int unsigned g, int unsigned b, int closest_only)215 {216 int i,f,u,c;217 if (!closest_only)218 {219 for (i=ncolors-1,f=-1,u=-1; i>=0 && f<0; i--)220 {221 if (used(i))222 {223 if (pal[i].red==r && pal[i].green==g && pal[i].blue==b)224 f=i;225 }226 else227 u=i;228 }229 } else { f=-1; u=-1; }230 if (f<0)231 {232 if (u>=0)233 { pal[u].red=r;234 pal[u].green=g;235 pal[u].blue=b;236 set_used(u);237 f=u;238 }239 else240 {241 for (i=0,f=0,u=10000; i<ncolors; i++)242 { c=(pal[i].red-r)*(pal[i].red-r)+243 (pal[i].green-g)*(pal[i].green-g)+244 (pal[i].blue-b)*(pal[i].blue-b);245 if (c<u)246 { f=i;247 u=c;248 }249 }250 }251 }252 return f;253 195 } 254 196 … … 430 372 } 431 373 432 void quant_palette::add_color(unsigned char r, unsigned char g, unsigned char b)433 {434 quant_node **p,*fat;435 int lev,cn,stop;436 p=&root;437 lev=0;438 stop=0;439 fat=NULL;440 if (nc>=mx-1)441 prune();442 while (!stop)443 {444 lev++;445 if (!(*p))446 {447 if (lev>2 && !fat)448 printf("h");449 (*p)=new quant_node(lev,fat);450 level[lev-1].add_end(*p);451 }452 453 if (!(*p)->is_leaf())454 {455 cn=((r&(256>>lev))!=0)<<2;456 cn+=((g&(256>>lev))!=0)<<1;457 cn+=((b&(256>>lev))!=0);458 fat=(*p);459 p=&((*p)->children[cn]);460 } else stop=1;461 462 }463 (*p)->set(r,g,b);464 if (!(*p)->tot)465 nc++;466 (*p)->tot++;467 }468 469 palette *quant_palette::create_pal()470 {471 palette *p;472 int i,x;473 quant_node *pn;474 p=new palette(mx);475 for (x=0,i=7; i>=0; i++)476 for (pn=(quant_node *)level[i].first();477 pn!=(quant_node *)level[i].first(); pn=(quant_node *)pn->Next())478 if (pn->is_leaf())479 p->set(x++,pn->red,pn->green,pn->blue);480 return p;481 }482 483 374 quant_palette::~quant_palette() 484 375 { … … 490 381 } 491 382 492 u nsigned charpalette::brightest(int all)493 { u nsigned charr,g,b,bri;383 uint8_t palette::brightest(int all) 384 { uint8_t r,g,b,bri; 494 385 unsigned i; 495 386 long brv; … … 510 401 } 511 402 512 u nsigned charpalette::darkest(int all, int noblack)513 { u nsigned charr,g,b,bri;403 uint8_t palette::darkest(int all, int noblack) 404 { uint8_t r,g,b,bri; 514 405 unsigned i; 515 406 long brv,x;
Note: See TracChangeset
for help on using the changeset viewer.