Changeset 115
- Timestamp:
- Mar 16, 2008, 10:51:54 PM (14 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/automap.cpp
r111 r115 59 59 if (draw_xstart==old_dx && draw_ystart==old_dy) 60 60 { 61 automap_window->screen->lock(); 61 62 automap_window->screen->add_dirty(centerx,centery,centerx,centery); 62 63 if ((tick++)&4) … … 64 65 else 65 66 automap_window->screen->putpixel(centerx,centery,27); 67 automap_window->screen->unlock(); 66 68 return ; 67 69 } … … 138 140 139 141 140 // draw the person as a dot, no need to add a dirty because we marked the whole screen already 142 // draw the person as a dot, no need to add a dirty because we marked the 143 // whole screen already 144 automap_window->screen->lock(); 141 145 if ((tick++)&4) 142 146 automap_window->screen->putpixel(centerx,centery,255); 143 147 else 144 148 automap_window->screen->putpixel(centerx,centery,27); 149 automap_window->screen->unlock(); 145 150 146 151 // set the clip back to full window size because soemthing else could mess with the area -
abuse/trunk/src/dev.cpp
r113 r115 391 391 new_height-=y+new_height-cy2; 392 392 393 393 screen->lock(); 394 im->lock(); 394 395 for (iy=iy_start;new_height>0;new_height--,y++,iy+=ystep) 395 396 { … … 399 400 *sl2=sl1[ix>>16]; 400 401 } 402 im->unlock(); 403 screen->unlock(); 401 404 } 402 405 … … 431 434 432 435 uint8_t d; 436 screen->lock(); 433 437 for (iy=iy_start;new_height>0;new_height--,y++,iy+=ystep) 434 438 { … … 442 446 } 443 447 } 448 screen->unlock(); 444 449 } 445 450 -
abuse/trunk/src/game.cpp
r113 r115 897 897 else 898 898 screen->clear(wm->black()); 899 screen->lock(); 899 900 for(y = y1, draw_y = yo; y <= y2; y++, draw_y += yinc) 900 901 { … … 921 922 } 922 923 } 924 screen->unlock(); 923 925 924 926 if(dev & EDIT_MODE) -
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 -
abuse/trunk/src/imlib/glread.cpp
r56 r115 41 41 while (first<=last) 42 42 { 43 sub->lock(); 43 44 for (y=0;(int)y<(int)height;y++) 44 45 { … … 46 47 sub->unpack_scanline(y); 47 48 } 49 sub->unlock(); 48 50 sub->put_image(im,(first%32)*width,(first/32)*height); 49 51 first++; … … 55 57 image *read_pic(char *fn, palette *&pal) 56 58 { 57 image *im ;59 image *im = NULL; 58 60 char x[4],bpp; 59 61 uint8_t *sl=NULL,esc,c,n,marker,vmode; … … 61 63 int xx,yy; 62 64 FILE *fp; 63 im=NULL;64 65 fp=fopen(fn,"rb"); 65 66 … … 74 75 { fclose(fp); set_error(imFILE_CORRUPTED); return NULL; } 75 76 76 im =new image(w,h);77 im = new image(w, h); 77 78 78 79 fread(&vmode,1,1,fp); … … 92 93 93 94 yy=h; xx=w; 95 96 im->lock(); 94 97 95 98 while (blocks-- && w>=1 && yy>=0) … … 137 140 } 138 141 } 142 143 im->unlock(); 144 139 145 fclose(fp); 140 146 return im; -
abuse/trunk/src/imlib/image.cpp
r114 r115 36 36 "Error occurred while writing, (disk full?)" 37 37 }; 38 38 39 39 40 40 int16_t imerror=0; … … 49 49 { printf("Program stopped, error : "); 50 50 if (imerror<=imMAX_ERROR) 51 printf("%s\n", imerr_messages[imerror]);51 printf("%s\n", imerr_messages[imerror]); 52 52 else 53 53 printf("Unsonsponsered error code, you got trouble\n"); … … 57 57 nosound(); 58 58 #else 59 printf("%c%c\n", 7,8);59 printf("%c%c\n", 7, 8); 60 60 #endif 61 61 exit(1); … … 78 78 79 79 image_descriptor::image_descriptor(int16_t length, int16_t height, 80 80 int keep_dirties, int static_memory) 81 81 82 82 { clipx1=0; clipy1=0; … … 92 92 w=new_width; 93 93 h=new_height; 94 make_page(new_width, new_height,page);94 make_page(new_width, new_height, page); 95 95 } 96 96 97 97 image::~image() 98 98 { 99 image_list.unlink((linked_node *)this); 100 delete_page(); 101 if (special) 102 delete special; 103 99 if(_locked) 100 { 101 fprintf(stderr, "Error: image is locked upon deletion\n"); 102 unlock(); 103 } 104 105 image_list.unlink((linked_node *)this); 106 delete_page(); 107 if(special) 108 delete special; 104 109 } 105 110 … … 107 112 void make_block(size_t size) 108 113 { 109 void *dat=jmalloc(size, "make_block : tmp");110 CONDITION(dat, "Memory error : could not make block\n");114 void *dat=jmalloc(size, "make_block : tmp"); 115 CONDITION(dat, "Memory error : could not make block\n"); 111 116 if (dat) jfree((char *)dat); 112 117 } … … 125 130 if (special) 126 131 { if (x>=special->x1_clip() && x<=special->x2_clip() && 127 132 y>=special->y1_clip() && y<=special->y2_clip()) 128 133 (*(scan_line(y)+x))=color; 129 134 } else (*(scan_line(y)+x))=color; … … 138 143 { 139 144 if (create_descriptor==2) 140 special=new image_descriptor(width, height,1,(page_buffer!=NULL));141 else special=new image_descriptor(width, height,0,(page_buffer!=NULL));145 special=new image_descriptor(width, height, 1, (page_buffer!=NULL)); 146 else special=new image_descriptor(width, height, 0, (page_buffer!=NULL)); 142 147 } else special=NULL; 143 make_page(width, height,page_buffer);148 make_page(width, height, page_buffer); 144 149 image_list.add_end((linked_node *) this); 150 _locked = false; 145 151 } 146 152 … … 148 154 { 149 155 int16_t i; 150 fp->seek(e->offset, 0);156 fp->seek(e->offset, 0); 151 157 w=fp->read_uint16(); 152 158 h=fp->read_uint16(); 153 159 special=NULL; 154 make_page(w, h,NULL);155 for (i=0; i<h;i++)156 fp->read(scan_line(i), w);160 make_page(w, h, NULL); 161 for (i=0; i<h; i++) 162 fp->read(scan_line(i), w); 157 163 image_list.add_end((linked_node *) this); 164 _locked = false; 158 165 } 159 166 … … 164 171 h=fp->read_uint16(); 165 172 special=NULL; 166 make_page(w, h,NULL);167 for (i=0; i<h;i++)168 fp->read(scan_line(i), w);173 make_page(w, h, NULL); 174 for (i=0; i<h; i++) 175 fp->read(scan_line(i), w); 169 176 image_list.add_end((linked_node *) this); 177 _locked = false; 178 } 179 180 void image::lock() 181 { 182 /* This is currently a no-op, because it's unneeded with SDL */ 183 184 if(_locked) 185 fprintf(stderr, "Trying to lock a locked picture!\n"); 186 _locked = true; 187 } 188 189 void image::unlock() 190 { 191 /* This is currently a no-op, because it's unneeded with SDL */ 192 193 if(!_locked) 194 fprintf(stderr, "Trying to unlock an unlocked picture!\n"); 195 _locked = false; 170 196 } 171 197 172 198 void image_uninit() 173 199 { 200 /* FIXME: is this used at all? */ 174 201 /* image *im; 175 202 while (image_list.first()) … … 188 215 { 189 216 uint8_t bt[2]; 190 uint16_t wrd, *up;217 uint16_t wrd, *up; 191 218 bt[0]=1; 192 219 bt[1]=0; … … 195 222 if (wrd!=0x01) 196 223 { printf("compiled with wrong endianness, edit system.h and try again\n"); 197 printf("1 (intel) = %d\n", (int)wrd);224 printf("1 (intel) = %d\n", (int)wrd); 198 225 exit(1); 199 226 } … … 204 231 int32_t image::total_pixels(uint8_t background) 205 232 { 206 int16_t i,j; 207 int32_t co; 208 uint8_t *c; 209 for (co=0,i=height()-1;i>=0;i--) 210 { c=scan_line(i); 211 for (j=width()-1;j>=0;j--,c++) 212 if (*c!=background) co++; 213 } 214 return co; 233 int16_t i, j; 234 int32_t co; 235 uint8_t *c; 236 237 lock(); 238 for(co = 0, i = height() - 1; i >= 0; i--) 239 { 240 c = scan_line(i); 241 for(j = width() - 1; j >= 0; j--, c++) 242 if(*c != background) co++; 243 } 244 unlock(); 245 return co; 215 246 } 216 247 217 248 void image::clear(int16_t color) 218 249 { 219 int16_t i; 220 if (color==-1) color=current_background; 221 if (special) 222 { if (special->x1_clip()<=special->x2_clip()) 223 for (i=special->y2_clip();i>=special->y1_clip();i--) 224 memset(scan_line(i)+special->x1_clip(),color, 225 special->x2_clip()-special->x1_clip()+1); 226 } 227 else 228 for (i=height()-1;i>=0;i--) 229 memset(scan_line(i),color,width()); 230 add_dirty(0,0,width()-1,height()-1); 231 } 232 250 int16_t i; 251 252 lock(); 253 if(color == -1) 254 color = current_background; 255 if(special) 256 { 257 if(special->x1_clip() <= special->x2_clip()) 258 for(i = special->y2_clip(); i >= special->y1_clip(); i--) 259 memset(scan_line(i) + special->x1_clip(), color, 260 special->x2_clip() - special->x1_clip() + 1); 261 } 262 else 263 for(i = height() - 1; i >= 0; i--) 264 memset(scan_line(i), color, width()); 265 add_dirty(0, 0, width() - 1, height() - 1); 266 unlock(); 267 } 233 268 234 269 image *image::copy() 235 270 { 236 image *im; 237 uint8_t *c,*dat; 238 int i; 239 dat=(uint8_t *)jmalloc(width(),"image copy"); 240 im=new image(width(),height()); 241 for (i=height()-1;i>=0;i--) 242 { c=scan_line(i); 243 memcpy(dat,c,width()); 244 c=im->scan_line(i); 245 memcpy(c,dat,width()); 246 } 247 jfree((char *)dat); 248 return im; 249 } 250 251 252 253 void image::line(int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint8_t color) 254 { 255 int16_t i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi; 256 unsigned dcy,dcx; 271 image *im; 272 uint8_t *c, *dat; 273 int i; 274 275 lock(); 276 dat = (uint8_t *)jmalloc(width(), "image copy"); 277 im = new image(width(), height()); 278 im->lock(); 279 for(i = height() - 1; i >= 0; i--) 280 { 281 c = scan_line(i); 282 memcpy(dat, c, width()); 283 c = im->scan_line(i); 284 memcpy(c, dat, width()); 285 } 286 im->unlock(); 287 unlock(); 288 jfree((char *)dat); 289 return im; 290 } 291 292 void image::line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) 293 { 294 int16_t i, xc, yc, er, n, m, xi, yi, xcxi, ycyi, xcyi; 295 unsigned dcy, dcx; 257 296 // check to make sure that both endpoint are on the screen 258 297 259 int16_t cx1, cy1,cx2,cy2;298 int16_t cx1, cy1, cx2, cy2; 260 299 261 300 // check to see if the line is completly clipped off 262 get_clip(cx1, cy1,cx2,cy2);301 get_clip(cx1, cy1, cx2, cy2); 263 302 if ((x1<cx1 && x2<cx1) || (x1>cx2 && x2>cx2) || 264 303 (y1<cy1 && y2<cy1) || (y1>cy2 && y2>cy2)) … … 275 314 { 276 315 int my=(y2-y1); 277 int mx=(x2-x1), b;316 int mx=(x2-x1), b; 278 317 if (!mx) return ; 279 318 if (my) … … 290 329 { 291 330 int my=(y2-y1); 292 int mx=(x2-x1), b;331 int mx=(x2-x1), b; 293 332 if (!mx) return ; 294 333 if (my) … … 311 350 { 312 351 int mx=(x2-x1); 313 int my=(y2-y1), b;352 int my=(y2-y1), b; 314 353 if (!my) 315 354 return ; … … 327 366 { 328 367 int mx=(x2-x1); 329 int my=(y2-y1), b;368 int my=(y2-y1), b; 330 369 if (!my) return ; 331 370 if (mx) … … 353 392 yi=y2; yc=y1; 354 393 355 add_dirty(xc, yc,xi,yi);394 add_dirty(xc, yc, xi, yi); 356 395 dcx=x1; dcy=y1; 357 396 xc=(x2-x1); yc=(y2-y1); … … 362 401 er=0; 363 402 403 lock(); 364 404 if (n>m) 365 405 { 366 406 xcxi=abs(2*xc*xi); 367 for (i=0; i<=n;i++)407 for (i=0; i<=n; i++) 368 408 { 369 409 *(scan_line(dcy)+dcx)=color; 370 410 if (er>0) 371 411 { dcy+=yi; 372 412 er-=xcxi; 373 413 } 374 414 er+=ycyi; … … 379 419 { 380 420 xcyi=abs(2*xc*yi); 381 for (i=0; i<=m;i++)421 for (i=0; i<=m; i++) 382 422 { 383 423 *(scan_line(dcy)+dcx)=color; 384 424 if (er>0) 385 425 { dcx+=xi; 386 426 er-=ycyi; 387 427 } 388 428 er+=xcyi; … … 390 430 } 391 431 } 432 unlock(); 392 433 } 393 434 … … 395 436 void image::put_image(image *screen, int16_t x, int16_t y, char transparent) 396 437 { 397 int16_t i,j,xl,yl; 398 uint8_t *pg1,*pg2,*source,*dest; 399 if (screen->special) // the screen is clipped then we onl want to put 400 // part of the image 401 put_part(screen,x,y,0,0,width()-1,height()-1,transparent); 402 else 403 { 404 if (x<screen->width() && y<screen->height()) 405 { 406 xl=width(); 407 if (x+xl>screen->width()) // clip to the border of the screen 408 xl=screen->width()-x; 409 yl=height(); 410 if (y+yl>screen->height()) 411 yl=screen->height()-y; 412 413 int startx=0,starty=0; 414 if (x<0) { startx=-x; x=0; } 415 if (y<0) { starty=-y; y=0; } 416 417 if (xl<0 || yl<0) return ; 418 419 screen->add_dirty(x,y,x+xl-1,y+yl-1); 420 for (j=starty;j<yl;j++,y++) 421 { 422 pg1=screen->scan_line(y); 423 pg2=scan_line(j); 424 if (transparent) 425 { 426 for (i=startx,source=pg2+startx,dest=pg1+x;i<xl;i++,source++,dest++) 427 if (*source!=current_background) *dest=*source; 428 } else memcpy(&pg1[x],pg2,xl); // strait copy 429 } 430 } 431 } 438 int16_t i, j, xl, yl; 439 uint8_t *pg1, *pg2, *source, *dest; 440 441 // the screen is clipped then we only want to put part of the image 442 if(screen->special) 443 { 444 put_part(screen, x, y, 0, 0, width()-1, height()-1, transparent); 445 return; 446 } 447 448 if(x < screen->width() && y < screen->height()) 449 { 450 xl = width(); 451 if(x + xl > screen->width()) // clip to the border of the screen 452 xl = screen->width() - x; 453 yl = height(); 454 if(y + yl > screen->height()) 455 yl = screen->height() - y; 456 457 int startx = 0, starty = 0; 458 if(x < 0) 459 { 460 startx = -x; 461 x = 0; 462 } 463 if(y < 0) 464 { 465 starty = -y; 466 y = 0; 467 } 468 469 if(xl < 0 || yl < 0) 470 return; 471 472 screen->add_dirty(x, y, x + xl - 1, y + yl - 1); 473 screen->lock(); 474 lock(); 475 for(j = starty; j < yl; j++, y++) 476 { 477 pg1 = screen->scan_line(y); 478 pg2 = scan_line(j); 479 if(transparent) 480 { 481 for(i = startx, source = pg2+startx, dest = pg1 + x; 482 i < xl; 483 i++, source++, dest++) 484 { 485 if(*source != current_background) 486 *dest = *source; 487 } 488 } 489 else 490 memcpy(&pg1[x], pg2, xl); // straight copy 491 } 492 unlock(); 493 screen->unlock(); 494 } 432 495 } 433 496 434 497 void image::fill_image(image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t align) 435 498 { 436 int16_t i, j,w,xx,start,xl,starty;437 uint8_t *pg1, *pg2;499 int16_t i, j, w, xx, start, xl, starty; 500 uint8_t *pg1, *pg2; 438 501 CHECK(x1<=x2 && y1<=y2); // we should have gotten this 439 502 … … 452 515 if (x2<0 || y2<0 || x1>=screen->width() || y1>=screen->height()) 453 516 return ; 454 screen->add_dirty(x1, y1,x2,y2);517 screen->add_dirty(x1, y1, x2, y2); 455 518 w=width(); 456 519 if (align) … … 463 526 starty=0; 464 527 } 465 for (j=y1;j<=y2;j++) 528 screen->lock(); 529 lock(); 530 for (j=y1; j<=y2; j++) 466 531 { 467 532 pg1=screen->scan_line(j); … … 472 537 while (i<=x2) 473 538 { 474 xl=min(w-xx, x2-i+1);475 476 memcpy(&pg1[i], &pg2[xx],xl);539 xl=min(w-xx, x2-i+1); 540 541 memcpy(&pg1[i], &pg2[xx], xl); 477 542 xx=0; 478 543 i+=xl; 479 544 } 480 545 } 546 unlock(); 547 screen->unlock(); 481 548 } 482 549 483 550 484 551 void image::put_part(image *screen, int16_t x, int16_t y, 485 486 { 487 int16_t xl ,yl,j,i;488 int16_t cx1, cy1,cx2,cy2;489 uint8_t *pg1, *pg2,*source,*dest;552 int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent) 553 { 554 int16_t xlen, ylen, j, i; 555 int16_t cx1, cy1, cx2, cy2; 556 uint8_t *pg1, *pg2, *source, *dest; 490 557 CHECK(x1<=x2 && y1<=y2); 491 558 492 screen->get_clip(cx1, cy1,cx2,cy2);559 screen->get_clip(cx1, cy1, cx2, cy2); 493 560 494 561 … … 521 588 522 589 523 xl=x2-x1+1; 524 yl=y2-y1+1; 525 526 screen->add_dirty(x,y,x+xl-1,y+yl-1); 527 590 xlen=x2-x1+1; 591 ylen=y2-y1+1; 592 593 screen->add_dirty(x, y, x+xlen-1, y+ylen-1); 594 595 screen->lock(); 596 lock(); 528 597 pg1=screen->scan_line(y); 529 598 pg2=scan_line(y1); … … 531 600 if (transparent) 532 601 { 533 for (j=0; j<yl;j++)534 { 535 for (i=0, source=&pg2[x1],dest=&pg1[x];i<xl;i++,source++,dest++)602 for (j=0; j<ylen; j++) 603 { 604 for (i=0, source=&pg2[x1], dest=&pg1[x]; i<xlen; i++, source++, dest++) 536 605 if (*source!=current_background) *dest=*source; 537 pg1=screen->next_line(y+j, pg1);538 pg2=next_line(y1+j, pg2);606 pg1=screen->next_line(y+j, pg1); 607 pg2=next_line(y1+j, pg2); 539 608 } 540 609 } 541 610 else 542 for (j=0; j<yl;j++)543 { 544 memcpy(&pg1[x], &pg2[x1],xl); // strait copy545 pg1=screen->next_line(y+j, pg1);546 pg2=next_line(y1+j, pg2);611 for (j=0; j<ylen; j++) 612 { 613 memcpy(&pg1[x], &pg2[x1], xlen); // strait copy 614 pg1=screen->next_line(y+j, pg1); 615 pg2=next_line(y1+j, pg2); 547 616 } 617 unlock(); 618 screen->unlock(); 548 619 } 549 620 550 621 void image::put_part_xrev(image *screen, int16_t x, int16_t y, 551 552 { 553 int16_t xl, yl,j,i;554 int16_t cx1, cy1,cx2,cy2;555 uint8_t *pg1, *pg2,*source,*dest;622 int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent) 623 { 624 int16_t xl, yl, j, i; 625 int16_t cx1, cy1, cx2, cy2; 626 uint8_t *pg1, *pg2, *source, *dest; 556 627 CHECK(x1<=x2 && y1<=y2); 557 628 … … 566 637 if (screen->special) 567 638 { 568 screen->special->get_clip(cx1, cy1,cx2,cy2);639 screen->special->get_clip(cx1, cy1, cx2, cy2); 569 640 if (x>cx2 || y>cy2 || x+(x2-x1)<0 || y+(y2-y1)<0) return ; 570 641 if (x<cx1) … … 593 664 if (y+yl>screen->height()) 594 665 yl=screen->height()-y; 595 screen->add_dirty(x,y,x+xl-1,y+yl-1); 596 for (j=0;j<yl;j++) 666 screen->add_dirty(x, y, x+xl-1, y+yl-1); 667 screen->lock(); 668 lock(); 669 for (j=0; j<yl; j++) 597 670 { 598 671 pg1=screen->scan_line(y+j); … … 600 673 if (transparent) 601 674 { 602 for (i=0,source=&pg2[x1],dest=&pg1[x+xl-1];i<xl;i++,source++,dest--)675 for (i=0, source=&pg2[x1], dest=&pg1[x+xl-1]; i<xl; i++, source++, dest--) 603 676 if (*source!=current_background) *dest=*source; 604 677 } 605 678 else 606 for (i=0,source=&pg2[x1],dest=&pg1[x+xl-1];i<xl;i++,source++,dest++)679 for (i=0, source=&pg2[x1], dest=&pg1[x+xl-1]; i<xl; i++, source++, dest++) 607 680 *dest=*source; 608 681 } 682 unlock(); 683 screen->unlock(); 609 684 } 610 685 } … … 612 687 613 688 void image::put_part_masked(image *screen, image *mask, int16_t x, int16_t y, 614 615 616 { 617 int16_t xl, yl,j,i,ml,mh;618 int16_t cx1, cy1,cx2,cy2;619 uint8_t *pg1, *pg2,*pg3;689 int16_t maskx, int16_t masky, 690 int16_t x1, int16_t y1, int16_t x2, int16_t y2) 691 { 692 int16_t xl, yl, j, i, ml, mh; 693 int16_t cx1, cy1, cx2, cy2; 694 uint8_t *pg1, *pg2, *pg3; 620 695 CHECK(x1<=x2 && y1<=y2); 621 696 622 697 if (screen->special) 623 698 { 624 screen->special->get_clip(cx1, cy1,cx2,cy2);699 screen->special->get_clip(cx1, cy1, cx2, cy2); 625 700 if (x>cx2 || y>cy2 || x+(x2-x1)<0 || y+(y2-y1)<0) return ; 626 701 if (x<cx1) … … 652 727 if (y+yl>screen->height()) 653 728 yl=screen->height()-y-1; 654 screen->add_dirty(x,y,x+xl-1,y+yl-1); 655 for (j=0;j<yl;j++) 729 screen->add_dirty(x, y, x+xl-1, y+yl-1); 730 screen->lock(); 731 mask->lock(); 732 lock(); 733 for (j=0; j<yl; j++) 656 734 { 657 735 pg1=screen->scan_line(y+j); … … 659 737 pg3=mask->scan_line(masky++); 660 738 if (masky>=mh) // wrap the mask around if out of bounds 661 662 for (i=0; i<xl;i++)739 masky=0; 740 for (i=0; i<xl; i++) 663 741 { 664 665 666 667 742 if (pg3[maskx+i]) // check to make sure not 0 before putting 743 pg1[x+i]=pg2[x1+i]; 744 if (maskx>=ml) // wrap x around if it goes to far 745 maskx=0; 668 746 } 669 747 } 748 unlock(); 749 mask->unlock(); 750 screen->unlock(); 670 751 } 671 752 } … … 674 755 675 756 uint8_t image::brightest_color(palette *pal) 676 { uint8_t *p, r,g,b,bri;677 int16_t i, j;757 { uint8_t *p, r, g, b, bri; 758 int16_t i, j; 678 759 int32_t brv; 679 760 brv=0; bri=0; 680 for (j=0;j<h;j++) 761 lock(); 762 for (j=0; j<h; j++) 681 763 { 682 764 p=scan_line(j); 683 for (i=0; i<w;i++)684 { pal->get(p[i], r,g,b);765 for (i=0; i<w; i++) 766 { pal->get(p[i], r, g, b); 685 767 if ((int32_t)r*(int32_t)g*(int32_t)b>brv) 686 768 { brv=(int32_t)r*(int32_t)g*(int32_t)b; 687 769 bri=p[i]; 688 770 } 689 771 } 690 772 } 773 unlock(); 691 774 return bri; 692 775 } 693 776 694 777 uint8_t image::darkest_color(palette *pal, int16_t noblack) 695 { uint8_t *p, r,g,b,bri;696 int16_t i, j;697 int32_t brv, x;778 { uint8_t *p, r, g, b, bri; 779 int16_t i, j; 780 int32_t brv, x; 698 781 brv=(int32_t)258*(int32_t)258*(int32_t)258; bri=0; 699 for (j=0;j<h;j++) 782 lock(); 783 for (j=0; j<h; j++) 700 784 { 701 785 p=scan_line(j); 702 for (i=0; i<w;i++)703 { pal->get(p[i], r,g,b);786 for (i=0; i<w; i++) 787 { pal->get(p[i], r, g, b); 704 788 x=(int32_t)r*(int32_t)g*(int32_t)b; 705 789 if (x<brv && (x || !noblack)) 706 790 { brv=x; 707 791 bri=p[i]; 708 792 } 709 793 } 710 794 } 795 unlock(); 711 796 return bri; 712 797 } 713 798 714 void image::rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)715 { 716 line(x1, y1,x2,y1,color);717 line(x2, y1,x2,y2,color);718 line(x1, y2,x2,y2,color);719 line(x1, y1,x1,y2,color);799 void image::rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) 800 { 801 line(x1, y1, x2, y1, color); 802 line(x2, y1, x2, y2, color); 803 line(x1, y2, x2, y2, color); 804 line(x1, y1, x1, y2, color); 720 805 } 721 806 … … 735 820 { 736 821 if (special) 737 special->get_clip(x1, y1,x2,y2);822 special->get_clip(x1, y1, x2, y2); 738 823 else 739 824 { x1=0; y1=0; x2=width()-1; y2=height()-1; } … … 753 838 y2=special->y2_clip(); 754 839 } 755 set_clip(x1, y1,x2,y2);840 set_clip(x1, y1, x2, y2); 756 841 } 757 842 … … 762 847 void image_descriptor::reduce_dirties() 763 848 { 764 dirty_rect *p, *q;765 int16_t x1, y1,x2,y2,nn;849 dirty_rect *p, *q; 850 int16_t x1, y1, x2, y2, nn; 766 851 x1=6000; y1=6000; 767 852 x2=0; y2=0; … … 780 865 nn--; 781 866 } 782 dirties.add_front((linked_node *) new dirty_rect(x1, y1,x2,y2));867 dirties.add_front((linked_node *) new dirty_rect(x1, y1, x2, y2)); 783 868 } 784 869 785 870 void image_descriptor::delete_dirty(int x1, int y1, int x2, int y2) 786 871 { 787 int16_t i, ax1,ay1,ax2,ay2;788 dirty_rect *p, *next;872 int16_t i, ax1, ay1, ax2, ay2; 873 dirty_rect *p, *next; 789 874 if (keep_dirt) 790 875 { … … 801 886 else 802 887 { 803 for (p=(dirty_rect *)dirties.first(); i;i--,p=(dirty_rect *)next)888 for (p=(dirty_rect *)dirties.first(); i; i--, p=(dirty_rect *)next) 804 889 { 805 890 next=(dirty_rect *)p->next(); 806 891 // are the two touching? 807 892 if (!(x2<p->dx1 || y2<p->dy1 || x1>p->dx2 || y1>p->dy2)) 808 893 { 809 894 // does it take a x slice off? (across) … … 821 906 else 822 907 { 823 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1,p->dx2,y1-1));908 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1, p->dx2, y1-1)); 824 909 p->dy1=y2+1; 825 910 } … … 834 919 else 835 920 { 836 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1,x1-1,p->dy2));921 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1, x1-1, p->dy2)); 837 922 p->dx1=x2+1; 838 923 } … … 847 932 else if (y1<=p->dy1) { ay1=p->dy1; ay2=y2; } 848 933 else { ay1=y1; ay2=y2; } 849 dirties.add_front((linked_node *) new dirty_rect(ax1, ay1,ax2,ay2));934 dirties.add_front((linked_node *) new dirty_rect(ax1, ay1, ax2, ay2)); 850 935 851 936 if (x2>=p->dx2 || x1<=p->dx1) { ax1=p->dx1; ax2=p->dx2; } … … 859 944 else { if (ax1==p->dx1) { ay1=p->dy1; ay2=y1-1; } 860 945 else { ay1=y1; ay2=y2; } } 861 dirties.add_front((linked_node *) new dirty_rect(ax1, ay1,ax2,ay2));946 dirties.add_front((linked_node *) new dirty_rect(ax1, ay1, ax2, ay2)); 862 947 863 948 if (x1>p->dx1 && x2<p->dx2) … … 865 950 if (y1>p->dy1 && y2<p->dy2) 866 951 { 867 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1,p->dx2,y1-1));868 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1,p->dx2,p->dy2));952 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1, p->dx2, y1-1)); 953 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1, p->dx2, p->dy2)); 869 954 } else if (y1<=p->dy1) 870 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1,p->dx2,p->dy2));955 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1, p->dx2, p->dy2)); 871 956 else 872 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1,p->dx2,y1-1));957 dirties.add_front((linked_node *) new dirty_rect(p->dx1, p->dy1, p->dx2, y1-1)); 873 958 } else if (y1>p->dy1 && y2<p->dy2) 874 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1,p->dx2,p->dy2));959 dirties.add_front((linked_node *) new dirty_rect(p->dx1, y2+1, p->dx2, p->dy2)); 875 960 dirties.unlink((linked_node *) p); 876 961 delete p; … … 897 982 i=dirties.number_nodes(); 898 983 if (!i) 899 dirties.add_front((linked_node *) new dirty_rect(x1, y1,x2,y2));984 dirties.add_front((linked_node *) new dirty_rect(x1, y1, x2, y2)); 900 985 else if (i>=MAX_DIRTY) 901 986 { 902 dirties.add_front((linked_node *) new dirty_rect(x1, y1,x2,y2));987 dirties.add_front((linked_node *) new dirty_rect(x1, y1, x2, y2)); 903 988 reduce_dirties(); // reduce to one dirty rectangle, we have to many 904 989 } 905 990 else 906 991 { 907 for (p=(dirty_rect *)dirties.first(); i>0;i--)992 for (p=(dirty_rect *)dirties.first(); i>0; i--) 908 993 { 909 994 910 995 // check to see if this new rectangle completly encloses the check rectangle 911 912 913 914 915 916 917 918 else p=tmp;919 } 920 921 {922 923 924 996 if (x1<=p->dx1 && y1<=p->dy1 && x2>=p->dx2 && y2>=p->dy2) 997 { 998 dirty_rect *tmp=(dirty_rect*) p->next(); 999 dirties.unlink((linked_node *)p); 1000 delete p; 1001 if (!dirties.first()) 1002 i=0; 1003 else p=tmp; 1004 } 1005 else if (!(x2<p->dx1 || y2<p->dy1 || x1>p->dx2 || y1>p->dy2)) 1006 { 1007 1008 1009 925 1010 /* if (x1<=p->dx1) { a+=p->dx1-x1; ax1=x1; } else ax1=p->dx1; 926 1011 if (y1<=p->dy1) { a+=p->dy1-y1; ay1=y1; } else ay1=p->dy1; 927 1012 if (x2>=p->dx2) { a+=x2-p->dx2; ax2=x2; } else ax2=p->dx2; 928 1013 if (y2>=p->dy2) { a+=y2-p->dy2; ay2=y2; } else ay2=p->dy2; 929 930 931 { p->dx1=ax1;// then expand the dirty932 933 934 935 936 937 938 939 940 add_dirty(x1,max(y1,p->dy1),p->dx1-1,min(y2,p->dy2));941 942 add_dirty(p->dx2+1,max(y1,p->dy1),x2,min(y2,p->dy2));943 944 add_dirty(x1,y1,x2,p->dy1-1);945 946 add_dirty(x1,p->dy2+1,x2,y2);947 948 949 950 951 1014 1015 if (a<50) 1016 { p->dx1=ax1; // then expand the dirty 1017 p->dy1=ay1; 1018 p->dx2=ax2; 1019 p->dy2=ay2; 1020 return ; 1021 } 1022 else */ 1023 { 1024 if (x1<p->dx1) 1025 add_dirty(x1, max(y1, p->dy1), p->dx1-1, min(y2, p->dy2)); 1026 if (x2>p->dx2) 1027 add_dirty(p->dx2+1, max(y1, p->dy1), x2, min(y2, p->dy2)); 1028 if (y1<p->dy1) 1029 add_dirty(x1, y1, x2, p->dy1-1); 1030 if (y2>p->dy2) 1031 add_dirty(x1, p->dy2+1, x2, y2); 1032 return ; 1033 } 1034 p=(dirty_rect *)p->next(); 1035 } else p=(dirty_rect *)p->next(); 1036 952 1037 } 953 1038 CHECK(x1<=x2 && y1<=y2); 954 dirties.add_end((linked_node *)new dirty_rect(x1, y1,x2,y2));1039 dirties.add_end((linked_node *)new dirty_rect(x1, y1, x2, y2)); 955 1040 } 956 1041 } … … 975 1060 if (x2<0 || y2<0 || x1>=width() || y1>=height() || x2<x1 || y2<y1) 976 1061 return ; 977 for (y=y1;y<=y2;y++) 978 memset(scan_line(y)+x1,color,(x2-x1+1)); 979 add_dirty(x1,y1,x2,y2); 1062 lock(); 1063 for (y=y1; y<=y2; y++) 1064 memset(scan_line(y)+x1, color, (x2-x1+1)); 1065 unlock(); 1066 add_dirty(x1, y1, x2, y2); 980 1067 } 981 1068 982 1069 void image::xor_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) 983 1070 { 984 int16_t y, x;1071 int16_t y, x; 985 1072 if (x1>x2 || y1>y2) return ; 986 1073 if (special) … … 999 1086 return ; 1000 1087 1088 lock(); 1001 1089 uint8_t *sl=scan_line(y1)+x1; 1002 for (y=y1; y<=y2;y++)1090 for (y=y1; y<=y2; y++) 1003 1091 { 1004 1092 uint8_t *s=sl; 1005 for (x=x1; x<=x2;x++,s++)1093 for (x=x1; x<=x2; x++, s++) 1006 1094 *s=(*s)^color; 1007 1095 sl+=w; 1008 1096 } 1009 1010 add_dirty(x1,y1,x2,y2); 1097 unlock(); 1098 1099 add_dirty(x1, y1, x2, y2); 1011 1100 } 1012 1101 … … 1015 1104 { 1016 1105 int16_t x; 1017 uint8_t *sl,*ex,mask,bt,sh; 1018 ex=(uint8_t *)jmalloc(width(),"image::unpacked scanline"); 1106 uint8_t *sl, *ex, mask, bt, sh; 1107 ex=(uint8_t *)jmalloc(width(), "image::unpacked scanline"); 1108 1109 lock(); 1019 1110 sl=scan_line(line); 1020 memcpy(ex,sl,width()); 1111 memcpy(ex, sl, width()); 1112 unlock(); 1021 1113 1022 1114 if (bitsperpixel==1) { mask=128; bt=8; } 1023 1115 else if (bitsperpixel==2) { mask=128+64; bt=4; } 1024 else 1025 1026 for (x=0; x<width();x++)1116 else { mask=128+64+32+16; bt=2; } 1117 1118 for (x=0; x<width(); x++) 1027 1119 { sh=((x%bt)<<(bitsperpixel-1)); 1028 1120 sl[x]=(ex[x/bt]&(mask>>sh))>>(bt-sh-1); … … 1034 1126 void image::dither(palette *pal) 1035 1127 { 1036 int16_t x, y,i,j;1037 uint8_t dt_matrix[]={0, 136, 24, 170,1038 68, 204,102,238,1039 51, 187, 17,153,1040 119,255, 85,221};1128 int16_t x, y, i, j; 1129 uint8_t dt_matrix[]={0, 136, 24, 170, 1130 68, 204, 102, 238, 1131 51, 187, 17, 153, 1132 119, 255, 85, 221}; 1041 1133 1042 1134 uint8_t *sl; 1043 for (y=height()-1;y>=0;y--) 1135 lock(); 1136 for (y=height()-1; y>=0; y--) 1044 1137 { 1045 1138 sl=scan_line(y); 1046 for (i=0, j=y%4,x=width()-1;x>=0;x--)1139 for (i=0, j=y%4, x=width()-1; x>=0; x--) 1047 1140 { 1048 1141 if (pal->red(sl[x])>dt_matrix[j*4+i]) 1049 1142 sl[x]=255; 1050 1143 else sl[x]=0; 1051 1144 if (i==3) i=0; else i++; 1052 1145 } 1053 1146 } 1147 unlock(); 1054 1148 } 1055 1149 … … 1067 1161 void image::resize(int16_t new_width, int16_t new_height) 1068 1162 { 1069 int old_width=width(),old_height=height(); 1070 uint8_t *im=(uint8_t *)jmalloc(width()*height(),"image::resized"); 1071 memcpy(im,scan_line(0),width()*height()); 1163 int old_width=width(), old_height=height(); 1164 uint8_t *im=(uint8_t *)jmalloc(width()*height(), "image::resized"); 1165 lock(); 1166 memcpy(im, scan_line(0), width()*height()); 1072 1167 1073 1168 delete_page(); 1074 make_page(new_width, new_height,NULL);1169 make_page(new_width, new_height, NULL); 1075 1170 w=new_width; // set the new hieght and width 1076 1171 h=new_height; 1077 1172 1078 uint8_t *sl1, *sl2;1079 int16_t y, y2,x2;1080 double yc, xc,yd,xd;1173 uint8_t *sl1, *sl2; 1174 int16_t y, y2, x2; 1175 double yc, xc, yd, xd; 1081 1176 1082 1177 … … 1084 1179 yc=(double)old_height/(double)new_height; 1085 1180 xc=(double)old_width/(double)new_width; 1086 for (y2=0, yd=0;y2<new_height;yd+=yc,y2++)1181 for (y2=0, yd=0; y2<new_height; yd+=yc, y2++) 1087 1182 { 1088 1183 y=(int)yd; 1089 1184 sl1=im+y*old_width; 1090 1185 sl2=scan_line(y2); 1091 for (xd=0, x2=0;x2<new_width;xd+=xc,x2++)1186 for (xd=0, x2=0; x2<new_width; xd+=xc, x2++) 1092 1187 { sl2[x2]=sl1[(int)xd]; } 1093 1188 } 1094 1189 jfree(im); 1095 if (special) special->resize(new_width,new_height); 1190 if (special) special->resize(new_width, new_height); 1191 unlock(); 1096 1192 } 1097 1193 1098 1194 void image::scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd) 1099 1195 { 1100 int16_t cx1, cy1,cx2,cy2;1196 int16_t cx1, cy1, cx2, cy2; 1101 1197 CHECK(x1>=0 && y1>=0 && x1<x2 && y1<y2 && x2<width() && y2<height()); 1102 1198 if (special) 1103 1199 { 1104 special->get_clip(cx1, cy1,cx2,cy2);1105 x1=max(x1, cx1); y1=max(cy1,y1); x2=min(x2,cx2); y2=min(y2,cy2);1106 } 1107 int16_t xsrc, ysrc,xdst,ydst,xtot=x2-x1-abs(xd)+1,ytot,xt;1108 uint8_t *src, *dst;1200 special->get_clip(cx1, cy1, cx2, cy2); 1201 x1=max(x1, cx1); y1=max(cy1, y1); x2=min(x2, cx2); y2=min(y2, cy2); 1202 } 1203 int16_t xsrc, ysrc, xdst, ydst, xtot=x2-x1-abs(xd)+1, ytot, xt; 1204 uint8_t *src, *dst; 1109 1205 if (xd<0) { xsrc=x1-xd; xdst=x1; } else { xsrc=x2-xd; xdst=x2; } 1110 1206 if (yd<0) { ysrc=y1-yd; ydst=y1; } else { ysrc=y2-yd; ydst=y2; } 1111 for (ytot=y2-y1-abs(yd)+1; ytot;ytot--)1207 for (ytot=y2-y1-abs(yd)+1; ytot; ytot--) 1112 1208 { src=scan_line(ysrc)+xsrc; 1113 1209 dst=scan_line(ydst)+xdst; 1114 1210 if (xd<0) 1115 for (xt=xtot; xt;xt--)1211 for (xt=xtot; xt; xt--) 1116 1212 *(dst++)=*(src++); 1117 else for (xt=xtot; xt;xt--)1213 else for (xt=xtot; xt; xt--) 1118 1214 *(dst--)=*(src--); 1119 1215 if (yd<0) { ysrc++; ydst++; } else { ysrc--; ydst--; } 1120 1216 } 1121 add_dirty(x1, y1,x2,y2);1217 add_dirty(x1, y1, x2, y2); 1122 1218 } 1123 1219 … … 1125 1221 image *image::create_smooth(int16_t smoothness) 1126 1222 { 1127 int16_t i, j,k,l,t,d;1223 int16_t i, j, k, l, t, d; 1128 1224 image *im; 1129 1225 CHECK(smoothness>=0); … … 1131 1227 d=smoothness*2+1; 1132 1228 d=d*d; 1133 im=new image(width(), height());1134 for (i=0; i<width();i++)1135 for (j=0; j<height();j++)1136 { 1137 for (t=0, k=-smoothness;k<=smoothness;k++)1138 for (l=-smoothness;l<=smoothness;l++)1139 1140 t+=pixel(i+k,j+l);1141 else t+=pixel(i,j);1142 im->putpixel(i, j,t/d);1229 im=new image(width(), height()); 1230 for (i=0; i<width(); i++) 1231 for (j=0; j<height(); j++) 1232 { 1233 for (t=0, k=-smoothness; k<=smoothness; k++) 1234 for (l=-smoothness; l<=smoothness; l++) 1235 if (i+k>smoothness && i+k<width()-smoothness && j+l<height()-smoothness && j+l>smoothness) 1236 t+=pixel(i+k, j+l); 1237 else t+=pixel(i, j); 1238 im->putpixel(i, j, t/d); 1143 1239 } 1144 1240 return im; … … 1146 1242 1147 1243 void image::widget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 1148 1149 { 1150 line(x1, y1,x2,y1,light);1151 line(x1, y1,x1,y2,light);1152 line(x2, y1+1,x2,y2,dark);1153 line(x1+1, y2,x2-1,y2,dark);1154 bar(x1+1, y1+1,x2-1,y2-1,med);1244 uint8_t light, uint8_t med, uint8_t dark) 1245 { 1246 line(x1, y1, x2, y1, light); 1247 line(x1, y1, x1, y2, light); 1248 line(x2, y1+1, x2, y2, dark); 1249 line(x1+1, y2, x2-1, y2, dark); 1250 bar(x1+1, y1+1, x2-1, y2-1, med); 1155 1251 } 1156 1252 … … 1158 1254 { 1159 1255 public : 1160 int16_t x, y;1256 int16_t x, y; 1161 1257 fill_rec *last; 1162 1258 fill_rec(int16_t X, int16_t Y, fill_rec *Last) … … 1166 1262 void image::flood_fill(int16_t x, int16_t y, uint8_t color) 1167 1263 { 1168 uint8_t *sl, *above,*below;1169 fill_rec *recs=NULL, *r;1264 uint8_t *sl, *above, *below; 1265 fill_rec *recs=NULL, *r; 1170 1266 uint8_t fcolor; 1267 lock(); 1171 1268 sl=scan_line(y); 1172 1269 fcolor=sl[x]; … … 1189 1286 above=scan_line(y-1); 1190 1287 if (above[x]==fcolor) 1191 { r=new fill_rec(x, y-1,recs);1288 { r=new fill_rec(x, y-1, recs); 1192 1289 recs=r; 1193 1290 } … … 1197 1294 above=scan_line(y+1); 1198 1295 if (above[x]==fcolor) 1199 { r=new fill_rec(x, y+1,recs);1296 { r=new fill_rec(x, y+1, recs); 1200 1297 recs=r; 1201 1298 } … … 1210 1307 { above=scan_line(y-1); 1211 1308 if (x>0 && above[x-1]!=fcolor && above[x]==fcolor) 1212 { r=new fill_rec(x, y-1,recs);1309 { r=new fill_rec(x, y-1, recs); 1213 1310 recs=r; 1214 1311 } … … 1217 1314 { below=scan_line(y+1); 1218 1315 if (x>0 && below[x-1]!=fcolor && below[x]==fcolor) 1219 { r=new fill_rec(x, y+1,recs);1316 { r=new fill_rec(x, y+1, recs); 1220 1317 recs=r; 1221 1318 } … … 1228 1325 above=scan_line(y-1); 1229 1326 if (above[x]==fcolor) 1230 { r=new fill_rec(x, y-1,recs);1327 { r=new fill_rec(x, y-1, recs); 1231 1328 recs=r; 1232 1329 } … … 1236 1333 above=scan_line(y+1); 1237 1334 if (above[x]==fcolor) 1238 { r=new fill_rec(x, y+1,recs);1335 { r=new fill_rec(x, y+1, recs); 1239 1336 recs=r; 1240 1337 } … … 1242 1339 } 1243 1340 } while (recs); 1341 unlock(); 1244 1342 } 1245 1343 … … 1250 1348 { 1251 1349 char st[100]; 1252 int16_t ledx[]={1, 2,1,2,3,3,3,3,1,2,0,0,0,0};1253 int16_t ledy[]={3, 3,0,0,1,2,4,6,7,7,4,6,1,2};1254 1255 int16_t dig[]={2+4+8+16+32+64, 4+8,2+4+1+32+16,2+4+1+8+16,64+1+4+8,1256 2+64+1+8+16, 64+32+1+8+16,2+4+8,1+2+4+8+16+32+64,64+2+4+1+8,1};1257 int16_t xx, yy,zz;1258 sprintf(st, "%8ld",(long int)num);1259 for (xx=0; xx<8;xx++)1350 int16_t ledx[]={1, 2, 1, 2, 3, 3, 3, 3, 1, 2, 0, 0, 0, 0}; 1351 int16_t ledy[]={3, 3, 0, 0, 1, 2, 4, 6, 7, 7, 4, 6, 1, 2}; 1352 1353 int16_t dig[]={2+4+8+16+32+64, 4+8, 2+4+1+32+16, 2+4+1+8+16, 64+1+4+8, 1354 2+64+1+8+16, 64+32+1+8+16, 2+4+8, 1+2+4+8+16+32+64, 64+2+4+1+8, 1}; 1355 int16_t xx, yy, zz; 1356 sprintf(st, "%8ld", (long int)num); 1357 for (xx=0; xx<8; xx++) 1260 1358 { 1261 1359 if (st[xx]!=' ') 1262 1360 { 1263 1361 if (st[xx]=='-') 1264 1362 zz=10; 1265 1363 else 1266 1267 for (yy=0; yy<7;yy++)1268 1269 line(x+ledx[yy*2]*scale,y+ledy[yy*2]*scale,x+ledx[yy*2+1]*scale,1270 y+ledy[yy*2+1]*scale,color);1364 zz=st[xx]-'0'; 1365 for (yy=0; yy<7; yy++) 1366 if ((1<<yy)&dig[zz]) 1367 line(x+ledx[yy*2]*scale, y+ledy[yy*2]*scale, x+ledx[yy*2+1]*scale, 1368 y+ledy[yy*2+1]*scale, color); 1271 1369 } 1272 1370 x+=6*scale; … … 1274 1372 } 1275 1373 1276 uint8_t dither_matrix[]={0, 136, 24, 170,1277 68, 204,102,238,1278 51, 187, 17,153,1279 119,255, 85,221};1374 uint8_t dither_matrix[]={0, 136, 24, 170, 1375 68, 204, 102, 238, 1376 51, 187, 17, 153, 1377 119, 255, 85, 221}; 1280 1378 1281 1379 image *image::copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2) 1282 1380 { 1283 int16_t x, y,cx1,cy1,cx2,cy2,ry,rx,bo,dity,ditx;1381 int16_t x, y, cx1, cy1, cx2, cy2, ry, rx, bo, dity, ditx; 1284 1382 image *ret; 1285 uint8_t *sl1, *sl2;1286 get_clip(cx1, cy1,cx2,cy2);1383 uint8_t *sl1, *sl2; 1384 get_clip(cx1, cy1, cx2, cy2); 1287 1385 if (y1<cy1) y1=cy1; 1288 1386 if (x1<cx1) x1=cx1; … … 1291 1389 CHECK(x2>=x1 && y2>=y1); 1292 1390 if (x2<x1 || y2<y1) return NULL; 1293 ret=new image((x2-x1+8)/8, (y2-y1+1));1391 ret=new image((x2-x1+8)/8, (y2-y1+1)); 1294 1392 if (!last_loaded()) 1295 1393 ret->clear(); 1296 1394 else 1297 for (y=y1,ry=0,dity=(y1%4)*4;y<=y2;y++,ry++) 1395 { 1396 ret->lock(); 1397 lock(); 1398 for (y=y1, ry=0, dity=(y1%4)*4; y<=y2; y++, ry++) 1298 1399 { 1299 1400 sl1=ret->scan_line(ry); // sl1 is the scan linefo the return image 1300 1401 sl2=scan_line(y); // sl2 is the orginal image scan line 1301 memset(sl1, 0,(x2-x1+8)/8);1302 for (bo=7, rx=0,x=x1,ditx=x1%4;x<=x2;x++)1402 memset(sl1, 0, (x2-x1+8)/8); 1403 for (bo=7, rx=0, x=x1, ditx=x1%4; x<=x2; x++) 1303 1404 { 1304 1405 if (last_loaded()->red(sl2[x])>dither_matrix[ditx+dity]) 1305 1406 sl1[rx]|=1<<bo; 1306 1407 if (bo!=0) 1307 1408 bo--; 1308 1409 else 1309 1410 { 1310 1311 1411 rx++; 1412 bo=7; 1312 1413 } 1313 1414 ditx+=1; if (ditx>3) ditx=0; … … 1315 1416 dity+=4; if (dity>12) dity=0; 1316 1417 } 1418 unlock(); 1419 ret->unlock(); 1420 } 1317 1421 return ret; 1318 1422 } … … 1320 1424 void image::flip_x() 1321 1425 { 1322 uint8_t *rev=(uint8_t *)jmalloc(width(),"image tmp::flipped_x"),*sl; 1323 CONDITION(rev,"memory allocation"); 1324 int y,x,i; 1325 for (y=0;y<height();y++) 1426 uint8_t *rev=(uint8_t *)jmalloc(width(), "image tmp::flipped_x"), *sl; 1427 CONDITION(rev, "memory allocation"); 1428 int y, x, i; 1429 1430 /* FIXME: Abuse Win32 uses RestoreSurface() here instead of locking */ 1431 lock(); 1432 for (y=0; y<height(); y++) 1326 1433 { sl=scan_line(y); 1327 for (i=0, x=width()-1;x>=0;x--,i++)1434 for (i=0, x=width()-1; x>=0; x--, i++) 1328 1435 rev[i]=sl[x]; 1329 memcpy(sl,rev,width()); 1330 } 1436 memcpy(sl, rev, width()); 1437 } 1438 unlock(); 1331 1439 jfree(rev); 1332 1440 } … … 1334 1442 void image::flip_y() 1335 1443 { 1336 uint8_t *rev=(uint8_t *)jmalloc(width(), "image::flipped_y"),*sl;1337 CONDITION(rev, "memory allocation");1444 uint8_t *rev=(uint8_t *)jmalloc(width(), "image::flipped_y"), *sl; 1445 CONDITION(rev, "memory allocation"); 1338 1446 int y; 1339 for (y=0;y<height()/2;y++) 1447 1448 /* FIXME: Abuse Win32 uses RestoreSurface() here instead of locking */ 1449 lock(); 1450 for (y=0; y<height()/2; y++) 1340 1451 { sl=scan_line(y); 1341 memcpy(rev,sl,width()); 1342 memcpy(sl,scan_line(height()-y-1),width()); 1343 memcpy(scan_line(height()-y-1),rev,width()); 1344 } 1452 memcpy(rev, sl, width()); 1453 memcpy(sl, scan_line(height()-y-1), width()); 1454 memcpy(scan_line(height()-y-1), rev, width()); 1455 } 1456 unlock(); 1457 jfree(rev); 1345 1458 } 1346 1459 … … 1348 1461 { 1349 1462 uint8_t *sl; 1350 int y,x; 1351 for (y=0;y<height();y++) 1463 int y, x; 1464 lock(); 1465 for (y=0; y<height(); y++) 1352 1466 { 1353 1467 sl=scan_line(y); 1354 for (x=width(); x;x--,sl++)1468 for (x=width(); x; x--, sl++) 1355 1469 if (*sl) 1356 1470 *sl=color; 1357 1471 } 1358 } 1472 unlock(); 1473 } -
abuse/trunk/src/imlib/image.hpp
r112 r115 8 8 */ 9 9 10 #ifndef _IMGAE_HPP_ 11 #define _IMGAE_HPP_ 10 #ifndef _IMAGE_HPP_ 11 #define _IMAGE_HPP_ 12 12 13 #include <stdlib.h> 13 14 #include "linked.hpp" … … 19 20 20 21 extern char const *imerr_messages[]; // correspond to imERRORS 21 #define imREAD_ERROR 22 #define imREAD_ERROR 1 22 23 #define imINCORRECT_FILETYPE 2 23 24 #define imFILE_CORRUPTED 3 … … 26 27 #define imNOT_SUPPORTED 6 27 28 #define imWRITE_ERROR 7 28 #define imMAX_ERROR 29 #define imMAX_ERROR 7 29 30 30 31 int16_t current_error(); … … 39 40 typedef struct image_color_t 40 41 { 41 42 43 42 uint16_t r; 43 uint16_t g; 44 uint16_t b; 44 45 } image_color; 45 46 … … 52 53 int16_t dx1,dy1,dx2,dy2; 53 54 dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 54 { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 55 if (x2<x1 || y2<y1)55 { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 56 if(x2<x1 || y2<y1) 56 57 printf("add inccorect dirty\n"); 57 58 } 58 59 virtual int16_t compare(void *n1, int16_t field) 59 { return 60 { return((dirty_rect *)n1)->dy1>dy1; } 60 61 } ; 61 62 62 63 class image_descriptor 63 64 { 64 int16_t l,h; 65 int16_t clipx1, clipy1, clipx2, clipy2; 66 public : 67 uint8_t keep_dirt, 68 static_mem; // if this flag is set then don't free memory on exit 69 70 linked_list dirties; 71 void *extended_descriptor; // type depends on current system 72 73 image_descriptor(int16_t length, int16_t height, 74 int keep_dirties=1, int static_memory=0); 75 int16_t bound_x1(int16_t x1) { return x1<clipx1 ? clipx1 : x1; } 76 int16_t bound_y1(int16_t y1) { return y1<clipy1 ? clipy1 : y1; } 77 int16_t bound_x2(int16_t x2) { return x2>clipx2 ? clipx2 : x2; } 78 int16_t bound_y2(int16_t y2) { return y2>clipy2 ? clipy2 : y2; } 79 int16_t x1_clip() { return clipx1; } 80 int16_t y1_clip() { return clipy1; } 81 int16_t x2_clip() { return clipx2; } 82 int16_t y2_clip() { return clipy2; } 83 void dirty_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ;} 84 void clean_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } 85 void clear_dirties(); 86 int16_t get_dirty_area(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) { return 0; } 87 void get_clip(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 88 { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; } 89 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 90 { if (x2<x1) x2=x1; 91 if (y2<y1) y2=y1; 92 if (x1<0) clipx1=0; else clipx1=x1; 93 if (y1<0) clipy1=0; else clipy1=y1; 94 if (x2>=l) clipx2=l-1; else clipx2=x2; 95 if (y2>=h) clipy2=h-1; else clipy2=y2; 96 } 97 void reduce_dirties(); 98 void add_dirty(int x1, int y1, int x2, int y2); 99 void delete_dirty(int x1, int y1, int x2, int y2); 100 void resize(int16_t length, int16_t height) 101 { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; } 102 } ; 65 private: 66 int16_t l, h; 67 int16_t clipx1, clipy1, clipx2, clipy2; 68 69 public: 70 uint8_t keep_dirt, 71 static_mem; // if set, don't free memory on exit 72 73 linked_list dirties; 74 void *extended_descriptor; 75 76 image_descriptor(int16_t length, int16_t height, 77 int keep_dirties = 1, int static_memory = 0); 78 int16_t bound_x1(int16_t x1) { return x1 < clipx1 ? clipx1 : x1; } 79 int16_t bound_y1(int16_t y1) { return y1 < clipy1 ? clipy1 : y1; } 80 int16_t bound_x2(int16_t x2) { return x2 > clipx2 ? clipx2 : x2; } 81 int16_t bound_y2(int16_t y2) { return y2 > clipy2 ? clipy2 : y2; } 82 int16_t x1_clip() { return clipx1; } 83 int16_t y1_clip() { return clipy1; } 84 int16_t x2_clip() { return clipx2; } 85 int16_t y2_clip() { return clipy2; } 86 void dirty_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } 87 void clean_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } 88 void clear_dirties(); 89 int16_t get_dirty_area(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 90 { 91 return 0; 92 } 93 void get_clip(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 94 { 95 x1 = clipx1; y1 = clipy1; x2 = clipx2; y2 = clipy2; 96 } 97 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 98 { 99 if(x2 < x1) x2 = x1; 100 if(y2 < y1) y2 = y1; 101 if(x1 < 0) clipx1 = 0; else clipx1 = x1; 102 if(y1 < 0) clipy1 = 0; else clipy1 = y1; 103 if(x2 >= l) clipx2 = l - 1; else clipx2 = x2; 104 if(y2 >= h) clipy2 = h - 1; else clipy2 = y2; 105 } 106 void reduce_dirties(); 107 void add_dirty(int x1, int y1, int x2, int y2); 108 void delete_dirty(int x1, int y1, int x2, int y2); 109 void resize(int16_t length, int16_t height) 110 { 111 l = length; h = height; 112 clipx1 = 0; clipy1 = 0; clipx2 = l - 1; clipy2 = h - 1; 113 } 114 }; 103 115 104 116 class image : public linked_node 105 { 106 uint8_t *data; 107 int16_t w,h; 108 void make_page(int16_t width, int16_t height, uint8_t *page_buffer); 109 void delete_page(); 110 public : 111 image_descriptor *special; 112 image(spec_entry *e, bFILE *fp); 113 image(bFILE *fp); 114 image(int16_t width, int16_t height, // required 115 uint8_t *page_buffer=NULL, 116 int16_t create_descriptor=0); // 0=no, 1=yes, 2=yes & keep dirties 117 uint8_t pixel (int16_t x, int16_t y); 118 void putpixel (int16_t x, int16_t y, char color); 119 uint8_t *scan_line (int16_t y) { return data+y*w; } 120 uint8_t *next_line (int16_t lasty, uint8_t *last_scan) 121 { return last_scan+w; } 122 int32_t total_pixels (uint8_t background=0); 123 image *copy (); // makes a copy of an image 124 void clear (int16_t color=-1); // -1 is background color 125 void to_24bit (palette &pal); 126 int16_t width () { return (int16_t)w; } 127 int16_t height () { return (int16_t)h; } 128 void scroll (int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd); 129 void fill_image (image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, 130 int16_t align=1); 131 void put_image (image *screen, int16_t x, int16_t y, char transparent=0); 132 void put_part (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, 133 int16_t x2, int16_t y2, char transparent=0); 134 void put_part_xrev (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, 135 int16_t x2, int16_t y2, char transparent=0); 136 void put_part_masked (image *screen, image *mask, int16_t x, int16_t y, 137 int16_t maskx, int16_t masky, int16_t x1, int16_t y1, int16_t x2, int16_t y2); 138 image *copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2); 139 void bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 140 void xor_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 141 void widget_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, 142 uint8_t light, uint8_t med, uint8_t dark); 143 void line (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 144 void rectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 145 void burn_led (int16_t x, int16_t y, int32_t num, int16_t color, int16_t scale=1); 146 void set_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2); 147 void get_clip (int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2); 148 void in_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2); 149 150 void dirt_off () { if (special && special->keep_dirt) special->keep_dirt=0; } 151 void dirt_on () { if (special) special->keep_dirt=1; } 152 153 void add_dirty (int x1, int y1, int x2, int y2) 154 { if (special) special->add_dirty(x1,y1,x2,y2); } 155 void delete_dirty (int x1, int y1, int x2, int y2) 156 { if (special) special->delete_dirty(x1,y1,x2,y2); } 157 void clear_dirties () { if (special) special->clear_dirties(); } 158 void dither (palette *pal); // use a b&w palette! 159 void resize (int16_t new_width, int16_t new_height); 160 void change_size (int16_t new_width, int16_t new_height, uint8_t *page=NULL); 161 void flood_fill (int16_t x, int16_t y, uint8_t color); 162 image *create_smooth (int16_t smoothness=1); // 0 no smoothness 163 void unpack_scanline (int16_t line, char bitsperpixel=1); 164 uint8_t brightest_color (palette *pal); 165 void flip_x (); 166 void flip_y (); 167 void make_color (uint8_t color); 168 uint8_t darkest_color (palette *pal, int16_t noblack=0); 169 170 ~image(); 171 } ; 172 117 { 118 private: 119 uint8_t *data; 120 int16_t w, h; 121 void make_page(int16_t width, int16_t height, uint8_t *page_buffer); 122 void delete_page(); 123 bool _locked; 124 125 public: 126 image_descriptor *special; 127 128 image(spec_entry *e, bFILE *fp); 129 image(bFILE *fp); 130 image(int16_t width, int16_t height, 131 uint8_t *page_buffer = NULL, int16_t create_descriptor = 0); 132 ~image(); 133 134 void lock(); 135 void unlock(); 136 137 uint8_t pixel(int16_t x, int16_t y); 138 void putpixel(int16_t x, int16_t y, char color); 139 uint8_t *scan_line(int16_t y) 140 { 141 return data + y * w; 142 } 143 uint8_t *next_line(int16_t lasty, uint8_t *last_scan) 144 { 145 return last_scan + w; 146 } 147 int32_t total_pixels(uint8_t background=0); 148 image *copy(); // makes a copy of an image 149 void clear(int16_t color = -1); // -1 is background color 150 void to_24bit(palette &pal); 151 int16_t width() 152 { 153 return (int16_t)w; 154 } 155 int16_t height() 156 { 157 return (int16_t)h; 158 } 159 void scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 160 int16_t xd, int16_t yd); 161 void fill_image(image *screen, int16_t x1, int16_t y1, 162 int16_t x2, int16_t y2, int16_t align = 1); 163 void put_image(image *screen, int16_t x, int16_t y, char transparent = 0); 164 void put_part(image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, 165 int16_t x2, int16_t y2, char transparent = 0); 166 void put_part_xrev(image *screen, int16_t x, int16_t y, 167 int16_t x1, int16_t y1, int16_t x2, int16_t y2, 168 char transparent = 0); 169 void put_part_masked(image *screen, image *mask, int16_t x, int16_t y, 170 int16_t maskx, int16_t masky, int16_t x1, int16_t y1, 171 int16_t x2, int16_t y2); 172 image *copy_part_dithered(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 173 void bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 174 void xor_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 175 void widget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 176 uint8_t light, uint8_t med, uint8_t dark); 177 void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 178 void rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 179 uint8_t color); 180 void burn_led(int16_t x, int16_t y, int32_t num, int16_t color, 181 int16_t scale = 1); 182 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 183 void get_clip(int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2); 184 void in_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 185 186 void dirt_off() 187 { 188 if(special && special->keep_dirt) special->keep_dirt = 0; 189 } 190 void dirt_on() 191 { 192 if(special) special->keep_dirt = 1; 193 } 194 195 void add_dirty(int x1, int y1, int x2, int y2) 196 { 197 if(special) special->add_dirty(x1, y1, x2, y2); 198 } 199 void delete_dirty(int x1, int y1, int x2, int y2) 200 { 201 if(special) special->delete_dirty(x1, y1, x2, y2); 202 } 203 void clear_dirties() 204 { 205 if(special) special->clear_dirties(); 206 } 207 void dither(palette *pal); // use a b&w palette! 208 void resize(int16_t new_width, int16_t new_height); 209 void change_size(int16_t new_width, int16_t new_height, 210 uint8_t *page = NULL); 211 void flood_fill(int16_t x, int16_t y, uint8_t color); 212 image *create_smooth(int16_t smoothness = 1); // 0 no smoothness 213 void unpack_scanline(int16_t line, char bitsperpixel = 1); 214 uint8_t brightest_color(palette *pal); 215 void flip_x(); 216 void flip_y(); 217 void make_color(uint8_t color); 218 uint8_t darkest_color(palette *pal, int16_t noblack = 0); 219 }; 173 220 174 221 class image_controller 175 222 { 176 public : 177 image_controller() { image_init(); } 178 ~image_controller() 179 { 180 image_uninit(); 181 } 182 } ; 183 184 185 186 #endif 187 188 189 190 191 192 193 194 223 public: 224 image_controller() 225 { 226 image_init(); 227 } 228 ~image_controller() 229 { 230 image_uninit(); 231 } 232 }; 233 234 #endif /* _IMAGE_HPP_ */ 235 -
abuse/trunk/src/imlib/morph.cpp
r112 r115 33 33 { 34 34 morph_point8 *m8=(morph_point8 *)p; 35 screen->lock(); 35 36 for (i=0;i<total;i++,m8++) 36 37 { … … 50 51 } 51 52 } 53 screen->unlock(); 52 54 } 53 55 } … … 62 64 short cx1,cy1,cx2,cy2; 63 65 screen->get_clip(cx1,cy1,cx2,cy2); 66 screen->lock(); 64 67 while (tot--) 65 68 { … … 76 79 } 77 80 } 81 screen->unlock(); 78 82 } 79 83 … … 85 89 short cx1,cy1,cx2,cy2; 86 90 screen->get_clip(cx1,cy1,cx2,cy2); 91 screen->lock(); 87 92 while (tot--) 88 93 { … … 99 104 } 100 105 } 106 screen->unlock(); 101 107 } 102 108 -
abuse/trunk/src/imlib/scroller.cpp
r112 r115 59 59 remap[2]=wm->dark_color(); 60 60 61 screen->lock(); 61 62 for (int yc=ich;yc;yc--,y++) 62 63 { … … 72 73 } 73 74 screen->add_dirty(x,y,x+icw-1,y+ich-1); 75 screen->unlock(); 74 76 } 75 77 -
abuse/trunk/src/imlib/timage.cpp
r56 r115 23 23 x+=*(dp++); 24 24 if (x<w) 25 { 26 27 28 29 25 { 26 int run=*(dp++); 27 memset(dp,c,run); 28 x+=run; 29 dp+=run; 30 30 } 31 31 } … … 36 36 { 37 37 image *im=new image(w,h); 38 39 im->lock(); 38 40 uint8_t *d=im->scan_line(0),*dp=data,*dline; 39 41 int y,x; … … 49 51 x+=skip; 50 52 if (x<w) 51 { 52 53 54 55 56 53 { 54 int run=*(dp++); 55 memcpy(dline,dp,run); 56 x+=run; 57 dline+=run; 58 dp+=run; 57 59 } 58 60 } 59 61 d=im->next_line(y,d); 60 62 } 63 im->unlock(); 61 64 return im; 62 65 } … … 65 68 { 66 69 int size=0,x,y; 67 uint8_t *sl,*datap,*marker; 70 uint8_t *sl,*datap,*marker; 68 71 w=im->width(); 69 72 h=im->height(); 70 73 74 im->lock(); 75 71 76 // first we must find out how much data to allocate 72 77 for (y=0;y<im->height();y++) 73 78 { 74 79 sl=im->scan_line(y); 75 x=0; 80 x=0; 76 81 while (x<w) 77 { 78 size++; 79 while (x<w && *sl==0) { sl++; x++; } 80 82 { 83 size++; 84 while (x<w && *sl==0) { sl++; x++; } 85 81 86 if (x<w) 82 87 { 83 size++; // byte for the size of the run 88 size++; // byte for the size of the run 84 89 while (x<w && (*sl)!=0) 85 90 { 86 87 88 sl++; 89 } 90 } 91 } 92 } 91 size++; 92 x++; 93 sl++; 94 } 95 } 96 } 97 } 93 98 94 99 #ifdef MEM_CHECK … … 104 109 { printf("size = %d %d (%d)\n",im->width(),im->height(),size); } 105 110 CONDITION(datap,"malloc error for trans_image::data"); 106 111 107 112 for (y=0;y<hh;y++) // now actually make the runs 108 113 { 109 114 sl=im->scan_line(y); 110 x=0; 115 x=0; 111 116 while (x<ww) 112 { 113 *datap=0; // start the skip at 0 114 while (x<im->width() && (*sl)==0) 115 { sl++; x++; (*datap)++; } 116 datap++; 117 117 { 118 *datap=0; // start the skip at 0 119 while (x<im->width() && (*sl)==0) 120 { sl++; x++; (*datap)++; } 121 datap++; 122 118 123 if (x<ww) 119 124 { 120 125 marker=datap; // let marker be the run size 121 122 datap++; // skip over this spot 126 *marker=0; 127 datap++; // skip over this spot 123 128 while (x<im->width() && (*sl)!=0) 124 { 125 (*marker)++; 126 (*datap)=*sl; 127 datap++; 128 x++; 129 sl++; 130 } 131 } 132 } 133 } 134 } 135 136 void trans_image::put_scan_line(image *screen, int x, int y, int line) // always transparent 129 { 130 (*marker)++; 131 (*datap)=*sl; 132 datap++; 133 x++; 134 sl++; 135 } 136 } 137 } 138 } 139 im->unlock(); 140 } 141 142 void trans_image::put_scan_line(image *screen, int x, int y, int line) // always transparent 137 143 { 138 144 int16_t x1,y1,x2,y2; … … 142 148 143 149 uint8_t *datap=data; 144 int ix; 150 int ix; 145 151 while (line) // skip scan line data until we get to the line of interest 146 152 { 147 for (ix=0;ix<w;) 148 { 153 for (ix=0;ix<w;) 154 { 149 155 ix+=*datap; // skip blank space 150 156 datap++; 151 if (ix<w) 152 { 153 154 155 156 } 157 } 158 line--; 159 y++; 160 } 161 162 157 if (ix<w) 158 { 159 int run_length=*datap; // skip run 160 ix+=run_length; 161 datap+=run_length+1; 162 } 163 } 164 line--; 165 y++; 166 } 167 168 163 169 // now slam this list of runs to the screen 170 screen->lock(); 164 171 uint8_t *screen_line=screen->scan_line(y)+x; 165 166 for (ix=0;ix<w;) 167 { 172 173 for (ix=0;ix<w;) 174 { 168 175 int skip=*datap; // how much space to skip? 169 176 datap++; 170 177 screen_line+=skip; 171 ix+=skip; 172 178 ix+=skip; 179 173 180 if (ix<w) 174 { 181 { 175 182 int run_length=*datap; 176 183 datap++; … … 178 185 if (x+ix+run_length-1<x1) // is this run clipped out totally? 179 186 { 180 181 182 187 datap+=run_length; 188 ix+=run_length; 189 screen_line+=run_length; 183 190 } 184 191 else 185 { 186 if (x+ix<x1) // is the run clipped partially? 187 { 188 int clip=(x1-(x+ix)); 189 datap+=clip; 190 run_length-=clip; 191 screen_line+=clip; 192 ix+=clip; 193 } 194 195 if (x+ix>x2) // clipped totally on the right? 192 { 193 if (x+ix<x1) // is the run clipped partially? 194 { 195 int clip=(x1-(x+ix)); 196 datap+=clip; 197 run_length-=clip; 198 screen_line+=clip; 199 ix+=clip; 200 } 201 202 if (x+ix>x2) // clipped totally on the right? 203 { 204 screen->unlock(); 196 205 return ; // we are done, return! 197 else if (x+ix+run_length-1>x2) // partially clipped? 198 { 199 memcpy(screen_line,datap,(x+ix+run_length-1)-x2); // slam what we can 200 return ; // and return 'cause we are done with the line 206 } 207 else if (x+ix+run_length-1>x2) // partially clipped? 208 { 209 memcpy(screen_line,datap,(x+ix+run_length-1)-x2); // slam what we can 210 screen->unlock(); 211 return ; // and return 'cause we are done with the line 201 212 } else 202 213 { 203 memcpy(screen_line,datap,run_length); 204 205 206 ix+=run_length;207 } 208 } 209 } 210 } 211 212 } 213 214 215 inline uint8_t *trans_image::clip_y(image *screen, int x1, int y1, int x2, int y2, 216 214 memcpy(screen_line,datap,run_length); 215 screen_line+=run_length; 216 datap+=run_length; 217 ix+=run_length; 218 } 219 } 220 } 221 } 222 screen->unlock(); 223 } 224 225 226 inline uint8_t *trans_image::clip_y(image *screen, int x1, int y1, int x2, int y2, 227 int x, int &y, int &ysteps) 217 228 { 218 229 // check to see if it is total clipped out first … … 220 231 return NULL; 221 232 222 register uint8_t *datap=data;233 uint8_t *datap=data; 223 234 224 235 225 236 ysteps=height(); 226 237 227 238 if (y<y1) // check to see if the image gets clipped at the top 228 239 { … … 230 241 231 242 // because data is stored in runs, we need to skip over the top clipped portion 232 int skips=(y1-y); // how many lines do we need to skip? 243 int skips=(y1-y); // how many lines do we need to skip? 233 244 ysteps-=skips; // reduce h (number of lines to draw) 234 245 y=y1; // start drawing here now 235 246 while (skips--) 236 { 237 registerint ix=0;247 { 248 int ix=0; 238 249 while (ix<w) 239 { 250 { 240 251 ix+=(*datap); // skip over empty space 241 datap++; 242 if (ix<w) 243 { ix+=*datap; 244 245 } 246 } 247 } 248 } 249 252 datap++; 253 if (ix<w) 254 { ix+=*datap; 255 datap+=(*datap)+1; // skip over data 256 } 257 } 258 } 259 } 260 250 261 if (y+ysteps>y2) // check to see if it gets clipped at the bottom 251 262 ysteps-=(y+ysteps-y2-1); 252 263 253 screen->add_dirty(max(x,x1),y,min(x+width()-1,x2),y+h-1); 264 screen->add_dirty(max(x,x1),y,min(x+width()-1,x2),y+h-1); 254 265 return datap; 255 } 256 257 void trans_image::put_image_filled(image *screen, int x, int y, 258 266 } 267 268 void trans_image::put_image_filled(image *screen, int x, int y, 269 uint8_t fill_color) 259 270 { 260 271 int16_t x1,y1,x2,y2; … … 262 273 263 274 screen->get_clip(x1,y1,x2,y2); 264 registeruint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;275 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line; 265 276 if (!datap) return ; // if clip_y says nothing to draw, return 266 267 screen_line=screen->scan_line(y)+x; 277 278 screen->lock(); 279 280 screen_line=screen->scan_line(y)+x; 268 281 int sw=screen->width()-w; 269 282 x1-=x; x2-=x; 270 283 for (;ysteps>0;ysteps--) 271 { 272 registerint ix,slam_length;284 { 285 int ix,slam_length; 273 286 for (ix=0;ix<w;) 274 287 { … … 277 290 ix+=blank; // skip over empty space 278 291 screen_line+=blank; 279 280 datap++; 281 if (ix<w) 282 { 283 slam_length=*datap; // find the length of this run 284 datap++; 285 286 287 288 289 290 291 292 { 293 294 { 295 chop_length=(x1-ix); 296 297 298 299 300 301 datap+=slam_length; 302 slam_length=0; 303 304 { 305 slam_length-=chop_length; // else advance everything to begining of slam 306 307 308 datap+=chop_length; 309 } 310 } 311 312 313 314 315 316 317 318 319 ix+=slam_length; 320 321 } 322 323 } 292 293 datap++; 294 if (ix<w) 295 { 296 slam_length=*datap; // find the length of this run 297 datap++; 298 if (ix+slam_length<x1 || ix>x2) // see if this run is totally clipped 299 { 300 datap+=slam_length; 301 ix+=slam_length; 302 screen_line+=slam_length; 303 } 304 else 305 { 306 if (ix<x1) // the left side needs to be chopped ? 307 { 308 chop_length=(x1-ix); 309 310 if (chop_length>=slam_length) // see if we chopped it all off 311 { // yes, we did 312 ix+=slam_length; // advance everything to the end of run 313 screen_line+=slam_length; 314 datap+=slam_length; 315 slam_length=0; 316 } else 317 { 318 slam_length-=chop_length; // else advance everything to begining of slam 319 ix+=chop_length; 320 screen_line+=chop_length; 321 datap+=chop_length; 322 } 323 } 324 325 if (slam_length) // see if there is anything left to slam 326 { 327 if (ix+slam_length>x2) // see if right side needs to be chopped off 328 memcpy(screen_line,datap,x2-ix+1); 329 else 330 memcpy(screen_line,datap,slam_length); 331 datap+=slam_length; 332 ix+=slam_length; 333 screen_line+=slam_length; 334 } 335 } 336 } 324 337 } 325 338 screen_line+=sw; 326 } 339 } 340 screen->unlock(); 327 341 } 328 342 … … 330 344 { 331 345 int ix,ysteps=height(); 332 int screen_skip =screen->width()-w;346 int screen_skip; 333 347 uint8_t skip,*datap=data; 348 349 screen->lock(); 350 screen_skip = screen->width() - w; 334 351 for (;ysteps;ysteps--) 335 352 { … … 342 359 343 360 if (s_off<screen->scan_line(0)) 344 printf("bad write");361 printf("bad write in trans_image::put_image_offseted"); 345 362 346 363 347 364 if (ix<w) 348 365 { 349 350 351 352 353 354 355 356 357 printf("bad write");366 skip=*datap; 367 datap++; 368 memcpy(s_off,datap,skip); 369 datap+=skip; 370 s_off+=skip; 371 ix+=skip; 372 373 if (s_off>=screen->scan_line(screen->height()+1)) 374 printf("bad write in trans_image::put_image_offseted"); 358 375 } 359 376 } 360 377 s_off+=screen_skip; 361 378 } 362 } 363 364 void trans_image::put_image(image *screen, int x, int y) 379 screen->unlock(); 380 } 381 382 void trans_image::put_image(image *screen, int x, int y) 365 383 { 366 384 int16_t x1,y1,x2,y2; … … 368 386 369 387 screen->get_clip(x1,y1,x2,y2); 370 registeruint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;388 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line; 371 389 if (!datap) return ; // if clip_y says nothing to draw, return 372 373 screen_line=screen->scan_line(y)+x; 390 391 screen->lock(); 392 screen_line=screen->scan_line(y)+x; 374 393 int sw=screen->width(); 375 394 x1-=x; x2-=x; 376 395 for (;ysteps>0;ysteps--) 377 { 378 registerint ix,slam_length;396 { 397 int ix,slam_length; 379 398 for (ix=0;ix<w;) 380 399 { 381 400 ix+=(*datap); // skip over empty space 382 datap++; 383 if (ix<w) 384 { 385 slam_length=*datap; // find the length of this run 386 datap++; 387 388 389 390 ix+=slam_length; 391 392 393 { 394 395 { 396 chop_length=(x1-ix); 397 398 399 400 401 datap+=slam_length; 402 slam_length=0; 403 404 { 405 slam_length-=chop_length; // else advance everything to begining of slam 406 407 datap+=chop_length; 408 } 409 } 410 411 412 413 414 415 416 417 418 ix+=slam_length; 419 } 420 421 } 401 datap++; 402 if (ix<w) 403 { 404 slam_length=*datap; // find the length of this run 405 datap++; 406 if (ix+slam_length<x1 || ix>x2) // see if this run is totally clipped 407 { 408 datap+=slam_length; 409 ix+=slam_length; 410 } 411 else 412 { 413 if (ix<x1) // the left side needs to be chopped ? 414 { 415 chop_length=(x1-ix); 416 417 if (chop_length>=slam_length) // see if we chopped it all off 418 { // yes, we did 419 ix+=slam_length; // advance everything to the end of run 420 datap+=slam_length; 421 slam_length=0; 422 } else 423 { 424 slam_length-=chop_length; // else advance everything to begining of slam 425 ix+=chop_length; 426 datap+=chop_length; 427 } 428 } 429 430 if (slam_length) // see if there is anything left to slam 431 { 432 if (ix+slam_length>x2) // see if right side needs to be chopped off 433 memcpy(screen_line+ix,datap,x2-ix+1); 434 else 435 memcpy(screen_line+ix,datap,slam_length); 436 datap+=slam_length; 437 ix+=slam_length; 438 } 439 } 440 } 422 441 } 423 442 screen_line+=sw; 424 } 425 } 426 427 void trans_image::put_remaped(image *screen, int x, int y, uint8_t *remap) 443 } 444 screen->unlock(); 445 } 446 447 void trans_image::put_remaped(image *screen, int x, int y, uint8_t *remap) 428 448 { 429 449 int16_t x1,y1,x2,y2; … … 431 451 432 452 screen->get_clip(x1,y1,x2,y2); 433 registeruint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;453 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line; 434 454 if (!datap) return ; // if clip_y says nothing to draw, return 435 436 screen_line=screen->scan_line(y)+x; 455 456 screen->lock(); 457 screen_line=screen->scan_line(y)+x; 437 458 int sw=screen->width(); 438 459 x1-=x; x2-=x; 439 460 for (;ysteps>0;ysteps--) 440 { 441 registerint ix,slam_length;461 { 462 int ix,slam_length; 442 463 for (ix=0;ix<w;) 443 464 { 444 465 ix+=(*datap); // skip over empty space 445 datap++; 446 if (ix<w) 447 { 448 slam_length=*datap; // find the length of this run 449 datap++; 450 451 452 453 ix+=slam_length; 454 455 456 { 457 458 { 459 chop_length=(x1-ix); 460 461 462 463 464 datap+=slam_length; 465 slam_length=0; 466 467 { 468 slam_length-=chop_length; // else advance everything to begining of slam 469 470 datap+=chop_length; 471 } 472 } 473 474 475 476 477 registerint counter;478 if (ix+slam_length>x2) // see if right side needs to be chopped off 479 480 481 482 483 registeruint8_t *sl=screen_line+ix,*sl2=datap;484 ix+=slam_length; 485 486 487 488 489 490 491 492 493 } 494 495 } 466 datap++; 467 if (ix<w) 468 { 469 slam_length=*datap; // find the length of this run 470 datap++; 471 if (ix+slam_length<x1 || ix>x2) // see if this run is totally clipped 472 { 473 datap+=slam_length; 474 ix+=slam_length; 475 } 476 else 477 { 478 if (ix<x1) // the left side needs to be chopped ? 479 { 480 chop_length=(x1-ix); 481 482 if (chop_length>=slam_length) // see if we chopped it all off 483 { // yes, we did 484 ix+=slam_length; // advance everything to the end of run 485 datap+=slam_length; 486 slam_length=0; 487 } else 488 { 489 slam_length-=chop_length; // else advance everything to begining of slam 490 ix+=chop_length; 491 datap+=chop_length; 492 } 493 } 494 495 496 if (slam_length) // see if there is anything left to slam 497 { 498 int counter; 499 if (ix+slam_length>x2) // see if right side needs to be chopped off 500 counter=x2-ix+1; 501 else 502 counter=slam_length; 503 504 uint8_t *sl=screen_line+ix,*sl2=datap; 505 ix+=slam_length; 506 datap+=slam_length; 507 while (counter) 508 { 509 counter--; 510 *(sl)=remap[*(sl2)]; 511 sl++; 512 sl2++; 513 } 514 } 515 } 516 } 496 517 } 497 518 screen_line+=sw; 498 } 499 } 500 501 502 503 void trans_image::put_double_remaped(image *screen, int x, int y, uint8_t *remap, uint8_t *remap2) 519 } 520 screen->unlock(); 521 } 522 523 524 525 void trans_image::put_double_remaped(image *screen, int x, int y, uint8_t *remap, uint8_t *remap2) 504 526 { 505 527 int16_t x1,y1,x2,y2; … … 507 529 508 530 screen->get_clip(x1,y1,x2,y2); 509 registeruint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;531 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line; 510 532 if (!datap) return ; // if clip_y says nothing to draw, return 511 512 screen_line=screen->scan_line(y)+x; 533 534 screen->lock(); 535 screen_line=screen->scan_line(y)+x; 513 536 int sw=screen->width(); 514 537 x1-=x; x2-=x; 515 538 for (;ysteps>0;ysteps--) 516 { 517 registerint ix,slam_length;539 { 540 int ix,slam_length; 518 541 for (ix=0;ix<w;) 519 542 { 520 543 ix+=(*datap); // skip over empty space 521 datap++; 522 if (ix<w) 523 { 524 slam_length=*datap; // find the length of this run 525 datap++; 526 527 528 529 ix+=slam_length; 530 531 532 { 533 534 { 535 chop_length=(x1-ix); 536 537 538 539 540 datap+=slam_length; 541 slam_length=0; 542 543 { 544 slam_length-=chop_length; // else advance everything to begining of slam 545 546 datap+=chop_length; 547 } 548 } 549 550 551 552 553 registerint counter;554 if (ix+slam_length>x2) // see if right side needs to be chopped off 555 556 557 558 559 registeruint8_t *sl=screen_line+ix,*sl2=datap;560 ix+=slam_length; 561 562 563 564 565 566 567 568 569 } 570 571 } 544 datap++; 545 if (ix<w) 546 { 547 slam_length=*datap; // find the length of this run 548 datap++; 549 if (ix+slam_length<x1 || ix>x2) // see if this run is totally clipped 550 { 551 datap+=slam_length; 552 ix+=slam_length; 553 } 554 else 555 { 556 if (ix<x1) // the left side needs to be chopped ? 557 { 558 chop_length=(x1-ix); 559 560 if (chop_length>=slam_length) // see if we chopped it all off 561 { // yes, we did 562 ix+=slam_length; // advance everything to the end of run 563 datap+=slam_length; 564 slam_length=0; 565 } else 566 { 567 slam_length-=chop_length; // else advance everything to begining of slam 568 ix+=chop_length; 569 datap+=chop_length; 570 } 571 } 572 573 574 if (slam_length) // see if there is anything left to slam 575 { 576 int counter; 577 if (ix+slam_length>x2) // see if right side needs to be chopped off 578 counter=x2-ix+1; 579 else 580 counter=slam_length; 581 582 uint8_t *sl=screen_line+ix,*sl2=datap; 583 ix+=slam_length; 584 datap+=slam_length; 585 while (counter) 586 { 587 counter--; 588 *(sl)=remap2[remap[*(sl2)]]; 589 sl++; 590 sl2++; 591 } 592 } 593 } 594 } 572 595 } 573 596 screen_line+=sw; 574 } 597 } 598 screen->unlock(); 575 599 } 576 600 … … 578 602 579 603 void trans_image::put_fade(image *screen, int x, int y, 580 int frame_on, int total_frames, 581 color_filter *f, palette *pal) 604 int frame_on, int total_frames, 605 color_filter *f, palette *pal) 582 606 { 583 607 int16_t x1,y1,x2,y2; … … 593 617 594 618 long fixmul=(frame_on<<16)/total_frames; 619 screen->lock(); 595 620 for (;ysteps>0;ysteps--,y++) 596 { 621 { 597 622 screen_line=screen->scan_line(y); 598 623 599 624 for (ix=0;ix<w;) 600 625 { 601 626 ix+=(*datap); // skip over empty space 602 datap++; 603 if (ix<w) 604 { 605 slam_length=*datap; // find the length of this run 606 datap++; 607 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 608 { 609 datap+=slam_length; 610 ix+=slam_length; 611 } 612 else 613 { 614 if (x+ix<x1) // the left side needs to be chopped ? 615 { 616 chop_length=(x1-x-ix); 617 618 if (chop_length>=slam_length) // see if we chopped it all off 619 { // yes, we did 620 ix+=slam_length; // advance everything to the end of run 621 datap+=slam_length; 622 slam_length=0; 623 } else 624 { 625 slam_length-=chop_length; // else advance everything to begining of slam 626 ix+=chop_length; 627 datap+=chop_length; 628 } 629 } 630 631 if (slam_length) // see if there is anything left to slam 632 { 633 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 634 chop_length=x2-x-ix; 635 else chop_length=slam_length; 636 screen_run=screen_line+x+ix; 637 638 slam_length-=chop_length; 639 ix+=chop_length; 640 641 while (chop_length--) 642 { 643 caddr1=paddr+(int)(*screen_run)*3; 644 caddr2=paddr+(int)(*datap)*3; 645 646 r_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 647 caddr1++; caddr2++; 648 649 g_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 650 caddr1++; caddr2++; 651 652 b_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 653 *screen_run=f->lookup_color(r_dest>>3,g_dest>>3,b_dest>>3); 654 655 screen_run++; 656 datap++; 657 } 658 datap+=slam_length; 659 ix+=slam_length; 660 } 661 } 662 } 663 } 664 } 627 datap++; 628 if (ix<w) 629 { 630 slam_length=*datap; // find the length of this run 631 datap++; 632 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 633 { 634 datap+=slam_length; 635 ix+=slam_length; 636 } 637 else 638 { 639 if (x+ix<x1) // the left side needs to be chopped ? 640 { 641 chop_length=(x1-x-ix); 642 643 if (chop_length>=slam_length) // see if we chopped it all off 644 { // yes, we did 645 ix+=slam_length; // advance everything to the end of run 646 datap+=slam_length; 647 slam_length=0; 648 } else 649 { 650 slam_length-=chop_length; // else advance everything to begining of slam 651 ix+=chop_length; 652 datap+=chop_length; 653 } 654 } 655 656 if (slam_length) // see if there is anything left to slam 657 { 658 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 659 chop_length=x2-x-ix; 660 else chop_length=slam_length; 661 screen_run=screen_line+x+ix; 662 663 slam_length-=chop_length; 664 ix+=chop_length; 665 666 while (chop_length--) 667 { 668 caddr1=paddr+(int)(*screen_run)*3; 669 caddr2=paddr+(int)(*datap)*3; 670 671 r_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 672 caddr1++; caddr2++; 673 674 g_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 675 caddr1++; caddr2++; 676 677 b_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 678 *screen_run=f->lookup_color(r_dest>>3,g_dest>>3,b_dest>>3); 679 680 screen_run++; 681 datap++; 682 } 683 datap+=slam_length; 684 ix+=slam_length; 685 } 686 } 687 } 688 } 689 } 690 screen->unlock(); 665 691 } 666 692 … … 669 695 670 696 void trans_image::put_fade_tint(image *screen, int x, int y, 671 int frame_on, int total_frames, 672 673 color_filter *f, palette *pal) 697 int frame_on, int total_frames, 698 uint8_t *tint, 699 color_filter *f, palette *pal) 674 700 { 675 701 int16_t x1,y1,x2,y2; … … 681 707 if (!datap) return ; 682 708 709 screen->lock(); 683 710 uint8_t *screen_run,*paddr=(uint8_t *)pal->addr(), 684 711 *caddr1,*caddr2,r_dest,g_dest,b_dest; … … 686 713 long fixmul=(frame_on<<16)/total_frames; 687 714 for (;ysteps>0;ysteps--,y++) 688 { 715 { 689 716 screen_line=screen->scan_line(y); 690 717 691 718 for (ix=0;ix<w;) 692 719 { 693 720 ix+=(*datap); // skip over empty space 694 datap++; 695 if (ix<w) 696 { 697 slam_length=*datap; // find the length of this run 698 datap++; 699 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 700 { 701 datap+=slam_length; 702 ix+=slam_length; 703 } 704 else 705 { 706 if (x+ix<x1) // the left side needs to be chopped ? 707 { 708 chop_length=(x1-x-ix); 709 710 if (chop_length>=slam_length) // see if we chopped it all off 711 { // yes, we did 712 ix+=slam_length; // advance everything to the end of run 713 datap+=slam_length; 714 slam_length=0; 715 } else 716 { 717 slam_length-=chop_length; // else advance everything to begining of slam 718 ix+=chop_length; 719 datap+=chop_length; 720 } 721 } 722 723 if (slam_length) // see if there is anything left to slam 724 { 725 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 726 chop_length=x2-x-ix; 727 else chop_length=slam_length; 728 screen_run=screen_line+x+ix; 729 730 slam_length-=chop_length; 731 ix+=chop_length; 732 733 while (chop_length--) 734 { 735 caddr1=paddr+(int)(*screen_run)*3; 736 caddr2=paddr+(int)(tint[*datap])*3; 737 738 r_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 739 caddr1++; caddr2++; 740 741 g_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 742 caddr1++; caddr2++; 743 744 b_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 745 *screen_run=f->lookup_color(r_dest>>3,g_dest>>3,b_dest>>3); 746 747 screen_run++; 748 datap++; 749 } 750 datap+=slam_length; 751 ix+=slam_length; 752 } 753 } 754 } 755 } 756 } 757 } 758 759 760 761 762 763 764 void trans_image::put_color(image *screen, int x, int y, int color) 721 datap++; 722 if (ix<w) 723 { 724 slam_length=*datap; // find the length of this run 725 datap++; 726 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 727 { 728 datap+=slam_length; 729 ix+=slam_length; 730 } 731 else 732 { 733 if (x+ix<x1) // the left side needs to be chopped ? 734 { 735 chop_length=(x1-x-ix); 736 737 if (chop_length>=slam_length) // see if we chopped it all off 738 { // yes, we did 739 ix+=slam_length; // advance everything to the end of run 740 datap+=slam_length; 741 slam_length=0; 742 } else 743 { 744 slam_length-=chop_length; // else advance everything to begining of slam 745 ix+=chop_length; 746 datap+=chop_length; 747 } 748 } 749 750 if (slam_length) // see if there is anything left to slam 751 { 752 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 753 chop_length=x2-x-ix; 754 else chop_length=slam_length; 755 screen_run=screen_line+x+ix; 756 757 slam_length-=chop_length; 758 ix+=chop_length; 759 760 while (chop_length--) 761 { 762 caddr1=paddr+(int)(*screen_run)*3; 763 caddr2=paddr+(int)(tint[*datap])*3; 764 765 r_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 766 caddr1++; caddr2++; 767 768 g_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 769 caddr1++; caddr2++; 770 771 b_dest=((((int)(*caddr1)-(int)(*caddr2))*fixmul)>>16)+(int)(*caddr2); 772 *screen_run=f->lookup_color(r_dest>>3,g_dest>>3,b_dest>>3); 773 774 screen_run++; 775 datap++; 776 } 777 datap+=slam_length; 778 ix+=slam_length; 779 } 780 } 781 } 782 } 783 } 784 screen->unlock(); 785 } 786 787 void trans_image::put_color(image *screen, int x, int y, int color) 765 788 { 766 789 int16_t x1,y1,x2,y2; 767 790 int ix,slam_length,chop_length,ysteps; 768 791 769 792 screen->get_clip(x1,y1,x2,y2); 770 793 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps), 771 794 *screen_line; 772 795 if (!datap) return ; 773 774 796 797 screen->lock(); 775 798 for (;ysteps>0;ysteps--,y++) 776 { 799 { 777 800 screen_line=screen->scan_line(y); 778 801 779 802 for (ix=0;ix<w;) 780 803 { 781 804 ix+=(*datap); // skip over empty space 782 datap++; 783 if (ix<w) 784 { 785 slam_length=*datap; // find the length of this run 786 datap++; 787 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 788 { 789 datap+=slam_length; 790 ix+=slam_length; 791 } 792 else 793 { 794 if (x+ix<x1) // the left side needs to be chopped ? 795 { 796 chop_length=(x1-x-ix); 797 798 if (chop_length>=slam_length) // see if we chopped it all off 799 { // yes, we did 800 ix+=slam_length; // advance everything to the end of run 801 datap+=slam_length; 802 slam_length=0; 803 } else 804 { 805 slam_length-=chop_length; // else advance everything to begining of slam 806 ix+=chop_length; 807 datap+=chop_length; 808 } 809 } 810 811 if (slam_length) // see if there is anything left to slam 812 { 813 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 814 memset(screen_line+x+ix,color,x2-x-ix+1); 815 else 816 memset(screen_line+x+ix,color,slam_length); 817 datap+=slam_length; 818 ix+=slam_length; 819 } 820 } 821 } 822 } 823 } 805 datap++; 806 if (ix<w) 807 { 808 slam_length=*datap; // find the length of this run 809 datap++; 810 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 811 { 812 datap+=slam_length; 813 ix+=slam_length; 814 } 815 else 816 { 817 if (x+ix<x1) // the left side needs to be chopped ? 818 { 819 chop_length=(x1-x-ix); 820 821 if (chop_length>=slam_length) // see if we chopped it all off 822 { // yes, we did 823 ix+=slam_length; // advance everything to the end of run 824 datap+=slam_length; 825 slam_length=0; 826 } else 827 { 828 slam_length-=chop_length; // else advance everything to begining of slam 829 ix+=chop_length; 830 datap+=chop_length; 831 } 832 } 833 834 if (slam_length) // see if there is anything left to slam 835 { 836 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 837 memset(screen_line+x+ix,color,x2-x-ix+1); 838 else 839 memset(screen_line+x+ix,color,slam_length); 840 datap+=slam_length; 841 ix+=slam_length; 842 } 843 } 844 } 845 } 846 } 847 screen->unlock(); 824 848 } 825 849 826 850 827 851 // ASSUMES that the blend image completly covers this image 828 void trans_image::put_blend16(image *screen, image *blend, int x, int y, 829 852 void trans_image::put_blend16(image *screen, image *blend, int x, int y, 853 int blendx, int blendy, int blend_amount, color_filter *f, palette *pal) 830 854 831 855 { 832 856 int16_t x1,y1,x2,y2; 833 857 int ix,slam_length,chop_length,ysteps; 834 uint8_t *paddr=(uint8_t *)pal->addr(); 835 858 uint8_t *paddr=(uint8_t *)pal->addr(); 859 836 860 screen->get_clip(x1,y1,x2,y2); 837 861 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps), … … 839 863 if (!datap) return ; 840 864 CONDITION(y>=blendy && y+ysteps<blendy+blend->height()+1,"Blend doesn't fit on trans_image"); 841 865 842 866 blend_amount=16-blend_amount; 843 867 868 screen->lock(); 844 869 for (;ysteps>0;ysteps--,y++) 845 { 870 { 846 871 screen_line=screen->scan_line(y); 847 872 blend_line=blend->scan_line(y-blendy); 848 849 873 874 850 875 for (ix=0;ix<w;) 851 876 { 852 877 ix+=(*datap); // skip over empty space 853 datap++; 854 if (ix<w) 855 { 856 slam_length=*datap; // find the length of this run 857 datap++; 858 859 860 861 ix+=slam_length; 862 863 864 { 865 866 { 867 chop_length=(x1-x-ix); 868 869 870 871 872 datap+=slam_length; 873 slam_length=0; 874 875 { 876 slam_length-=chop_length; // else advance everything to begining of slam 877 878 datap+=chop_length; 879 } 880 } 881 882 883 884 885 886 887 888 889 890 891 *caddr1,*caddr2,r_dest,g_dest,b_dest; 892 893 894 ix+=chop_length; 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 datap++; 916 917 918 ix+=slam_length; 919 } 920 921 922 } 923 } 924 } 925 926 927 } 928 929 void trans_image::put_predator(image *screen, int x, int y) 878 datap++; 879 if (ix<w) 880 { 881 slam_length=*datap; // find the length of this run 882 datap++; 883 if (x+ix+slam_length<x1 || x+ix>x2) // see if this run is totally clipped 884 { 885 datap+=slam_length; 886 ix+=slam_length; 887 } 888 else 889 { 890 if (x+ix<x1) // the left side needs to be chopped ? 891 { 892 chop_length=(x1-x-ix); 893 894 if (chop_length>=slam_length) // see if we chopped it all off 895 { // yes, we did 896 ix+=slam_length; // advance everything to the end of run 897 datap+=slam_length; 898 slam_length=0; 899 } else 900 { 901 slam_length-=chop_length; // else advance everything to begining of slam 902 ix+=chop_length; 903 datap+=chop_length; 904 } 905 } 906 907 if (slam_length) // see if there is anything left to slam 908 { 909 910 if (x+ix+slam_length>x2) // see if right side needs to be chopped off 911 chop_length=x2-x-ix; 912 else chop_length=slam_length; 913 914 uint8_t *screen_run=screen_line+x+ix, 915 *blend_run=blend_line+x+ix-blendx, 916 *caddr1,*caddr2,r_dest,g_dest,b_dest; 917 918 slam_length-=chop_length; 919 ix+=chop_length; 920 921 922 while (chop_length--) 923 { 924 caddr1=paddr+(int)(*blend_run)*3; 925 caddr2=paddr+(int)(*datap)*3; 926 927 r_dest=((int)(*caddr1)-(int)(*caddr2))*blend_amount/16+(int)(*caddr2); 928 caddr1++; caddr2++; 929 930 g_dest=((int)(*caddr1)-(int)(*caddr2))*blend_amount/16+(int)(*caddr2); 931 caddr1++; caddr2++; 932 933 b_dest=((int)(*caddr1)-(int)(*caddr2))*blend_amount/16+(int)(*caddr2); 934 935 *screen_run=f->lookup_color(r_dest>>3,g_dest>>3,b_dest>>3); 936 937 938 screen_run++; 939 blend_run++; 940 datap++; 941 } 942 datap+=slam_length; 943 ix+=slam_length; 944 } 945 946 } 947 } 948 } 949 } 950 951 screen->unlock(); 952 } 953 954 void trans_image::put_predator(image *screen, int x, int y) 930 955 { 931 956 int16_t x1,y1,x2,y2; … … 933 958 934 959 screen->get_clip(x1,y1,x2,y2); 935 registeruint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;960 uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line; 936 961 if (!datap) return ; // if clip_y says nothing to draw, return 937 962 … … 946 971 if (x<w) 947 972 { 948 949 950 951 } 952 } 953 if (y==y2) 973 int run_size=*datap; 974 datap+=run_size+1; 975 x+=run_size; 976 } 977 } 978 if (y==y2) 954 979 return; 955 980 else 956 y++; 981 y++; 957 982 }*/ 958 959 screen_line=screen->scan_line(y)+x; 983 984 screen->lock(); 985 screen_line=screen->scan_line(y)+x; 960 986 int sw=screen->width(); 961 987 x1-=x; x2-=x; 962 988 for (;ysteps>0;ysteps--) 963 { 964 registerint ix,slam_length;989 { 990 int ix,slam_length; 965 991 for (ix=0;ix<w;) 966 992 { 967 993 ix+=(*datap); // skip over empty space 968 datap++; 969 if (ix<w) 970 { 971 slam_length=*datap; // find the length of this run 972 datap++; 973 974 975 976 ix+=slam_length; 977 978 979 { 980 981 { 982 chop_length=(x1-ix); 983 984 985 986 987 datap+=slam_length; 988 slam_length=0; 989 990 { 991 slam_length-=chop_length; // else advance everything to begining of slam 992 993 datap+=chop_length; 994 } 995 } 996 997 998 999 1000 1001 1002 1003 1004 ix+=slam_length; 1005 } 1006 1007 } 994 datap++; 995 if (ix<w) 996 { 997 slam_length=*datap; // find the length of this run 998 datap++; 999 if (ix+slam_length<x1 || ix>x2) // see if this run is totally clipped 1000 { 1001 datap+=slam_length; 1002 ix+=slam_length; 1003 } 1004 else 1005 { 1006 if (ix<x1) // the left side needs to be chopped ? 1007 { 1008 chop_length=(x1-ix); 1009 1010 if (chop_length>=slam_length) // see if we chopped it all off 1011 { // yes, we did 1012 ix+=slam_length; // advance everything to the end of run 1013 datap+=slam_length; 1014 slam_length=0; 1015 } else 1016 { 1017 slam_length-=chop_length; // else advance everything to begining of slam 1018 ix+=chop_length; 1019 datap+=chop_length; 1020 } 1021 } 1022 1023 if (slam_length) // see if there is anything left to slam 1024 { 1025 if (ix+slam_length>x2) // see if right side needs to be chopped off 1026 memcpy(screen_line+ix,screen_line+sw+sw+ix,x2-ix+1); 1027 else 1028 memcpy(screen_line+ix,screen_line+sw+sw+ix,slam_length); 1029 datap+=slam_length; 1030 ix+=slam_length; 1031 } 1032 } 1033 } 1008 1034 } 1009 1035 screen_line+=sw; 1010 } 1036 } 1037 screen->unlock(); 1011 1038 } 1012 1039 … … 1023 1050 if (x<w) 1024 1051 { 1025 1026 1027 1028 } 1052 int s=*d; d++; t+=s+1; 1053 d+=s; 1054 x+=s; 1055 } 1029 1056 } 1030 1057 } -
abuse/trunk/src/level.cpp
r106 r115 1657 1657 fp->write_uint16(i->width()); 1658 1658 fp->write_uint16(i->height()); 1659 int y=0; 1660 for (;y<i->height();y++) 1659 1660 i->lock(); 1661 for(int y = 0; y < i->height(); y++) 1661 1662 fp->write(i->scan_line(y),i->width()); 1663 i->unlock(); 1662 1664 1663 1665 delete i; -
abuse/trunk/src/light.cpp
r90 r115 776 776 light_patch *first=make_patch_list(cx2-cx1+1,cy2-cy1+1,screenx,screeny); 777 777 778 int scr_w=screen->width();779 780 778 int prefix_x=(screenx&7); 781 779 int prefix=screenx&7; … … 791 789 792 790 light_patch *f=first; 791 792 screen->lock(); 793 794 int scr_w=screen->width(); 793 795 uint8_t *screen_line=screen->scan_line(cy1)+cx1; 794 796 … … 880 882 881 883 screen_line-=prefix; 882 883 884 885 } 886 884 } 885 screen->unlock(); 887 886 888 887 while (first) -
abuse/trunk/src/menu.cpp
r113 r115 49 49 percent=256-percent; 50 50 51 screen->lock(); 51 52 for (y=y1;y<=y2;y++) 52 53 { … … 62 63 } 63 64 screen->add_dirty(x1,y1,x2,y2); 65 screen->unlock(); 64 66 } 65 67 … … 75 77 if (x2<x1 || y2<y1) return ; 76 78 79 screen->lock(); 77 80 for (y=y1;y<=y2;y++) 78 81 { … … 88 91 } 89 92 screen->add_dirty(x1,y1,x2,y2); 93 screen->unlock(); 90 94 } 91 95 -
abuse/trunk/src/particle.cpp
r56 r115 45 45 last_anim->next=pan; 46 46 last_anim=pan; 47 } 47 } 48 48 } 49 49 … … 76 76 args=lcdr(args); 77 77 pseqs[total_pseqs]=new part_sequence(args); 78 total_pseqs++; 78 total_pseqs++; 79 79 return total_pseqs; 80 80 } … … 84 84 part_sequence::part_sequence(void *args) 85 85 { 86 char *fn=lstring_value(lcar(args)); 86 char *fn=lstring_value(lcar(args)); 87 87 bFILE *fp=open_file(fn,"rb"); 88 88 if (fp->open_failure()) … … 106 106 if (sd.entries[i]->type==SPEC_PARTICLE) tframes++; 107 107 frames=(int *)jmalloc(sizeof(int)*tframes,"part_frame id list\n"); 108 108 109 109 int on=0; 110 110 for (i=0;i<sd.total;i++) 111 if (sd.entries[i]->type==SPEC_PARTICLE) 111 if (sd.entries[i]->type==SPEC_PARTICLE) 112 112 frames[on++]=cash.reg(fn,sd.entries[i]->name,SPEC_PARTICLE,1); 113 113 … … 128 128 if (y>y2) y2=x; 129 129 data[i].x=x; 130 data[i].y=y; 131 data[i].color=fp->read_uint8(); 130 data[i].y=y; 131 data[i].color=fp->read_uint8(); 132 132 } 133 133 } … … 148 148 p=p->next; 149 149 delete d; 150 } else 150 } else 151 151 { 152 152 last=p; … … 159 159 void draw_panims(view *v) 160 160 { 161 for (part_animation *p=first_anim;p;p=p->next) 161 for (part_animation *p=first_anim;p;p=p->next) 162 162 { 163 163 cash.part(p->seq->frames[p->frame])->draw(screen,p->x-v->xoff()+v->cx1,p->y-v->yoff()+v->cy1,p->dir); … … 178 178 while (i && pon->y<cy1) { pon++; i--; } 179 179 if (!i) return ; 180 screen->lock(); 180 181 if (dir>0) 181 182 { … … 187 188 i--; 188 189 pon++; 189 } 190 } 190 191 } else 191 192 { … … 197 198 i--; 198 199 pon++; 199 } 200 } 201 202 } 203 204 205 200 } 201 } 202 screen->unlock(); 203 } 206 204 207 205 void scatter_line(int x1, int y1, int x2, int y2, int c, int s) 208 206 { 209 int16_t cx1, cy1, cx2, cy2; 210 screen->get_clip( cx1, cy1, cx2, cy2 ); 211 212 int t = abs( x2 - x1 ) > abs( y2 - y1 ) ? abs( x2 - x1 ) + 1 : abs( y2 - y1 ) + 1; 213 long xo = x1 << 16, yo = y1 << 16, dx = ( ( x2 - x1 ) << 16 ) / t, dy = ( ( y2 - y1 ) << 16 ) / t, x, y; 214 215 int xm = ( 1 << s ); 216 int ym = ( 1 << s ); 217 s = ( 15 - s ); 218 219 while( t-- ) 220 { 221 x = ( xo >> 16 ) + ( jrand() >> s ) - xm; 222 y = ( yo >> 16 ) + ( jrand() >> s ) - ym; 223 if( !( x < cx1 || y < cy1 || x > cx2 || y > cy2 ) ) 224 { 225 *(screen->scan_line( y ) + x ) = c; 226 } 227 xo += dx; 228 yo += dy; 229 } 207 int16_t cx1, cy1, cx2, cy2; 208 screen->get_clip( cx1, cy1, cx2, cy2 ); 209 210 int t = abs( x2 - x1 ) > abs( y2 - y1 ) ? abs( x2 - x1 ) + 1 : abs( y2 - y1 ) + 1; 211 long xo = x1 << 16, yo = y1 << 16, dx = ( ( x2 - x1 ) << 16 ) / t, dy = ( ( y2 - y1 ) << 16 ) / t, x, y; 212 213 int xm = ( 1 << s ); 214 int ym = ( 1 << s ); 215 s = ( 15 - s ); 216 217 screen->lock(); 218 while( t-- ) 219 { 220 x = ( xo >> 16 ) + ( jrand() >> s ) - xm; 221 y = ( yo >> 16 ) + ( jrand() >> s ) - ym; 222 if( !( x < cx1 || y < cy1 || x > cx2 || y > cy2 ) ) 223 { 224 *(screen->scan_line( y ) + x ) = c; 225 } 226 xo += dx; 227 yo += dy; 228 } 229 screen->unlock(); 230 230 } 231 231 … … 234 234 void ascatter_line(int x1, int y1, int x2, int y2, int c1, int c2, int s) 235 235 { 236 int16_t cx1, cy1, cx2, cy2; 237 screen->get_clip( cx1, cy1, cx2, cy2 ); 238 239 int t = abs( x2 - x1 ) > abs( y2 - y1 ) ? abs( x2 - x1 ) + 1 : abs( y2 - y1 ) + 1; 240 long xo = x1 << 16, yo = y1 << 16, dx = ( ( x2 - x1 ) << 16 ) / t, dy = ( ( y2 - y1 ) <<16 ) / t, x, y; 241 242 int xm = ( 1 << s ); 243 int ym = ( 1 << s ); 244 s = ( 15 - s ); 245 246 int w = screen->width(); 247 uint8_t *addr; 248 249 while( t-- ) 250 { 251 x = ( xo >> 16 ) + ( jrand() >> s ) - xm; 252 y = ( yo >> 16 ) + ( jrand() >> s ) - ym; 253 if( !( x <= cx1 || y <= cy1 || x >= cx2 || y >= cy2 ) ) 254 { 255 addr = screen->scan_line( y ) + x; 256 *addr = c1; 257 *(addr + w) = c2; 258 *(addr - w) = c2; 259 *(addr - 1) = c2; 260 *(addr + 1) = c2; 261 } 262 xo += dx; 263 yo += dy; 264 } 265 } 236 int16_t cx1, cy1, cx2, cy2; 237 screen->get_clip( cx1, cy1, cx2, cy2 ); 238 239 int t = abs( x2 - x1 ) > abs( y2 - y1 ) ? abs( x2 - x1 ) + 1 : abs( y2 - y1 ) + 1; 240 long xo = x1 << 16, yo = y1 << 16, dx = ( ( x2 - x1 ) << 16 ) / t, dy = ( ( y2 - y1 ) <<16 ) / t, x, y; 241 242 int xm = ( 1 << s ); 243 int ym = ( 1 << s ); 244 s = ( 15 - s ); 245 246 screen->lock(); 247 248 int w = screen->width(); 249 uint8_t *addr; 250 251 while( t-- ) 252 { 253 x = ( xo >> 16 ) + ( jrand() >> s ) - xm; 254 y = ( yo >> 16 ) + ( jrand() >> s ) - ym; 255 if( !( x <= cx1 || y <= cy1 || x >= cx2 || y >= cy2 ) ) 256 { 257 addr = screen->scan_line( y ) + x; 258 *addr = c1; 259 *(addr + w) = c2; 260 *(addr - w) = c2; 261 *(addr - 1) = c2; 262 *(addr + 1) = c2; 263 } 264 xo += dx; 265 yo += dy; 266 } 267 268 screen->unlock(); 269 } 270
Note: See TracChangeset
for help on using the changeset viewer.