Changeset 531 for abuse/trunk/src/imlib/timage.cpp
- Timestamp:
- Apr 22, 2011, 7:32:05 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/timage.cpp
r530 r531 15 15 #include "timage.h" 16 16 17 image *trans_image::make_image()18 {19 image *im = new image(m_size);20 21 im->Lock();22 uint8_t *d=im->scan_line(0),*dp=m_data,*dline;23 int y,x;24 for (y=0; y<m_size.y; y++)25 {26 x=0;27 dline=d;28 memset(dline,0,m_size.x);29 while(x<m_size.x)30 {31 int skip=*(dp++);32 dline+=skip;33 x+=skip;34 if (x<m_size.x)35 {36 int run=*(dp++);37 memcpy(dline,dp,run);38 x+=run;39 dline+=run;40 dp+=run;41 }42 }43 d=im->next_line(y,d);44 }45 im->Unlock();46 return im;47 }48 49 17 trans_image::trans_image(image *im, char const *name) 50 18 { 51 int size=0,x,y; 52 uint8_t *sl,*datap,*marker; 53 m_size = im->Size(); 54 55 im->Lock(); 56 57 // first we must find out how much data to allocate 58 for (y=0; y<im->Size().y; y++) 59 { 60 sl=im->scan_line(y); 61 x=0; 62 while (x<m_size.x) 63 { 64 size++; 65 while (x<m_size.x && *sl==0) { sl++; x++; } 66 67 if (x<m_size.x) 68 { 69 size++; // byte for the size of the run 70 while (x<m_size.x && (*sl)!=0) 71 { 72 size++; 73 x++; 74 sl++; 75 } 76 } 77 } 78 } 79 80 m_data=(uint8_t *)malloc(size); 81 int ww=im->Size().x,hh=im->Size().y; 82 datap=m_data; 83 if (!datap) 84 { printf("size = %d %d (%d)\n",im->Size().x,im->Size().y,size); } 85 CONDITION(datap,"malloc error for trans_image::m_data"); 86 87 for (y=0; y<hh; y++) // now actually make the runs 88 { 89 sl=im->scan_line(y); 90 x=0; 91 while (x<ww) 92 { 93 *datap=0; // start the skip at 0 94 while (x<im->Size().x && (*sl)==0) 95 { sl++; x++; (*datap)++; } 96 datap++; 97 98 if (x<ww) 99 { 100 marker=datap; // let marker be the run size 101 *marker=0; 102 datap++; // skip over this spot 103 while (x<im->Size().x && (*sl)!=0) 104 { 105 (*marker)++; 106 (*datap)=*sl; 107 datap++; 108 x++; 109 sl++; 110 } 111 } 112 } 113 } 114 im->Unlock(); 19 m_size = im->Size(); 20 21 im->Lock(); 22 23 // First find out how much data to allocate 24 size_t bytes = 0; 25 for (int y = 0; y < m_size.y; y++) 26 { 27 uint8_t *parser = im->scan_line(y); 28 for (int x = 0; x < m_size.x; ) 29 { 30 bytes++; 31 while (x < m_size.x && *parser == 0) 32 { 33 parser++; x++; 34 } 35 36 if (x >= m_size.x) 37 break; 38 39 bytes++; // byte for the size of the run 40 while (x < m_size.x && *parser != 0) 41 { 42 bytes++; 43 x++; 44 parser++; 45 } 46 } 47 } 48 49 uint8_t *parser = m_data = (uint8_t *)malloc(bytes); 50 if (!parser) 51 { 52 printf("size = %d %d (%d bytes)\n",im->Size().x,im->Size().y,bytes); 53 CONDITION(parser, "malloc error for trans_image::m_data"); 54 } 55 56 // Now fill the RLE transparency image 57 for (int y = 0; y < m_size.y; y++) 58 { 59 uint8_t *sl = im->scan_line(y); 60 61 for (int x = 0; x < m_size.x; ) 62 { 63 uint8_t len = 0; 64 while (x + len < m_size.x && sl[len] == 0) 65 len++; 66 67 *parser++ = len; 68 x += len; 69 sl += len; 70 71 if (x >= m_size.x) 72 break; 73 74 len = 0; 75 while (x + len < m_size.x && sl[len] != 0) 76 { 77 parser[len + 1] = sl[len]; 78 len++; 79 } 80 81 *parser++ = len; 82 parser += len; 83 x += len; 84 sl += len; 85 } 86 } 87 im->Unlock(); 115 88 } 116 89 … … 118 91 { 119 92 free(m_data); 93 } 94 95 image *trans_image::ToImage() 96 { 97 image *im = new image(m_size); 98 99 // FIXME: this is required until FILLED mode is fixed 100 im->Lock(); 101 memset(im->scan_line(0), 0, m_size.x * m_size.y); 102 im->Unlock(); 103 104 PutImage(im, 0, 0); 105 return im; 120 106 } 121 107 … … 273 259 screen->Lock(); 274 260 275 screen_line = screen->scan_line(y) +x;261 screen_line = screen->scan_line(y) + x; 276 262 int sw = screen->Size().x; 277 263 x1 -= x; x2 -= x; … … 421 407 { 422 408 uint8_t *d = m_data; 423 size_t t = 0;409 size_t ret = 0; 424 410 425 411 for (int y = 0; y < m_size.y; y++) … … 427 413 for (int x = 0; x < m_size.x; x++) 428 414 { 429 x += *d ; d++;t++;415 x += *d++; ret++; 430 416 431 417 if (x >= m_size.x) 432 418 break; 433 419 434 int s = *d; d++; t += s + 1; d += s; x += s;435 } 436 } 437 return t + 4 + 4;438 } 439 420 size_t run = *d++; ret += run + 1; d += run; x += run; 421 } 422 } 423 return ret + sizeof(void *) + sizeof(vec2i); 424 } 425
Note: See TracChangeset
for help on using the changeset viewer.