Changeset 17 for abuse/trunk/src/imlib/image.cpp
- Timestamp:
- Nov 10, 2005, 9:41:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/image.cpp
r2 r17 12 12 #include <stdlib.h> 13 13 14 extern u nsigned charcurrent_background;14 extern uint8_t current_background; 15 15 char *imerr_messages[]={"No error", 16 16 "Error occured while reading", … … 23 23 24 24 25 short imerror=0;26 short swpfile_num=0;27 28 short current_error()25 int16_t imerror=0; 26 int16_t swpfile_num=0; 27 28 int16_t current_error() 29 29 { return imerror; } 30 30 … … 48 48 } 49 49 50 void set_error( short x)50 void set_error(int16_t x) 51 51 { imerror=x; } 52 52 53 short last_error()54 { 55 short ec;53 int16_t last_error() 54 { 55 int16_t ec; 56 56 ec=imerror; 57 57 imerror=0; … … 62 62 63 63 64 image_descriptor::image_descriptor( short length, short height,64 image_descriptor::image_descriptor(int16_t length, int16_t height, 65 65 int keep_dirties, int static_memory) 66 66 … … 72 72 } 73 73 74 void image::change_size( short new_width, short new_height, unsigned char*page)74 void image::change_size(int16_t new_width, int16_t new_height, uint8_t *page) 75 75 { 76 76 delete_page(); … … 97 97 } 98 98 99 u nsigned char image::pixel(short x, short y)99 uint8_t image::pixel(int16_t x, int16_t y) 100 100 { 101 101 CONDITION(x>=0 && x<width() && y>=0 && y<height(), … … 104 104 } 105 105 106 void image::putpixel( short x, short y, char color)106 void image::putpixel(int16_t x, int16_t y, char color) 107 107 { 108 108 CONDITION(x>=0 && x<width() && y>=0 && y<height(), … … 116 116 117 117 118 image::image( short width, short height, unsigned char *page_buffer, short create_descriptor)118 image::image(int16_t width, int16_t height, uint8_t *page_buffer, int16_t create_descriptor) 119 119 { 120 120 w=width; … … 132 132 image::image(spec_entry *e, bFILE *fp) 133 133 { 134 short i;134 int16_t i; 135 135 fp->seek(e->offset,0); 136 w=fp->read_ short();137 h=fp->read_ short();136 w=fp->read_uint16(); 137 h=fp->read_uint16(); 138 138 special=NULL; 139 139 make_page(w,h,NULL); … … 145 145 image::image(bFILE *fp) 146 146 { 147 short i;148 w=fp->read_ short();149 h=fp->read_ short();147 int16_t i; 148 w=fp->read_uint16(); 149 h=fp->read_uint16(); 150 150 special=NULL; 151 151 make_page(w,h,NULL); … … 172 172 void image_init() 173 173 { 174 u nsigned charbt[2];175 u nsigned short wrd,*up;174 uint8_t bt[2]; 175 uint16_t wrd,*up; 176 176 bt[0]=1; 177 177 bt[1]=0; 178 up=(u nsigned short *)bt;179 wrd= int_to_intel(*up);178 up=(uint16_t *)bt; 179 wrd=uint16_to_intel(*up); 180 180 if (wrd!=0x01) 181 181 { printf("Compiled under wrong ENDING-nes, edit system.h and try again\n"); … … 187 187 188 188 189 long image::total_pixels(unsigned charbackground)190 { 191 short i,j;192 longco;193 u nsigned char*c;189 int32_t image::total_pixels(uint8_t background) 190 { 191 int16_t i,j; 192 int32_t co; 193 uint8_t *c; 194 194 for (co=0,i=height()-1;i>=0;i--) 195 195 { c=scan_line(i); … … 200 200 } 201 201 202 void image::clear( short color)203 { 204 short i;202 void image::clear(int16_t color) 203 { 204 int16_t i; 205 205 if (color==-1) color=current_background; 206 206 if (special) … … 220 220 { 221 221 image *im; 222 u nsigned char*c,*dat;222 uint8_t *c,*dat; 223 223 int i; 224 dat=(u nsigned char*)jmalloc(width(),"image copy");224 dat=(uint8_t *)jmalloc(width(),"image copy"); 225 225 im=new image(width(),height()); 226 226 for (i=height()-1;i>=0;i--) … … 236 236 237 237 238 void image::line( short x1, short y1,short x2, short y2, unsigned charcolor)239 { 240 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;238 void image::line(int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint8_t color) 239 { 240 int16_t i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi; 241 241 unsigned dcy,dcx; 242 242 // check to make sure that both endpoint are on the screen 243 243 244 short cx1,cy1,cx2,cy2;244 int16_t cx1,cy1,cx2,cy2; 245 245 246 246 // check to see if the line is completly clipped off … … 378 378 379 379 380 void image::put_image(image *screen, short x, short y, char transparent)381 { 382 short i,j,xl,yl;383 u nsigned char*pg1,*pg2,*source,*dest;380 void image::put_image(image *screen, int16_t x, int16_t y, char transparent) 381 { 382 int16_t i,j,xl,yl; 383 uint8_t *pg1,*pg2,*source,*dest; 384 384 if (screen->special) // the screen is clipped then we onl want to put 385 385 // part of the image … … 417 417 } 418 418 419 void image::fill_image(image *screen, short x1, short y1, short x2, short y2, short allign)420 { 421 short i,j,w,xx,start,xl,starty;422 u nsigned char*pg1,*pg2;419 void image::fill_image(image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t allign) 420 { 421 int16_t i,j,w,xx,start,xl,starty; 422 uint8_t *pg1,*pg2; 423 423 CHECK(x1<=x2 && y1<=y2); // we should have gotten this 424 424 … … 467 467 468 468 469 void image::put_part(image *screen, short x, short y,470 short x1, short y1, short x2, short y2, char transparent)471 { 472 short xl,yl,j,i;473 short cx1,cy1,cx2,cy2;474 u nsigned char*pg1,*pg2,*source,*dest;469 void image::put_part(image *screen, int16_t x, int16_t y, 470 int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent) 471 { 472 int16_t xl,yl,j,i; 473 int16_t cx1,cy1,cx2,cy2; 474 uint8_t *pg1,*pg2,*source,*dest; 475 475 CHECK(x1<=x2 && y1<=y2); 476 476 … … 533 533 } 534 534 535 void image::put_part_xrev(image *screen, short x, short y,536 short x1, short y1, short x2, short y2, char transparent)537 { 538 short xl,yl,j,i;539 short cx1,cy1,cx2,cy2;540 u nsigned char*pg1,*pg2,*source,*dest;535 void image::put_part_xrev(image *screen, int16_t x, int16_t y, 536 int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent) 537 { 538 int16_t xl,yl,j,i; 539 int16_t cx1,cy1,cx2,cy2; 540 uint8_t *pg1,*pg2,*source,*dest; 541 541 CHECK(x1<=x2 && y1<=y2); 542 542 … … 596 596 597 597 598 void image::put_part_masked(image *screen, image *mask, short x, short y,599 short maskx, short masky,600 short x1, short y1, short x2, short y2)601 { 602 short xl,yl,j,i,ml,mh;603 short cx1,cy1,cx2,cy2;604 u nsigned char*pg1,*pg2,*pg3;598 void image::put_part_masked(image *screen, image *mask, int16_t x, int16_t y, 599 int16_t maskx, int16_t masky, 600 int16_t x1, int16_t y1, int16_t x2, int16_t y2) 601 { 602 int16_t xl,yl,j,i,ml,mh; 603 int16_t cx1,cy1,cx2,cy2; 604 uint8_t *pg1,*pg2,*pg3; 605 605 CHECK(x1<=x2 && y1<=y2); 606 606 … … 658 658 659 659 660 u nsigned charimage::brightest_color(palette *pal)661 { u nsigned char*p,r,g,b,bri;662 short i,j;663 longbrv;660 uint8_t image::brightest_color(palette *pal) 661 { uint8_t *p,r,g,b,bri; 662 int16_t i,j; 663 int32_t brv; 664 664 brv=0; bri=0; 665 665 for (j=0;j<h;j++) … … 668 668 for (i=0;i<w;i++) 669 669 { pal->get(p[i],r,g,b); 670 if (( long)r*(long)g*(long)b>brv)671 { brv=( long)r*(long)g*(long)b;670 if ((int32_t)r*(int32_t)g*(int32_t)b>brv) 671 { brv=(int32_t)r*(int32_t)g*(int32_t)b; 672 672 bri=p[i]; 673 673 } … … 677 677 } 678 678 679 u nsigned char image::darkest_color(palette *pal, short noblack)680 { u nsigned char*p,r,g,b,bri;681 short i,j;682 longbrv,x;683 brv=( long)258*(long)258*(long)258; bri=0;679 uint8_t image::darkest_color(palette *pal, int16_t noblack) 680 { uint8_t *p,r,g,b,bri; 681 int16_t i,j; 682 int32_t brv,x; 683 brv=(int32_t)258*(int32_t)258*(int32_t)258; bri=0; 684 684 for (j=0;j<h;j++) 685 685 { … … 687 687 for (i=0;i<w;i++) 688 688 { pal->get(p[i],r,g,b); 689 x=( long)r*(long)g*(long)b;689 x=(int32_t)r*(int32_t)g*(int32_t)b; 690 690 if (x<brv && (x || !noblack)) 691 691 { brv=x; … … 697 697 } 698 698 699 void image::rectangle( short x1, short y1,short x2, short y2, unsigned charcolor)699 void image::rectangle(int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint8_t color) 700 700 { 701 701 line(x1,y1,x2,y1,color); … … 705 705 } 706 706 707 void image::set_clip( short x1, short y1, short x2, short y2)707 void image::set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 708 708 { 709 709 // If the image does not already have an Image descriptor, allocate one. … … 718 718 } 719 719 720 void image::get_clip ( short &x1, short &y1, short &x2, short &y2)720 void image::get_clip (int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 721 721 { 722 722 if (special) … … 726 726 } 727 727 728 void image::in_clip ( short x1, short y1, short x2, short y2)728 void image::in_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2) 729 729 { 730 730 if (special) … … 747 747 { 748 748 dirty_rect *p,*q; 749 short x1,y1,x2,y2,nn;749 int16_t x1,y1,x2,y2,nn; 750 750 x1=6000; y1=6000; 751 751 x2=0; y2=0; … … 769 769 void image_descriptor::delete_dirty(int x1, int y1, int x2, int y2) 770 770 { 771 short i,ax1,ay1,ax2,ay2;771 int16_t i,ax1,ay1,ax2,ay2; 772 772 dirty_rect *p,*next; 773 773 if (keep_dirt) … … 869 869 void image_descriptor::add_dirty(int x1, int y1, int x2, int y2) 870 870 { 871 short i;871 int16_t i; 872 872 dirty_rect *p; 873 873 if (keep_dirt) … … 941 941 } 942 942 943 void image::bar ( short x1, short y1, short x2, short y2, unsigned charcolor)944 { 945 short y;943 void image::bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) 944 { 945 int16_t y; 946 946 if (x1>x2 || y1>y2) return ; 947 947 if (special) … … 964 964 } 965 965 966 void image::xor_bar ( short x1, short y1, short x2, short y2, unsigned charcolor)967 { 968 short y,x;966 void image::xor_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) 967 { 968 int16_t y,x; 969 969 if (x1>x2 || y1>y2) return ; 970 970 if (special) … … 983 983 return ; 984 984 985 u nsigned char*sl=scan_line(y1)+x1;985 uint8_t *sl=scan_line(y1)+x1; 986 986 for (y=y1;y<=y2;y++) 987 987 { 988 u nsigned char*s=sl;988 uint8_t *s=sl; 989 989 for (x=x1;x<=x2;x++,s++) 990 990 *s=(*s)^color; … … 996 996 997 997 998 void image::unpack_scanline( short line, char bitsperpixel)999 { 1000 short x;1001 u nsigned char*sl,*ex,mask,bt,sh;1002 ex=(u nsigned char*)jmalloc(width(),"image::unpacked scanline");998 void image::unpack_scanline(int16_t line, char bitsperpixel) 999 { 1000 int16_t x; 1001 uint8_t *sl,*ex,mask,bt,sh; 1002 ex=(uint8_t *)jmalloc(width(),"image::unpacked scanline"); 1003 1003 sl=scan_line(line); 1004 1004 memcpy(ex,sl,width()); … … 1018 1018 void image::dither(palette *pal) 1019 1019 { 1020 short x,y,i,j;1021 u nsigned chardt_matrix[]={0, 136,24, 170,1020 int16_t x,y,i,j; 1021 uint8_t dt_matrix[]={0, 136,24, 170, 1022 1022 68, 204,102,238, 1023 1023 51, 187, 17,153, 1024 1024 119,255, 85,221}; 1025 1025 1026 u nsigned char*sl;1026 uint8_t *sl; 1027 1027 for (y=height()-1;y>=0;y--) 1028 1028 { … … 1049 1049 } 1050 1050 1051 void image::resize( short new_width, short new_height)1051 void image::resize(int16_t new_width, int16_t new_height) 1052 1052 { 1053 1053 int old_width=width(),old_height=height(); 1054 u nsigned char *im=(unsigned char*)jmalloc(width()*height(),"image::resized");1054 uint8_t *im=(uint8_t *)jmalloc(width()*height(),"image::resized"); 1055 1055 memcpy(im,scan_line(0),width()*height()); 1056 1056 … … 1060 1060 h=new_height; 1061 1061 1062 u nsigned char*sl1,*sl2;1063 short y,y2,x2;1062 uint8_t *sl1,*sl2; 1063 int16_t y,y2,x2; 1064 1064 double yc,xc,yd,xd; 1065 1065 … … 1080 1080 } 1081 1081 1082 void image::scroll( short x1, short y1, short x2, short y2, short xd, short yd)1083 { 1084 short cx1,cy1,cx2,cy2;1082 void image::scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd) 1083 { 1084 int16_t cx1,cy1,cx2,cy2; 1085 1085 CHECK(x1>=0 && y1>=0 && x1<x2 && y1<y2 && x2<width() && y2<height()); 1086 1086 if (special) … … 1089 1089 x1=max(x1,cx1); y1=max(cy1,y1); x2=min(x2,cx2); y2=min(y2,cy2); 1090 1090 } 1091 short xsrc,ysrc,xdst,ydst,xtot=x2-x1-abs(xd)+1,ytot,xt;1092 u nsigned char*src,*dst;1091 int16_t xsrc,ysrc,xdst,ydst,xtot=x2-x1-abs(xd)+1,ytot,xt; 1092 uint8_t *src,*dst; 1093 1093 if (xd<0) { xsrc=x1-xd; xdst=x1; } else { xsrc=x2-xd; xdst=x2; } 1094 1094 if (yd<0) { ysrc=y1-yd; ydst=y1; } else { ysrc=y2-yd; ydst=y2; } … … 1107 1107 1108 1108 1109 image *image::create_smooth( short smoothness)1110 { 1111 short i,j,k,l,t,d;1109 image *image::create_smooth(int16_t smoothness) 1110 { 1111 int16_t i,j,k,l,t,d; 1112 1112 image *im; 1113 1113 CHECK(smoothness>=0); … … 1129 1129 } 1130 1130 1131 void image::wiget_bar( short x1, short y1, short x2, short y2,1132 u nsigned char light, unsigned char med, unsigned chardark)1131 void image::wiget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 1132 uint8_t light, uint8_t med, uint8_t dark) 1133 1133 { 1134 1134 line(x1,y1,x2,y1,light); … … 1142 1142 { 1143 1143 public : 1144 short x,y;1144 int16_t x,y; 1145 1145 fill_rec *last; 1146 fill_rec( short X, short Y, fill_rec *Last)1146 fill_rec(int16_t X, int16_t Y, fill_rec *Last) 1147 1147 { x=X; y=Y; last=Last; } 1148 1148 } ; 1149 1149 1150 void image::flood_fill( short x, short y, unsigned charcolor)1151 { 1152 u nsigned char*sl,*above,*below;1150 void image::flood_fill(int16_t x, int16_t y, uint8_t color) 1151 { 1152 uint8_t *sl,*above,*below; 1153 1153 fill_rec *recs=NULL,*r; 1154 u nsigned charfcolor;1154 uint8_t fcolor; 1155 1155 sl=scan_line(y); 1156 1156 fcolor=sl[x]; … … 1231 1231 #define LED_L 5 1232 1232 #define LED_H 5 1233 void image::burn_led( short x, short y, long num, short color, short scale)1233 void image::burn_led(int16_t x, int16_t y, int32_t num, int16_t color, int16_t scale) 1234 1234 { 1235 1235 char st[100]; 1236 short ledx[]={1,2,1,2,3,3,3,3,1,2,0,0,0,0};1237 short ledy[]={3,3,0,0,1,2,4,6,7,7,4,6,1,2};1238 1239 short dig[]={2+4+8+16+32+64,4+8,2+4+1+32+16,2+4+1+8+16,64+1+4+8,1236 int16_t ledx[]={1,2,1,2,3,3,3,3,1,2,0,0,0,0}; 1237 int16_t ledy[]={3,3,0,0,1,2,4,6,7,7,4,6,1,2}; 1238 1239 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, 1240 1240 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}; 1241 short xx,yy,zz;1242 sprintf(st,"%8ld", num);1241 int16_t xx,yy,zz; 1242 sprintf(st,"%8ld",(long int)num); 1243 1243 for (xx=0;xx<8;xx++) 1244 1244 { … … 1258 1258 } 1259 1259 1260 u nsigned chardither_matrix[]={0, 136,24, 170,1260 uint8_t dither_matrix[]={0, 136,24, 170, 1261 1261 68, 204,102,238, 1262 1262 51, 187, 17,153, 1263 1263 119,255, 85,221}; 1264 1264 1265 image *image::copy_part_dithered ( short x1, short y1, short x2, short y2)1266 { 1267 short x,y,cx1,cy1,cx2,cy2,ry,rx,bo,dity,ditx;1265 image *image::copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2) 1266 { 1267 int16_t x,y,cx1,cy1,cx2,cy2,ry,rx,bo,dity,ditx; 1268 1268 image *ret; 1269 u nsigned char*sl1,*sl2;1269 uint8_t *sl1,*sl2; 1270 1270 get_clip(cx1,cy1,cx2,cy2); 1271 1271 if (y1<cy1) y1=cy1; … … 1304 1304 void image::flip_x() 1305 1305 { 1306 u nsigned char *rev=(unsigned char*)jmalloc(width(),"image tmp::flipped_x"),*sl;1306 uint8_t *rev=(uint8_t *)jmalloc(width(),"image tmp::flipped_x"),*sl; 1307 1307 CONDITION(rev,"memory allocation"); 1308 1308 int y,x,i; … … 1318 1318 void image::flip_y() 1319 1319 { 1320 u nsigned char *rev=(unsigned char*)jmalloc(width(),"image::flipped_y"),*sl;1320 uint8_t *rev=(uint8_t *)jmalloc(width(),"image::flipped_y"),*sl; 1321 1321 CONDITION(rev,"memory allocation"); 1322 1322 int y; … … 1329 1329 } 1330 1330 1331 void image::make_color(u nsigned charcolor)1332 { 1333 u nsigned char*sl;1331 void image::make_color(uint8_t color) 1332 { 1333 uint8_t *sl; 1334 1334 int y,x; 1335 1335 for (y=0;y<height();y++)
Note: See TracChangeset
for help on using the changeset viewer.