Changeset 124 for abuse/trunk/src/imlib/morph.cpp
- Timestamp:
- Mar 18, 2008, 9:36:56 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/morph.cpp
r115 r124 16 16 long trans(long x1, long x2, long frame) 17 17 { 18 return (((x2-x1)<<5)*frame+(x1<<8))>>8; 18 return (((x2-x1)<<5)*frame+(x1<<8))>>8; 19 19 } 20 20 21 21 22 22 void jmorph::show_step_frame(image *screen, int x, int y, int frame_on, 23 23 color_filter *fli, palette *pal) 24 24 { 25 25 short x1,y1,x2,y2; 26 26 unsigned char r1,g1,b1,r2,g2,b2; 27 27 screen->get_clip(x1,y1,x2,y2); 28 28 29 29 int i; 30 30 long xx,yy; 31 31 32 32 if (small) 33 33 { … … 38 38 xx=x+trans(m8->x1,m8->x2,frame_on); 39 39 yy=y+trans(m8->y1,m8->y2,frame_on); 40 40 41 41 if (xx>=x1 && xx<=x2 && yy>=y1 && yy<=y2) 42 { 43 44 45 46 42 { 43 pal->get(m8->start_color,r1,g1,b1); 44 pal->get(m8->end_color,r2,g2,b2); 45 46 long r=trans(r1,r2,frame_on)>>3, 47 47 g=trans(g1,g2,frame_on)>>3, 48 49 48 b=trans(b1,b2,frame_on)>>3; 49 50 50 *(screen->scan_line(yy)+xx)=fli->lookup_color(r,g,b); 51 } 51 } 52 52 } 53 53 screen->unlock(); 54 } 55 } 56 57 58 void patched_morph::show_frame(image *screen, int x, int y, 59 54 } 55 } 56 57 58 void patched_morph::show_frame(image *screen, int x, int y, 59 int frame_on, color_filter *fli, palette *pal) 60 60 { 61 61 jmorph::show_step_frame(screen,x,y,frame_on,fli,pal); … … 63 63 unsigned char *p=pats[frame_on].patch_data; 64 64 short cx1,cy1,cx2,cy2; 65 screen->get_clip(cx1,cy1,cx2,cy2); 65 screen->get_clip(cx1,cy1,cx2,cy2); 66 66 screen->lock(); 67 67 while (tot--) … … 76 76 p++; 77 77 else 78 79 } 80 } 78 *(screen->scan_line(yy)+xx)=*(p++); 79 } 80 } 81 81 screen->unlock(); 82 82 } … … 85 85 { 86 86 jmorph::show_8(screen,x,y,frame_on,fli,pal); 87 int tot=pats[frame_on].patches,xx,yy; 87 int tot=pats[frame_on].patches,xx,yy; 88 88 unsigned char *p=pats[frame_on].patch_data; 89 89 short cx1,cy1,cx2,cy2; 90 screen->get_clip(cx1,cy1,cx2,cy2); 90 screen->get_clip(cx1,cy1,cx2,cy2); 91 91 screen->lock(); 92 92 while (tot--) … … 101 101 p++; 102 102 else 103 104 } 105 } 103 *(screen->scan_line(yy)+xx)=*(p++); 104 } 105 } 106 106 screen->unlock(); 107 107 } … … 111 111 112 112 patched_morph::patched_morph(image *i1, image *hint1, image *i2, image *hint2, int aneal_steps, 113 113 color_filter *fli, palette *pal, int frames) : jmorph(i1,hint1,i2,hint2,aneal_steps) 114 114 { 115 115 int i,j,w,h,x,y,tot,r,g,b,mark_color,dist; 116 116 unsigned char *cur_patch,*sl,ored,og,ob; 117 117 118 118 frames=9; 119 120 patches=frames; 119 120 patches=frames; 121 121 pats=(morph_patch *)jmalloc(sizeof(morph_patch)*patches,"morph::patch array"); 122 122 w=max(bound_x2(0),bound_x2(1)); 123 h=max(bound_y2(0),bound_y2(1)); 123 h=max(bound_y2(0),bound_y2(1)); 124 124 image *im=new image(w,h); 125 125 … … 128 128 { 129 129 pats[i].patch_data=NULL; 130 pats[i].patches=0; 130 pats[i].patches=0; 131 131 if (i!=0 && i!=patches-1) 132 { 132 { 133 133 im->clear(); 134 134 jmorph::show_step_frame(im,0,0,i,fli,pal); 135 135 for (j=0;j<4;j++) 136 { 137 136 { 137 for (y=0;y<h;y++) 138 138 for (sl=im->scan_line(y),x=0;x<w;x++,sl++) 139 { 140 141 142 tot=r=g=b=0;143 if (x!=0 && *(sl-1)) 144 { tot++; 145 r+=pal->red(*(sl-1)); 146 g+=pal->green(*(sl-1)); 147 b+=pal->blue(*(sl-1));148 }149 if (x!=w-1 && *(sl+1)) 150 { tot++; 151 r+=pal->red(*(sl+1)); 152 g+=pal->green(*(sl+1)); 153 b+=pal->blue(*(sl+1)); 154 }155 if (y!=0 && im->pixel(x,y-1)) 156 { tot++; 157 r+=pal->red(im->pixel(x,y-1)); 158 g+=pal->green(im->pixel(x,y-1)); 159 160 161 if (y!=h-1 && im->pixel(x,y+1)) 162 { tot++; 163 r+=pal->red(im->pixel(x,y+1)); 164 g+=pal->green(im->pixel(x,y+1)); 165 166 167 168 if (*sl && tot==0) // kill any separate pixels169 170 171 172 173 174 175 176 177 178 179 180 // 181 mark_color=fli->lookup_color(r>>3,g>>3,b>>3);182 183 184 else if (*sl==0 && tot>=3)185 mark_color=fli->lookup_color((r/tot)>>3,(g/tot)>>3,(b/tot)>>3);186 187 {188 189 190 cur_patch=pats[i].patch_data+ (pats[i].patches-1)*3;191 192 193 *sl=mark_color;194 *(cur_patch++)=*sl;195 }196 197 } 198 } 199 } 139 { 140 mark_color=-1; 141 142 tot=r=g=b=0; 143 if (x!=0 && *(sl-1)) 144 { tot++; 145 r+=pal->red(*(sl-1)); 146 g+=pal->green(*(sl-1)); 147 b+=pal->blue(*(sl-1)); 148 } 149 if (x!=w-1 && *(sl+1)) 150 { tot++; 151 r+=pal->red(*(sl+1)); 152 g+=pal->green(*(sl+1)); 153 b+=pal->blue(*(sl+1)); 154 } 155 if (y!=0 && im->pixel(x,y-1)) 156 { tot++; 157 r+=pal->red(im->pixel(x,y-1)); 158 g+=pal->green(im->pixel(x,y-1)); 159 b+=pal->blue(im->pixel(x,y-1)); 160 } 161 if (y!=h-1 && im->pixel(x,y+1)) 162 { tot++; 163 r+=pal->red(im->pixel(x,y+1)); 164 g+=pal->green(im->pixel(x,y+1)); 165 b+=pal->blue(im->pixel(x,y+1)); 166 } 167 168 if (*sl && tot==0) // kill any separate pixels 169 mark_color=0; 170 else if (*sl) 171 { 172 pal->get(*sl,ored,og,ob); // see if we need to blur this on in 173 r/=tot; 174 g/=tot; 175 b/=tot; 176 177 dist=((int)ored-r)*((int)ored-r)+((int)og-g)*((int)og-g)+((int)ob-b)*((int)ob-b); 178 if (i>0 && i<patches-1 && dist>3000) 179 { 180 // printf("adding blur at %d %d to frame %d, dist=%d\n",x,y,i,dist); 181 mark_color=fli->lookup_color(r>>3,g>>3,b>>3); 182 } 183 } 184 else if (*sl==0 && tot>=3) 185 mark_color=fli->lookup_color((r/tot)>>3,(g/tot)>>3,(b/tot)>>3); 186 if (mark_color>=0) 187 { 188 pats[i].patches++; 189 pats[i].patch_data=(unsigned char *)realloc(pats[i].patch_data,3*pats[i].patches); 190 cur_patch=pats[i].patch_data+ (pats[i].patches-1)*3; 191 *(cur_patch++)=x; 192 *(cur_patch++)=y; 193 *sl=mark_color; 194 *(cur_patch++)=*sl; 195 } 196 } 197 } 198 } 199 } 200 200 delete im; 201 201 202 202 } 203 203 … … 247 247 } 248 248 } 249 } 249 } 250 250 251 251 … … 253 253 { 254 254 int w=max(bound_x2(0),bound_x2(1)),h=max(bound_y2(0),bound_y2(1)), 255 i,pixelx,pixely,k,l,frame_on; 255 i,pixelx,pixely,k,l,frame_on; 256 256 morph_point8 **middle_map,*other; 257 257 unsigned char *end_map; 258 258 CONDITION(small,"add filler not defined for 16bit morphs\n"); 259 259 260 260 if (frames<3) return ; 261 261 262 262 263 263 middle_map=(morph_point8 **)jmalloc(w*h*sizeof(morph_point8 *), 264 264 "morph::middle_map"); // create an image of pointers 265 265 end_map=(unsigned char *)jmalloc(w*h, 266 266 "morph::end_map"); // maps all the ending pixels 267 267 268 268 for (frame_on=2;frame_on<frames-1;frame_on++) 269 { 269 { 270 270 memset(middle_map,0,w*h*sizeof(morph_point8 *)); // initialize them middle pointers NULL 271 271 memset(end_map,0,w*h); // clear all end pixels 272 272 273 273 morph_point8 *p_on=(morph_point8 *)p; // p is the array of morph points 274 for (i=0;i<total;i++,p_on++) 275 { 274 for (i=0;i<total;i++,p_on++) 275 { 276 276 pixelx=(long)((int)p_on->x2-(int)p_on->x1)*(long) frame_on /(long) frames +p_on->x1; 277 277 pixely=(long)((int)p_on->y2-(int)p_on->y1)*(long) frame_on /(long) frames +p_on->y1; … … 281 281 } 282 282 283 283 284 284 int skipped=0; 285 286 for (pixely=0;pixely<h;pixely++) 287 { 288 for (pixelx=0;pixelx<w;pixelx++) 289 { 290 if (middle_map[pixelx+pixely*w]==NULL) // we are checking for 'duds' (misplaced black pixels) 291 { 292 int tot; 293 if (pixelx>0) if (middle_map[pixelx-1+pixely*w]) tot=1; else tot=0; 294 if (pixelx<w-1) if (middle_map[pixelx+1+pixely*w]) tot++; 295 if (pixely>0) if (middle_map[pixelx+(pixely-1)*w]) tot++; 296 if (pixely<h-1) if (middle_map[pixelx+(pixely+1)*w]) tot++; 297 298 if (tot>=3) // it is surronded by 3 non black squares, this is a dud 299 { 300 int distance,shortest_distance,shortest_end_x,shortest_end_y; 301 morph_point8 *shortest=NULL; 285 302 286 for (pixely=0;pixely<h;pixely++) 287 { 288 for (pixelx=0;pixelx<w;pixelx++) 289 { 290 if (middle_map[pixelx+pixely*w]==NULL) // we are checking for 'duds' (misplaced black pixels) 291 { 292 int tot; 293 if (pixelx>0) if (middle_map[pixelx-1+pixely*w]) tot=1; else tot=0; 294 if (pixelx<w-1) if (middle_map[pixelx+1+pixely*w]) tot++; 295 if (pixely>0) if (middle_map[pixelx+(pixely-1)*w]) tot++; 296 if (pixely<h-1) if (middle_map[pixelx+(pixely+1)*w]) tot++; 297 298 if (tot>=3) // it is surronded by 3 non black squares, this is a dud 299 { 300 int distance,shortest_distance,shortest_end_x,shortest_end_y; 301 morph_point8 *shortest=NULL; 302 303 for (k=0;k<w;k++) 304 for (l=0;l<h;l++) 305 { 303 for (k=0;k<w;k++) 304 for (l=0;l<h;l++) 305 { 306 306 other=middle_map[k+(l)*w]; 307 308 309 310 end_y=frames*(pixely-other->y1)/frame_on+other->y1;311 312 { 307 if (other) 308 { 309 int end_x=frames*(pixelx-other->x1)/frame_on+other->x1, 310 end_y=frames*(pixely-other->y1)/frame_on+other->y1; 311 if (end_x>=0 && end_y>=0 && end_x<w && end_y<h && end_map[end_x+end_y*w]) 312 { 313 313 distance=(other->x1-end_x)*(other->x1-end_x)+ 314 315 316 317 318 319 320 shortest_end_y=end_y;321 322 323 324 }325 326 327 328 p=(void *)realloc(p,sizeof(morph_point8)*total);329 330 331 332 mod->start_color=shortest->start_color;333 334 335 mod->y2=shortest_end_y;336 mod->end_color=end_map[shortest_end_x+shortest_end_y*w];337 } 338 339 {340 341 342 343 344 345 } 346 347 } 348 } 349 } 350 314 (other->y1-end_y)*(other->y1-end_y); 315 if (!shortest || shortest_distance>distance) 316 { 317 shortest_distance=distance; 318 shortest=other; 319 shortest_end_x=end_x; 320 shortest_end_y=end_y; 321 } 322 } 323 } 324 } 325 if (shortest) 326 { 327 total++; 328 p=(void *)realloc(p,sizeof(morph_point8)*total); 329 morph_point8 *mod=((morph_point8 *)p)+total-1; 330 mod->x1=shortest->x1; 331 mod->y1=shortest->y1; 332 mod->start_color=shortest->start_color; 333 334 mod->x2=shortest_end_x; 335 mod->y2=shortest_end_y; 336 mod->end_color=end_map[shortest_end_x+shortest_end_y*w]; 337 } 338 else 339 { 340 skipped++; 341 printf("skiped so far : %d (frame %d)\n",skipped,frame_on); 342 } 343 344 345 } 346 } 347 } 348 } 349 } 350 351 351 jfree(middle_map); 352 352 jfree(end_map); 353 353 354 354 } 355 355 … … 360 360 int i; 361 361 fp->seek(e->offset,0); 362 fp->read(&total,4); 362 fp->read(&total,4); 363 363 total=long_to_local(total); 364 364 if (e->type==SPEC_MORPH_POINTS_8 || e->type==SPEC_PATCHED_MORPH) … … 373 373 374 374 for (i=0;i<total;i++) 375 { 375 { 376 376 ((morph_point16 *)p+i)->x1=fp->read_uint16(); 377 377 ((morph_point16 *)p+i)->y1=fp->read_uint16(); … … 385 385 } 386 386 w[0]=fp->read_uint16(); 387 h[0]=fp->read_uint16(); 387 h[0]=fp->read_uint16(); 388 388 w[1]=fp->read_uint16(); 389 389 h[1]=fp->read_uint16(); 390 390 } 391 391 392 void jmorph::show_frame(image *screen, int x, int y, 392 void jmorph::show_frame(image *screen, int x, int y, 393 393 int frames, int frame_on, color_filter *fli, palette *pal) 394 394 { … … 435 435 } 436 436 } 437 } 437 } 438 438 439 439 void jmorph::show_24frame(unsigned char *screen, int width, int height, … … 442 442 int pixelx,pixely,i; 443 443 unsigned char *scolor,*ecolor,*addr=(unsigned char *)pal->addr(),*pix; 444 444 445 445 if (small) 446 446 { … … 452 452 453 453 if (pixelx>=0 && pixely>=0 && pixelx<width && pixely<height) 454 { 454 { 455 455 scolor=addr+((int)p_on->start_color)*3; 456 456 ecolor=addr+((int)p_on->end_color)*3; 457 pix=screen+pixelx*3+pixely*3*width; 458 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 459 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 457 pix=screen+pixelx*3+pixely*3*width; 458 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 459 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 460 460 *pix=((int)(*ecolor)-(int)(*scolor))*frame_on/frames+*scolor; 461 461 } … … 471 471 472 472 if (pixelx>=0 && pixely>=0 && pixelx<width && pixely<height) 473 { 473 { 474 474 scolor=addr+((int)p_on->start_color)*3; 475 475 ecolor=addr+((int)p_on->end_color)*3; 476 pix=screen+pixelx*3+pixely*3*width; 477 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 478 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 476 pix=screen+pixelx*3+pixely*3*width; 477 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 478 *pix=(((int)*(ecolor++))-((int)*scolor))*frame_on/frames+*scolor; scolor++; pix++; 479 479 *pix=((int)(*ecolor)-(int)(*scolor))*frame_on/frames+*scolor; 480 480 } … … 484 484 485 485 486 jmorph::jmorph(image *i1, image *hint1, image *i2, image *hint2, 486 jmorph::jmorph(image *i1, image *hint1, image *i2, image *hint2, 487 487 int aneal_steps) 488 488 { 489 489 w[0]=i1->width(); 490 h[0]=i1->height(); 490 h[0]=i1->height(); 491 491 w[1]=i2->width(); 492 h[1]=i2->height(); 492 h[1]=i2->height(); 493 493 494 494 struct { int start,end; } crange[256]; … … 499 499 500 500 501 CONDITION(i1->width()==hint1->width() && i1->height()==hint1->height() && 501 CONDITION(i1->width()==hint1->width() && i1->height()==hint1->height() && 502 502 i2->width()==hint2->width() && i2->height()==hint2->height(), 503 503 "Image sizes do not correspond with hint sizes"); 504 if (i1->width()>255 || i2->width()>255 || i1->height()>255 || i2->height()>255) 504 if (i1->width()>255 || i2->width()>255 || i1->height()>255 || i2->height()>255) 505 505 small=0; 506 506 else small=1; … … 523 523 524 524 // check the user and see if the mask match up 525 for (x=0;x<256;x++) 525 for (x=0;x<256;x++) 526 526 { 527 527 if ((hint_hist1[x]!=0 && hint_hist2[x]==0) || … … 530 530 exit(1); 531 531 } else if (hint_hist1[x]) 532 { 532 { 533 533 if (!first) first=x; 534 534 total_hints++; … … 560 560 { total1--; 561 561 do { 562 findx1++; 563 if (findx1>=hint1->width()) { findx1=0; findy1++; } 562 findx1++; 563 if (findx1>=hint1->width()) { findx1=0; findy1++; } 564 564 } while (hint1->pixel(findx1,findy1)!=color); 565 565 } … … 568 568 randp=rand()%j+crange[color].start; 569 569 if (small) 570 { findx1=((morph_point8 *)plist)[randp].x1; 570 { findx1=((morph_point8 *)plist)[randp].x1; 571 571 findy1=((morph_point8 *)plist)[randp].y1; 572 572 } else 573 { findx1=((morph_point16 *)plist)[randp].x1; 573 { findx1=((morph_point16 *)plist)[randp].x1; 574 574 findy1=((morph_point16 *)plist)[randp].y1; 575 575 } 576 576 } 577 577 if (total2) // are there any more pixels left in this image? 578 { 578 { 579 579 total2--; 580 580 do { 581 findx2++; 582 if (findx2>=hint2->width()) { findx2=0; findy2++; } 581 findx2++; 582 if (findx2>=hint2->width()) { findx2=0; findy2++; } 583 583 } while (hint2->pixel(findx2,findy2)!=color); 584 584 } … … 587 587 randp=rand()%j+crange[color].start; 588 588 if (small) 589 { findx2=((morph_point8 *)plist)[randp].x2; 589 { findx2=((morph_point8 *)plist)[randp].x2; 590 590 findy2=((morph_point8 *)plist)[randp].y2; 591 591 } else 592 { findx2=((morph_point16 *)plist)[randp].x2; 592 { findx2=((morph_point16 *)plist)[randp].x2; 593 593 findy2=((morph_point16 *)plist)[randp].y2; 594 594 } … … 599 599 if (small) 600 600 { 601 ((morph_point8 *)plist)[cur_pix].x1=findx1; 602 ((morph_point8 *)plist)[cur_pix].x2=findx2; 603 ((morph_point8 *)plist)[cur_pix].y1=findy1; 604 ((morph_point8 *)plist)[cur_pix].y2=findy2; 601 ((morph_point8 *)plist)[cur_pix].x1=findx1; 602 ((morph_point8 *)plist)[cur_pix].x2=findx2; 603 ((morph_point8 *)plist)[cur_pix].y1=findy1; 604 ((morph_point8 *)plist)[cur_pix].y2=findy2; 605 605 ((morph_point8 *)plist)[cur_pix].start_color=i1->pixel(findx1,findy1); 606 606 ((morph_point8 *)plist)[cur_pix].end_color=i2->pixel(findx2,findy2); … … 608 608 else 609 609 { 610 ((morph_point16 *)plist)[cur_pix].x1=findx1; 611 ((morph_point16 *)plist)[cur_pix].x2=findx2; 612 ((morph_point16 *)plist)[cur_pix].y1=findy1; 613 ((morph_point16 *)plist)[cur_pix].y2=findy2; 610 ((morph_point16 *)plist)[cur_pix].x1=findx1; 611 ((morph_point16 *)plist)[cur_pix].x2=findx2; 612 ((morph_point16 *)plist)[cur_pix].y1=findy1; 613 ((morph_point16 *)plist)[cur_pix].y2=findy2; 614 614 ((morph_point16 *)plist)[cur_pix].start_color=i1->pixel(findx1,findy1); 615 615 ((morph_point16 *)plist)[cur_pix].end_color=i2->pixel(findx2,findy2); … … 630 630 start=crange[hint_color].start; 631 631 range=crange[hint_color].end-start+1; 632 for(k=crange[hint_color].start;k<=crange[hint_color].end;k++) 632 for(k=crange[hint_color].start;k<=crange[hint_color].end;k++) 633 633 { 634 634 swap_point=rand()%range+start; … … 644 644 (pk->x2-ps->x1)*(pk->x2-ps->x1)+(pk->y2-ps->y1)*(pk->y2-ps->y1); 645 645 if (new_distance<distance) 646 { 646 { 647 647 sx2=pk->x2; sy2=pk->y2; 648 648 sec=pk->end_color; … … 663 663 (pk->x2-ps->x1)*(pk->x2-ps->x1)+(pk->y2-ps->y1)*(pk->y2-ps->y1); 664 664 if (new_distance<distance) 665 { 665 { 666 666 sx2=pk->x2; sy2=pk->y2; 667 667 sec=pk->end_color; … … 677 677 } 678 678 p=plist; 679 } 679 } 680 680 681 681 int morph_width; … … 683 683 int morph8_compare(const void *p1, const void *p2) 684 684 { 685 int pos1=((morph_point8 *)p1)->x1+((morph_point8 *)p1)->y1*morph_width; 686 int pos2=((morph_point8 *)p2)->x1+((morph_point8 *)p2)->y1*morph_width; 685 int pos1=((morph_point8 *)p1)->x1+((morph_point8 *)p1)->y1*morph_width; 686 int pos2=((morph_point8 *)p2)->x1+((morph_point8 *)p2)->y1*morph_width; 687 687 if (pos1<pos2) return -1; 688 688 else if (pos1==pos2) return 0; 689 689 else return 1; 690 690 691 691 } 692 692 … … 696 696 int i; 697 697 698 699 fp->write_uint32(total); 698 699 fp->write_uint32(total); 700 700 if (small) 701 701 { … … 703 703 // if the points are put in order then they can be compressed easier 704 704 morph_width=max(bound_x2(0),bound_x2(1)); // global used by qsort compare routine 705 qsort(p,total,sizeof(morph_point8),morph8_compare); 706 707 fp->write(p,sizeof(morph_point8)*total); 708 } 705 qsort(p,total,sizeof(morph_point8),morph8_compare); 706 707 fp->write(p,sizeof(morph_point8)*total); 708 } 709 709 else 710 710 { … … 732 732 int i; 733 733 pm=mor; 734 735 total=mor->total_points(); 736 points=(step_struct *)jmalloc(sizeof(step_struct)*total,"step_morph::points"); 737 734 735 total=mor->total_points(); 736 points=(step_struct *)jmalloc(sizeof(step_struct)*total,"step_morph::points"); 737 738 738 dir=frame_direction; 739 739 face_dir=face_direction; 740 740 741 741 if (dir>0) 742 742 frame_on=0; 743 743 else 744 744 frame_on=mor->patches-1; 745 745 746 746 if (mor->small_morph()) 747 { 747 { 748 748 int x1,y1,x2,y2; 749 749 750 751 if (frame_direction>0) 752 { 753 morph_point8 *m8=mor->small_points(); 750 754 751 if (frame_direction>0) 752 { 753 morph_point8 *m8=mor->small_points(); 754 755 for (i=0;i<total;i++,m8++) 756 { 757 x1=(int)m8->x1; 758 x2=(int)m8->x2; 759 760 y1=(int)m8->y1; 761 y2=(int)m8->y2; 762 763 points[i].x=x1<<8; 764 points[i].y=y1<<8; 765 points[i].dx=(x2-x1)<<5; 766 points[i].dy=(y2-y1)<<5; 767 768 unsigned char r1,g1,b1,r2,g2,b2; 769 pal->get(m8->start_color,r1,g1,b1); 770 pal->get(m8->end_color,r2,g2,b2); 771 points[i].r=r1<<8; 772 points[i].g=g1<<8; 773 points[i].b=b1<<8; 774 775 points[i].dr=(long)((int)r2-(int)r1)<<5; 776 points[i].dg=(long)((int)g2-(int)g1)<<5; 777 points[i].db=(long)((int)b2-(int)b1)<<5; 778 } 779 } 755 for (i=0;i<total;i++,m8++) 756 { 757 x1=(int)m8->x1; 758 x2=(int)m8->x2; 759 760 y1=(int)m8->y1; 761 y2=(int)m8->y2; 762 763 points[i].x=x1<<8; 764 points[i].y=y1<<8; 765 points[i].dx=(x2-x1)<<5; 766 points[i].dy=(y2-y1)<<5; 767 768 unsigned char r1,g1,b1,r2,g2,b2; 769 pal->get(m8->start_color,r1,g1,b1); 770 pal->get(m8->end_color,r2,g2,b2); 771 points[i].r=r1<<8; 772 points[i].g=g1<<8; 773 points[i].b=b1<<8; 774 775 points[i].dr=(long)((int)r2-(int)r1)<<5; 776 points[i].dg=(long)((int)g2-(int)g1)<<5; 777 points[i].db=(long)((int)b2-(int)b1)<<5; 778 } 779 } 780 780 else 781 { 782 morph_point8 *m8=mor->small_points(); 783 784 { 785 786 787 788 789 790 791 792 points[i].y=y2<<8; 793 794 points[i].dy=(y1-y2)<<5; 795 796 797 798 799 800 801 802 803 804 805 points[i].db=(long)((int)b2-(int)b1)<<5; 806 807 } 808 } 781 { 782 morph_point8 *m8=mor->small_points(); 783 for (i=0;i<total;i++,m8++) 784 { 785 x1=(int)m8->x1; 786 x2=(int)m8->x2; 787 788 y1=(int)m8->y1; 789 y2=(int)m8->y2; 790 791 points[i].x=x2<<8; 792 points[i].y=y2<<8; 793 points[i].dx=(x1-x2)<<5; 794 points[i].dy=(y1-y2)<<5; 795 796 unsigned char r1,g1,b1,r2,g2,b2; 797 pal->get(m8->start_color,r2,g2,b2); 798 pal->get(m8->end_color,r1,g1,b1); 799 points[i].r=r1<<8; 800 points[i].g=g1<<8; 801 points[i].b=b1<<8; 802 803 points[i].dr=(long)((int)r2-(int)r1)<<5; 804 points[i].dg=(long)((int)g2-(int)g1)<<5; 805 points[i].db=(long)((int)b2-(int)b1)<<5; 806 } 807 } 808 } 809 809 810 810 … … 819 819 step_struct *ss; 820 820 821 morph_patch *pat=pm->pats+frame_on; 821 morph_patch *pat=pm->pats+frame_on; 822 822 int j,tp=pat->patches; 823 unsigned char *sl=pat->patch_data; 823 unsigned char *sl=pat->patch_data; 824 824 825 825 if (face_dir>0) 826 { 826 { 827 827 for (i=0,ss=points;i<total;i++,ss++) 828 828 { … … 836 836 ss->r+=ss->dr; 837 837 ss->g+=ss->dg; 838 ss->b+=ss->db; 839 } 838 ss->b+=ss->db; 839 } 840 840 841 841 for (j=0;j<tp;j++,sl++) … … 845 845 if (px>=x1 && px<=x2 && py>=y1 && py<=y2) 846 846 *(screen->scan_line(py)+px)=*sl; 847 } 847 } 848 848 } else 849 849 { … … 859 859 ss->r+=ss->dr; 860 860 ss->g+=ss->dg; 861 ss->b+=ss->db; 862 } 861 ss->b+=ss->db; 862 } 863 863 864 864 for (j=0;j<tp;j++,sl++) … … 868 868 if (px>=x1 && px<=x2 && py>=y1 && py<=y2) 869 869 *(screen->scan_line(py)+px)=*sl; 870 } 871 } 872 870 } 871 } 872 873 873 frame_on+=dir; 874 874 875 875 } 876 876 … … 878 878 { 879 879 step_struct *s=points; 880 int i; 880 int i; 881 881 for (i=0;i<total;i++,s++) 882 882 { … … 885 885 s->dr=-s->dr; 886 886 s->dg=-s->dg; 887 s->db=-s->db; 887 s->db=-s->db; 888 888 } 889 889 dir=-dir; 890 890 891 891 } 892 892 … … 895 895 { 896 896 int i; 897 897 898 898 patches=fp->read_uint16(); 899 899 pats=(morph_patch *)jmalloc(sizeof(morph_patch)*patches,"patched_morph::points"); 900 900 901 901 for (i=0;i<patches;i++) 902 902 { 903 903 pats[i].patches=fp->read_uint16(); 904 904 if (pats[i].patches) 905 { 905 { 906 906 pats[i].patch_data=(unsigned char *)jmalloc(3*pats[i].patches,"patched_morph::patch_data"); 907 fp->read(pats[i].patch_data,3*pats[i].patches); 907 fp->read(pats[i].patch_data,3*pats[i].patches); 908 908 } 909 909 else 910 910 pats[i].patch_data=NULL; 911 } 912 } 913 914 911 } 912 } 913 914
Note: See TracChangeset
for help on using the changeset viewer.