Changeset 512 for abuse/trunk/src/imlib/image.cpp
- Timestamp:
- Apr 20, 2011, 12:39:27 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/image.cpp
r494 r512 18 18 #endif 19 19 #include <stdlib.h> 20 21 #include "common.h" 20 22 21 23 #include "image.h" … … 91 93 { 92 94 delete_page(); 93 w=new_width; 94 h=new_height; 95 size = vec2i(new_width, new_height); 95 96 make_page(new_width, new_height, page); 96 97 } … … 120 121 uint8_t image::pixel(int16_t x, int16_t y) 121 122 { 122 CONDITION(x>=0 && x< width() && y>=0 && y<height(),123 CONDITION(x>=0 && x<size.x && y>=0 && y<size.y, 123 124 "image::pixel Bad pixel xy"); 124 125 return (*(scan_line(y)+x)); … … 127 128 void image::putpixel(int16_t x, int16_t y, char color) 128 129 { 129 CONDITION(x>=0 && x< width() && y>=0 && y<height(),130 CONDITION(x>=0 && x<size.x && y>=0 && y<size.y, 130 131 "image::putpixel Bad pixel xy"); 131 132 if (special) … … 139 140 image::image(int16_t width, int16_t height, uint8_t *page_buffer, int16_t create_descriptor) 140 141 { 141 w=width; 142 h=height; 142 size = vec2i(width, height); 143 143 if (create_descriptor || page_buffer) 144 144 { … … 154 154 image::image(spec_entry *e, bFILE *fp) 155 155 { 156 int16_t i;157 fp->seek(e->offset, 0);158 w=fp->read_uint16();159 h=fp->read_uint16();160 special=NULL;161 make_page(w, h, NULL);162 for (i=0; i<h; i++)163 fp->read(scan_line(i), w);164 image_list.add_end((linked_node *) this);156 int16_t i; 157 fp->seek(e->offset, 0); 158 size.x = fp->read_uint16(); 159 size.y = fp->read_uint16(); 160 special = NULL; 161 make_page(size.x, size.y, NULL); 162 for (i = 0; i < size.y; i++) 163 fp->read(scan_line(i), size.x); 164 image_list.add_end((linked_node *) this); 165 165 _locked = false; 166 166 } … … 168 168 image::image(bFILE *fp) 169 169 { 170 int16_t i;171 w=fp->read_uint16();172 h=fp->read_uint16();173 special=NULL;174 make_page(w, h, NULL);175 for (i=0; i<h; i++)176 fp->read(scan_line(i), w);177 image_list.add_end((linked_node *) this);170 int16_t i; 171 size.x = fp->read_uint16(); 172 size.y = fp->read_uint16(); 173 special = NULL; 174 make_page(size.x, size.y, NULL); 175 for (i = 0; i < size.y; i++) 176 fp->read(scan_line(i), size.x); 177 image_list.add_end((linked_node *) this); 178 178 _locked = false; 179 179 } … … 237 237 238 238 lock(); 239 for(co = 0, i = height()- 1; i >= 0; i--)239 for(co = 0, i = size.y - 1; i >= 0; i--) 240 240 { 241 241 c = scan_line(i); 242 for(j = width()- 1; j >= 0; j--, c++)242 for(j = size.x - 1; j >= 0; j--, c++) 243 243 if(*c != background) co++; 244 244 } … … 262 262 } 263 263 else 264 for(i = height()- 1; i >= 0; i--)265 memset(scan_line(i), color, width());266 add_dirty(0, 0, width() - 1, height()- 1);264 for(i = size.y - 1; i >= 0; i--) 265 memset(scan_line(i), color, size.x); 266 add_dirty(0, 0, size.x - 1, size.y - 1); 267 267 unlock(); 268 268 } … … 275 275 276 276 lock(); 277 dat = (uint8_t *)malloc( width());278 im = new image( width(), height());277 dat = (uint8_t *)malloc(size.x); 278 im = new image(size.x, size.y); 279 279 im->lock(); 280 for(i = height()- 1; i >= 0; i--)280 for(i = size.y - 1; i >= 0; i--) 281 281 { 282 282 c = scan_line(i); 283 memcpy(dat, c, width());283 memcpy(dat, c, size.x); 284 284 c = im->scan_line(i); 285 memcpy(c, dat, width());285 memcpy(c, dat, size.x); 286 286 } 287 287 im->unlock(); … … 443 443 if(screen->special) 444 444 { 445 put_part(screen, x, y, 0, 0, width()-1, height()-1, transparent);445 put_part(screen, x, y, 0, 0, size.x-1, size.y-1, transparent); 446 446 return; 447 447 } 448 448 449 if(x < screen-> width() && y < screen->height())450 { 451 xl = width();452 if(x + xl > screen-> width()) // clip to the border of the screen453 xl = screen-> width()- x;454 yl = height();455 if(y + yl > screen-> height())456 yl = screen-> height()- y;449 if(x < screen->Size().x && y < screen->Size().y) 450 { 451 xl = size.x; 452 if(x + xl > screen->Size().x) // clip to the border of the screen 453 xl = screen->Size().x - x; 454 yl = size.y; 455 if(y + yl > screen->Size().y) 456 yl = screen->Size().y - y; 457 457 458 458 int startx = 0, starty = 0; … … 511 511 { if (x1<0) x1=0; 512 512 if (y2<0) y1=0; 513 if (x2>=screen-> width()) x2=screen->width()-1;514 if (y2>=screen-> height()) y2=screen->height()-1;515 } 516 if (x2<0 || y2<0 || x1>=screen-> width() || y1>=screen->height())513 if (x2>=screen->Size().x) x2=screen->Size().x-1; 514 if (y2>=screen->Size().y) y2=screen->Size().y-1; 515 } 516 if (x2<0 || y2<0 || x1>=screen->Size().x || y1>=screen->Size().y) 517 517 return ; 518 518 screen->add_dirty(x1, y1, x2, y2); 519 w= width();519 w=size.x; 520 520 if (align) 521 521 { 522 522 start=x1%w; 523 starty=y1% height();523 starty=y1%size.y; 524 524 } 525 525 else … … 533 533 pg1=screen->scan_line(j); 534 534 pg2=scan_line(starty++); 535 if (starty>= height()) starty=0;535 if (starty>=size.y) starty=0; 536 536 i=x1; 537 537 xx=start; … … 565 565 if (x1<0) { x+=-x1; x1=0; } 566 566 if (y1<0) { y+=-y1; y1=0; } 567 if (x2>= width()) x2=width()-1;568 if (y2>= height()) y2=height()-1;567 if (x2>=size.x) x2=size.x-1; 568 if (y2>=size.y) y2=size.y-1; 569 569 if (x1>x2 || y1>y2) return ; // return if it was adjusted so that nothing will be put 570 570 … … 628 628 CHECK(x1<=x2 && y1<=y2); 629 629 630 i=x1; x1= width()-x2-1; // reverse the x locations631 x2= width()-i-1;630 i=x1; x1=size.x-x2-1; // reverse the x locations 631 x2=size.x-i-1; 632 632 633 633 if (x1<0) … … 649 649 { y2=cy2-y+y1; } 650 650 } 651 else if (x>screen-> width() || y>screen->height()|| x+x2<0 || y+y2<0)651 else if (x>screen->Size().x || y>screen->Size().y || x+x2<0 || y+y2<0) 652 652 return ; 653 653 654 if (x<screen-> width() && y<screen->height() && x1<width() && y1<height()&&654 if (x<screen->Size().x && y<screen->Size().y && x1<size.x && y1<size.y && 655 655 x1<=x2 && y1<=y2) 656 656 { 657 if (x2>= width())658 x2= width()-1;659 if (y2>= height())660 y2= height()-1;657 if (x2>=size.x) 658 x2=size.x-1; 659 if (y2>=size.y) 660 y2=size.y-1; 661 661 xl=x2-x1+1; 662 if (x+xl>screen-> width())663 xl=screen-> width()-x;662 if (x+xl>screen->Size().x) 663 xl=screen->Size().x-x; 664 664 yl=y2-y1+1; 665 if (y+yl>screen-> height())666 yl=screen-> height()-y;665 if (y+yl>screen->Size().y) 666 yl=screen->Size().y-y; 667 667 screen->add_dirty(x, y, x+xl-1, y+yl-1); 668 668 screen->lock(); … … 709 709 { y2=cy2+y1-y; } 710 710 } 711 else if (x>screen-> width() || y>screen->height()|| x+x1<0 || y+y1<0)711 else if (x>screen->Size().x || y>screen->Size().y || x+x1<0 || y+y1<0) 712 712 return ; 713 713 714 ml=mask-> width();715 mh=mask-> height();716 if (x<screen-> width() && y<screen->height() && x1<width() && y1<height()&&714 ml=mask->Size().x; 715 mh=mask->Size().y; 716 if (x<screen->Size().x && y<screen->Size().y && x1<size.x && y1<size.y && 717 717 maskx<ml && masky<mh && x1<=x2 && y1<=y2) 718 718 { 719 719 720 if (x2>= width())721 x2= width()-1;722 if (y2>= height())723 y2= height()-1;720 if (x2>=size.x) 721 x2=size.x-1; 722 if (y2>=size.y) 723 y2=size.y-1; 724 724 xl=x2-x1+1; 725 if (x+xl>screen-> width())726 xl=screen-> width()-x-1;725 if (x+xl>screen->Size().x) 726 xl=screen->Size().x-x-1; 727 727 yl=y2-y1+1; 728 if (y+yl>screen-> height())729 yl=screen-> height()-y-1;728 if (y+yl>screen->Size().y) 729 yl=screen->Size().y-y-1; 730 730 screen->add_dirty(x, y, x+xl-1, y+yl-1); 731 731 screen->lock(); … … 761 761 brv=0; bri=0; 762 762 lock(); 763 for (j=0; j< h; j++)763 for (j=0; j<size.y; j++) 764 764 { 765 765 p=scan_line(j); 766 for (i=0; i< w; i++)766 for (i=0; i<size.x; i++) 767 767 { pal->get(p[i], r, g, b); 768 768 if ((int32_t)r*(int32_t)g*(int32_t)b>brv) … … 782 782 brv=(int32_t)258*(int32_t)258*(int32_t)258; bri=0; 783 783 lock(); 784 for (j=0; j< h; j++)784 for (j=0; j<size.y; j++) 785 785 { 786 786 p=scan_line(j); 787 for (i=0; i< w; i++)787 for (i=0; i<size.x; i++) 788 788 { pal->get(p[i], r, g, b); 789 789 x=(int32_t)r*(int32_t)g*(int32_t)b; … … 811 811 // with no dirty rectangle keeping. 812 812 if(!special) 813 special = new image_descriptor( width(), height(), 0);813 special = new image_descriptor(size.x, size.y, 0); 814 814 815 815 // set the image descriptor what the clip … … 823 823 special->get_clip(x1, y1, x2, y2); 824 824 else 825 { x1=0; y1=0; x2= width()-1; y2=height()-1; }825 { x1=0; y1=0; x2=size.x-1; y2=size.y-1; } 826 826 } 827 827 … … 1056 1056 { if (x1<0) x1=0; 1057 1057 if (y1<0) y1=0; 1058 if (x2>= width()) x2=width()-1;1059 if (y2>= height()) y2=height()-1;1060 } 1061 if (x2<0 || y2<0 || x1>= width() || y1>=height()|| x2<x1 || y2<y1)1058 if (x2>=size.x) x2=size.x-1; 1059 if (y2>=size.y) y2=size.y-1; 1060 } 1061 if (x2<0 || y2<0 || x1>=size.x || y1>=size.y || x2<x1 || y2<y1) 1062 1062 return ; 1063 1063 lock(); … … 1081 1081 { if (x1<0) x1=0; 1082 1082 if (y1<0) y1=0; 1083 if (x2>= width()) x2=width()-1;1084 if (y2>= height()) y2=height()-1;1085 } 1086 if (x2<0 || y2<0 || x1>= width() || y1>=height()|| x2<x1 || y2<y1)1083 if (x2>=size.x) x2=size.x-1; 1084 if (y2>=size.y) y2=size.y-1; 1085 } 1086 if (x2<0 || y2<0 || x1>=size.x || y1>=size.y || x2<x1 || y2<y1) 1087 1087 return ; 1088 1088 … … 1094 1094 for (x=x1; x<=x2; x++, s++) 1095 1095 *s=(*s)^color; 1096 sl+= w;1096 sl+=size.x; 1097 1097 } 1098 1098 unlock(); … … 1106 1106 int16_t x; 1107 1107 uint8_t *sl, *ex, mask, bt, sh; 1108 ex=(uint8_t *)malloc( width());1108 ex=(uint8_t *)malloc(size.x); 1109 1109 1110 1110 lock(); 1111 1111 sl=scan_line(line); 1112 memcpy(ex, sl, width());1112 memcpy(ex, sl, size.x); 1113 1113 unlock(); 1114 1114 … … 1117 1117 else { mask=128+64+32+16; bt=2; } 1118 1118 1119 for (x=0; x< width(); x++)1119 for (x=0; x<size.x; x++) 1120 1120 { sh=((x%bt)<<(bitsperpixel-1)); 1121 1121 sl[x]=(ex[x/bt]&(mask>>sh))>>(bt-sh-1); … … 1135 1135 uint8_t *sl; 1136 1136 lock(); 1137 for (y= height()-1; y>=0; y--)1137 for (y=size.y-1; y>=0; y--) 1138 1138 { 1139 1139 sl=scan_line(y); 1140 for (i=0, j=y%4, x= width()-1; x>=0; x--)1140 for (i=0, j=y%4, x=size.x-1; x>=0; x--) 1141 1141 { 1142 1142 if (pal->red(sl[x])>dt_matrix[j*4+i]) … … 1162 1162 void image::resize(int16_t new_width, int16_t new_height) 1163 1163 { 1164 int old_width= width(), old_height=height();1165 uint8_t *im=(uint8_t *)malloc( width()*height());1164 int old_width=size.x, old_height=size.y; 1165 uint8_t *im=(uint8_t *)malloc(size.x*size.y); 1166 1166 lock(); 1167 memcpy(im, scan_line(0), width()*height());1167 memcpy(im, scan_line(0), size.x*size.y); 1168 1168 1169 1169 delete_page(); 1170 1170 make_page(new_width, new_height, NULL); 1171 w=new_width; // set the new hieght and width 1172 h=new_height; 1171 size = vec2i(new_width, new_height); // set the new height and width 1173 1172 1174 1173 uint8_t *sl1, *sl2; … … 1196 1195 { 1197 1196 int16_t cx1, cy1, cx2, cy2; 1198 CHECK(x1>=0 && y1>=0 && x1<x2 && y1<y2 && x2< width() && y2<height());1197 CHECK(x1>=0 && y1>=0 && x1<x2 && y1<y2 && x2<size.x && y2<size.y); 1199 1198 if (special) 1200 1199 { … … 1228 1227 d=smoothness*2+1; 1229 1228 d=d*d; 1230 im=new image( width(), height());1231 for (i=0; i< width(); i++)1232 for (j=0; j< height(); j++)1229 im=new image(size.x, size.y); 1230 for (i=0; i<size.x; i++) 1231 for (j=0; j<size.y; j++) 1233 1232 { 1234 1233 for (t=0, k=-smoothness; k<=smoothness; k++) 1235 1234 for (l=-smoothness; l<=smoothness; l++) 1236 if (i+k>smoothness && i+k< width()-smoothness && j+l<height()-smoothness && j+l>smoothness)1235 if (i+k>smoothness && i+k<size.x-smoothness && j+l<size.y-smoothness && j+l>smoothness) 1237 1236 t+=pixel(i+k, j+l); 1238 1237 else t+=pixel(i, j); … … 1291 1290 } 1292 1291 } 1293 if (y< height()-1)1292 if (y<size.y-1) 1294 1293 { 1295 1294 above=scan_line(y+1); … … 1312 1311 } 1313 1312 } 1314 if (y< height()-1)1313 if (y<size.y-1) 1315 1314 { below=scan_line(y+1); 1316 1315 if (x>0 && below[x-1]!=fcolor && below[x]==fcolor) … … 1320 1319 } 1321 1320 x++; 1322 } while (sl[x]==fcolor && x< width());1321 } while (sl[x]==fcolor && x<size.x); 1323 1322 x--; 1324 1323 if (y>0) … … 1330 1329 } 1331 1330 } 1332 if (y< height()-1)1331 if (y<size.y-1) 1333 1332 { 1334 1333 above=scan_line(y+1); … … 1425 1424 void image::flip_x() 1426 1425 { 1427 uint8_t *rev=(uint8_t *)malloc( width()), *sl;1426 uint8_t *rev=(uint8_t *)malloc(size.x), *sl; 1428 1427 CONDITION(rev, "memory allocation"); 1429 1428 int y, x, i; … … 1431 1430 /* FIXME: Abuse Win32 uses RestoreSurface() here instead of locking */ 1432 1431 lock(); 1433 for (y=0; y< height(); y++)1432 for (y=0; y<size.y; y++) 1434 1433 { sl=scan_line(y); 1435 for (i=0, x= width()-1; x>=0; x--, i++)1434 for (i=0, x=size.x-1; x>=0; x--, i++) 1436 1435 rev[i]=sl[x]; 1437 memcpy(sl, rev, width());1436 memcpy(sl, rev, size.x); 1438 1437 } 1439 1438 unlock(); … … 1443 1442 void image::flip_y() 1444 1443 { 1445 uint8_t *rev=(uint8_t *)malloc( width()), *sl;1444 uint8_t *rev=(uint8_t *)malloc(size.x), *sl; 1446 1445 CONDITION(rev, "memory allocation"); 1447 1446 int y; … … 1449 1448 /* FIXME: Abuse Win32 uses RestoreSurface() here instead of locking */ 1450 1449 lock(); 1451 for (y=0; y< height()/2; y++)1450 for (y=0; y<size.y/2; y++) 1452 1451 { sl=scan_line(y); 1453 memcpy(rev, sl, width());1454 memcpy(sl, scan_line( height()-y-1), width());1455 memcpy(scan_line( height()-y-1), rev, width());1452 memcpy(rev, sl, size.x); 1453 memcpy(sl, scan_line(size.y-y-1), size.x); 1454 memcpy(scan_line(size.y-y-1), rev, size.x); 1456 1455 } 1457 1456 unlock(); … … 1464 1463 int y, x; 1465 1464 lock(); 1466 for (y=0; y< height(); y++)1465 for (y=0; y<size.y; y++) 1467 1466 { 1468 1467 sl=scan_line(y); 1469 for (x= width(); x; x--, sl++)1468 for (x=size.x; x; x--, sl++) 1470 1469 if (*sl) 1471 1470 *sl=color;
Note: See TracChangeset
for help on using the changeset viewer.