Changeset 115 for abuse/trunk/src/imlib/filter.cpp
- Timestamp:
- Mar 16, 2008, 10:51:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/filter.cpp
r114 r115 98 98 int color_compare(void *c1, void *c2) 99 99 { 100 long v1,v2; 100 long v1,v2; 101 101 unsigned char r1,g1,b1,r2,g2,b2; 102 102 compare_pal->get( *((unsigned char *)c1),r1,g1,b1); … … 106 106 if (v1<v2) return -1; 107 107 else if (v1>v2) return 1; 108 else return 0; 108 else return 0; 109 109 } 110 110 … … 114 114 unsigned char map[256],*last_start,*start; 115 115 int i,last_color=0,color; 116 compare_pal=pal; 116 compare_pal=pal; 117 117 for (i=0;i,256;i++) 118 118 map[i]=i; 119 119 120 qsort(map,1,1,color_compare); 120 qsort(map,1,1,color_compare); 121 121 colors=1<<color_bits; 122 122 last_start=color_table=(unsigned char *)malloc(colors*colors*colors); 123 123 124 125 124 125 126 126 last_color=map[0]; 127 127 last_dist=0; 128 129 128 129 130 130 for (i=1;i<colors;i++) 131 { 131 { 132 132 color=map[i<<(8-color_bits)]; 133 dist= 133 dist= 134 134 135 135 memset(c, 136 136 } 137 138 137 138 139 139 }*/ 140 140 141 141 142 142 color_filter::color_filter(palette *pal, int color_bits, void (*stat_fun)(int)) 143 { 143 { 144 144 color_bits=5; // hard code 5 for now 145 145 int r,g,b,rv,gv,bv, … … 147 147 lshift=8-color_bits; 148 148 unsigned char *pp; 149 149 150 150 long dist_sqr,best; 151 151 int colors=1<<color_bits; … … 154 154 { 155 155 if (stat_fun) stat_fun(r); 156 rv=r<<lshift; 156 rv=r<<lshift; 157 157 for (g=0;g<colors;g++) 158 158 { 159 gv=g<<lshift; 159 gv=g<<lshift; 160 160 for (b=0;b<colors;b++) 161 161 { 162 bv=b<<lshift; 162 bv=b<<lshift; 163 163 best=0x7fffffff; 164 164 for (i=0,pp=(unsigned char *)pal->addr();i<max;i++) 165 { 165 { 166 166 register long rd=*(pp++)-rv, 167 167 gd=*(pp++)-gv, 168 168 bd=*(pp++)-bv; 169 169 170 170 dist_sqr=(long)rd*rd+(long)bd*bd+(long)gd*gd; 171 171 if (dist_sqr<best) … … 177 177 } 178 178 } 179 } 179 } 180 180 } 181 181 … … 203 203 204 204 205 void filter::put_image(image *screen, image *im, short x, short y, char transparent) 206 { 207 short cx1,cy1,cx2,cy2,x1=0,y1=0,x2=im->width()-1,y2=im->height()-1; 208 screen->get_clip(cx1,cy1,cx2,cy2); 209 210 // see if the image gets clipped off the screen 211 if (x>cx2 || y>cy2 || x+(x2-x1)<cx1 || y+(y2-y1)<cy1) return ; 212 213 if (x<cx1) 214 { x1+=(cx1-x); x=cx1; } 215 if (y<cy1) 216 { y1+=(cy1-y); y=cy1; } 217 218 if (x+x2-x1+1>cx2) 219 { x2=cx2-x+x1; } 220 221 if (y+y2-y1+1>cy2) 222 { y2=cy2-y+y1; } 223 if (x1>x2 || y1>y2) return ; 224 225 226 227 228 int xl=x2-x1+1; 229 int yl=y2-y1+1; 230 231 screen->add_dirty(x,y,x+xl-1,y+yl-1); 232 233 uint8_t *pg1=screen->scan_line(y),*source,*dest; 234 uint8_t *pg2=im->scan_line(y1); 235 int i; 236 for (int j=0;j<yl;j++) 237 { 238 for (i=0,source=&pg2[x1],dest=&pg1[x];i<xl;i++,source++,dest++) 239 if (!transparent || *source!=current_background) 240 *dest=fdat[*source]; 241 pg1=screen->next_line(y+j,pg1); 242 pg2=im->next_line(y1+j,pg2); 243 } 244 245 } 246 247 248 249 250 205 void filter::put_image(image *screen, image *im, short x, short y, 206 char transparent) 207 { 208 short cx1, cy1, cx2, cy2, x1 = 0, y1 = 0, 209 x2 = im->width() - 1, y2 = im->height() - 1; 210 screen->get_clip(cx1,cy1,cx2,cy2); 211 212 // see if the image gets clipped off the screen 213 if(x > cx2 || y > cy2 || x + (x2 - x1) < cx1 || y + (y2 - y1) < cy1) 214 return; 215 216 if(x < cx1) 217 { 218 x1 += (cx1 - x); 219 x = cx1; 220 } 221 if(y < cy1) 222 { 223 y1 += (cy1 - y); 224 y = cy1; 225 } 226 227 if(x + x2 - x1 + 1 > cx2) 228 x2 = cx2 - x + x1; 229 230 if(y + y2 - y1 + 1 > cy2) 231 y2 = cy2 - y + y1; 232 233 if(x1 > x2 || y1 > y2) 234 return; 235 236 int xl = x2 - x1 + 1; 237 int yl = y2 - y1 + 1; 238 239 screen->add_dirty(x, y, x + xl - 1, y + yl - 1); 240 241 screen->lock(); 242 im->lock(); 243 244 uint8_t *pg1 = screen->scan_line(y), *source, *dest; 245 uint8_t *pg2 = im->scan_line(y1); 246 int i; 247 for(int j = 0; j < yl; j++) 248 { 249 for(i = 0, source = &pg2[x1], dest = &pg1[x]; 250 i < xl; 251 i++, source++, dest++) 252 { 253 if(!transparent || *source != current_background) 254 *dest=fdat[*source]; 255 } 256 pg1 = screen->next_line(y + j, pg1); 257 pg2 = im->next_line(y1 + j, pg2); 258 } 259 260 im->unlock(); 261 screen->unlock(); 262 } 263
Note: See TracChangeset
for help on using the changeset viewer.