Changeset 527 for abuse/trunk/src/imlib/timage.cpp
- Timestamp:
- Apr 22, 2011, 4:13:04 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/timage.cpp
r521 r527 17 17 image *trans_image::make_image() 18 18 { 19 image *im =new image(vec2i(w,h));19 image *im = new image(m_size); 20 20 21 21 im->Lock(); 22 uint8_t *d=im->scan_line(0),*dp= data,*dline;22 uint8_t *d=im->scan_line(0),*dp=m_data,*dline; 23 23 int y,x; 24 for (y=0; y< h; y++)24 for (y=0; y<m_size.y; y++) 25 25 { 26 26 x=0; 27 27 dline=d; 28 memset(dline,0, w);29 while(x< w)28 memset(dline,0,m_size.x); 29 while(x<m_size.x) 30 30 { 31 31 int skip=*(dp++); 32 32 dline+=skip; 33 33 x+=skip; 34 if (x< w)34 if (x<m_size.x) 35 35 { 36 36 int run=*(dp++); … … 51 51 int size=0,x,y; 52 52 uint8_t *sl,*datap,*marker; 53 w=im->Size().x; 54 h=im->Size().y; 53 m_size = im->Size(); 55 54 56 55 im->Lock(); … … 61 60 sl=im->scan_line(y); 62 61 x=0; 63 while (x< w)62 while (x<m_size.x) 64 63 { 65 64 size++; 66 while (x< w&& *sl==0) { sl++; x++; }67 68 if (x< w)65 while (x<m_size.x && *sl==0) { sl++; x++; } 66 67 if (x<m_size.x) 69 68 { 70 69 size++; // byte for the size of the run 71 while (x< w&& (*sl)!=0)70 while (x<m_size.x && (*sl)!=0) 72 71 { 73 72 size++; … … 79 78 } 80 79 81 data=(uint8_t *)malloc(size);80 m_data=(uint8_t *)malloc(size); 82 81 int ww=im->Size().x,hh=im->Size().y; 83 datap= data;82 datap=m_data; 84 83 if (!datap) 85 84 { printf("size = %d %d (%d)\n",im->Size().x,im->Size().y,size); } 86 CONDITION(datap,"malloc error for trans_image:: data");85 CONDITION(datap,"malloc error for trans_image::m_data"); 87 86 88 87 for (y=0; y<hh; y++) // now actually make the runs … … 116 115 } 117 116 117 trans_image::~trans_image() 118 { 119 free(m_data); 120 } 121 118 122 void trans_image::put_scan_line(image *screen, int x, int y, int line) // always transparent 119 123 { 120 124 int x1, y1, x2, y2; 121 125 screen->GetClip(x1, y1, x2, y2); 122 if (y + line < y1 || y + line >= y2 || x >= x2 || x + w- 1 < x1)126 if (y + line < y1 || y + line >= y2 || x >= x2 || x + m_size.x - 1 < x1) 123 127 return; // clipped off completely? 124 128 125 uint8_t *datap= data;129 uint8_t *datap=m_data; 126 130 int ix; 127 131 while (line) // skip scan line data until we get to the line of interest 128 132 { 129 for (ix=0; ix< w; )133 for (ix=0; ix<m_size.x; ) 130 134 { 131 135 ix+=*datap; // skip blank space 132 136 datap++; 133 if (ix< w)137 if (ix<m_size.x) 134 138 { 135 139 int run_length=*datap; // skip run … … 147 151 uint8_t *screen_line=screen->scan_line(y)+x; 148 152 149 for (ix=0; ix< w; )153 for (ix=0; ix<m_size.x; ) 150 154 { 151 155 int skip=*datap; // how much space to skip? … … 154 158 ix+=skip; 155 159 156 if (ix< w)160 if (ix<m_size.x) 157 161 { 158 162 int run_length=*datap; … … 204 208 { 205 209 // check to see if it is totally clipped out first 206 if (y + h <= y1 || y >= y2 || x >= x2 || x + w<= x1)210 if (y + m_size.y <= y1 || y >= y2 || x >= x2 || x + m_size.x <= x1) 207 211 return NULL; 208 212 209 uint8_t *parser = data;213 uint8_t *parser = m_data; 210 214 211 215 int skiplines = Max(y1 - y, 0); // number of lines to skip 212 ysteps = Min(y2 - y, height()- skiplines); // number of lines to draw216 ysteps = Min(y2 - y, m_size.y - skiplines); // number of lines to draw 213 217 y += skiplines; // first line to draw 214 218 215 219 while (skiplines--) 216 220 { 217 for (int ix = 0; ix < w; )221 for (int ix = 0; ix < m_size.x; ) 218 222 { 219 223 ix += *parser++; // skip over empty space 220 224 221 if (ix >= w)225 if (ix >= m_size.x) 222 226 break; 223 227 … … 227 231 } 228 232 229 screen->AddDirty(Max(x, x1), y, Min(x + width(), x2), y + h);233 screen->AddDirty(Max(x, x1), y, Min(x + m_size.x, x2), y + m_size.y); 230 234 return parser; 231 235 } … … 246 250 247 251 screen_line=screen->scan_line(y)+x; 248 int sw=screen->Size().x- w;252 int sw=screen->Size().x-m_size.x; 249 253 x1 -= x; x2 -= x; 250 254 for (; ysteps>0; ysteps--) 251 255 { 252 256 int ix,slam_length; 253 for (ix=0; ix< w; )257 for (ix=0; ix<m_size.x; ) 254 258 { 255 259 int blank=(*datap); … … 259 263 260 264 datap++; 261 if (ix< w)265 if (ix<m_size.x) 262 266 { 263 267 slam_length=*datap; // find the length of this run … … 310 314 void trans_image::put_image_offseted(image *screen, uint8_t *s_off) // if screen x & y offset already calculated save a mul 311 315 { 312 int ix,ysteps= height();316 int ix,ysteps=m_size.y; 313 317 int screen_skip; 314 uint8_t skip,*datap= data;318 uint8_t skip,*datap=m_data; 315 319 316 320 screen->Lock(); 317 screen_skip = screen->Size().x - w;321 screen_skip = screen->Size().x - m_size.x; 318 322 for (; ysteps; ysteps--) 319 323 { 320 for (ix=0; ix< w; )324 for (ix=0; ix<m_size.x; ) 321 325 { 322 326 skip=*datap; // skip leading blank space … … 329 333 330 334 331 if (ix< w)335 if (ix<m_size.x) 332 336 { 333 337 skip=*datap; … … 364 368 { 365 369 int ix,slam_length; 366 for (ix=0; ix< w; )370 for (ix=0; ix<m_size.x; ) 367 371 { 368 372 ix+=(*datap); // skip over empty space 369 373 datap++; 370 if (ix< w)374 if (ix<m_size.x) 371 375 { 372 376 slam_length=*datap; // find the length of this run … … 430 434 { 431 435 int ix,slam_length; 432 for (ix=0; ix< w; )436 for (ix=0; ix<m_size.x; ) 433 437 { 434 438 ix+=(*datap); // skip over empty space 435 439 datap++; 436 if (ix< w)440 if (ix<m_size.x) 437 441 { 438 442 slam_length=*datap; // find the length of this run … … 509 513 { 510 514 int ix,slam_length; 511 for (ix=0; ix< w; )515 for (ix=0; ix<m_size.x; ) 512 516 { 513 517 ix+=(*datap); // skip over empty space 514 518 datap++; 515 if (ix< w)519 if (ix<m_size.x) 516 520 { 517 521 slam_length=*datap; // find the length of this run … … 592 596 screen_line=screen->scan_line(y); 593 597 594 for (ix=0; ix< w; )598 for (ix=0; ix<m_size.x; ) 595 599 { 596 600 ix+=(*datap); // skip over empty space 597 601 datap++; 598 if (ix< w)602 if (ix<m_size.x) 599 603 { 600 604 slam_length=*datap; // find the length of this run … … 687 691 screen_line=screen->scan_line(y); 688 692 689 for (ix=0; ix< w; )693 for (ix=0; ix<m_size.x; ) 690 694 { 691 695 ix+=(*datap); // skip over empty space 692 696 datap++; 693 if (ix< w)697 if (ix<m_size.x) 694 698 { 695 699 slam_length=*datap; // find the length of this run … … 771 775 screen_line=screen->scan_line(y); 772 776 773 for (ix=0; ix< w; )777 for (ix=0; ix<m_size.x; ) 774 778 { 775 779 ix+=(*datap); // skip over empty space 776 780 datap++; 777 if (ix< w)781 if (ix<m_size.x) 778 782 { 779 783 slam_length=*datap; // find the length of this run … … 844 848 845 849 846 for (ix=0; ix< w; )850 for (ix=0; ix<m_size.x; ) 847 851 { 848 852 ix+=(*datap); // skip over empty space 849 853 datap++; 850 if (ix< w)854 if (ix<m_size.x) 851 855 { 852 856 slam_length=*datap; // find the length of this run … … 935 939 936 940 // see if the last scanline is clipped off 937 if (y + ysteps == y2 - 1) ysteps -= 2; 938 else if (y + ysteps == y2 - 2) ysteps--; 939 /* { 940 for (int x=0; x<w; ) 941 { 942 int skip=*datap; datap++; 943 x+=skip; 944 if (x<w) 945 { 946 int run_size=*datap; 947 datap+=run_size+1; 948 x+=run_size; 949 } 950 } 951 if (y==y2 - 1) 952 return; 953 else 954 y++; 955 }*/ 941 ysteps = Min(ysteps, y2 - 1 - y - 2); 956 942 957 943 screen->Lock(); … … 962 948 { 963 949 int ix,slam_length; 964 for (ix=0; ix< w; )950 for (ix=0; ix<m_size.x; ) 965 951 { 966 952 ix+=(*datap); // skip over empty space 967 953 datap++; 968 if (ix< w)954 if (ix<m_size.x) 969 955 { 970 956 slam_length=*datap; // find the length of this run … … 1011 997 } 1012 998 1013 int trans_image::size()1014 { 1015 uint8_t *d=data;1016 int t=0;1017 for (int y=0; y<h; y++) 1018 {1019 int x=0;1020 while (x<w)1021 {1022 x+=*d; d++; t++;1023 if (x<w) 1024 {1025 int s=*d; d++; t+=s+1;1026 d+=s; 1027 x+=s;1028 }1029 } 1030 }1031 return t+4+4; 1032 } 999 size_t trans_image::MemUsage() 1000 { 1001 uint8_t *d = m_data; 1002 size_t t = 0; 1003 1004 for (int y = 0; y < m_size.y; y++) 1005 { 1006 for (int x = 0; x < m_size.x; x++) 1007 { 1008 x += *d; d++; t++; 1009 1010 if (x >= m_size.x) 1011 break; 1012 1013 int s = *d; d++; t += s + 1; d += s; x += s; 1014 } 1015 } 1016 return t + 4 + 4; 1017 } 1018
Note: See TracChangeset
for help on using the changeset viewer.