Ignore:
Timestamp:
Mar 18, 2008, 9:36:56 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Get rid of ugly tabs and trailing spaces everywhere.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/decoder.cpp

    r112 r124  
    121121      {
    122122      if (navail_bytes <= 0)
    123         {
    124 
    125         /* Out of bytes in current block, so read next block
    126           */
    127         pbytes = byte_buff;
    128         if ((navail_bytes = get_byte()) < 0)
    129             return(navail_bytes);
    130         else if (navail_bytes)
    131             {
    132             for (i = 0; i < navail_bytes; ++i)
    133                {
    134                if ((x = get_byte()) < 0)
    135                   return(x);
    136                byte_buff[i] = x;
    137                }
    138             }
    139         }
     123    {
     124
     125    /* Out of bytes in current block, so read next block
     126      */
     127    pbytes = byte_buff;
     128    if ((navail_bytes = get_byte()) < 0)
     129        return(navail_bytes);
     130    else if (navail_bytes)
     131        {
     132        for (i = 0; i < navail_bytes; ++i)
     133           {
     134           if ((x = get_byte()) < 0)
     135          return(x);
     136           byte_buff[i] = x;
     137           }
     138        }
     139    }
    140140      b1 = *pbytes++;
    141141      nbits_left = 8;
     
    147147      {
    148148      if (navail_bytes <= 0)
    149         {
    150 
    151         /* Out of bytes in current block, so read next block
    152           */
    153         pbytes = byte_buff;
    154         if ((navail_bytes = get_byte()) < 0)
    155             return(navail_bytes);
    156         else if (navail_bytes)
    157             {
    158             for (i = 0; i < navail_bytes; ++i)
    159                {
    160                if ((x = get_byte()) < 0)
    161                   return(x);
    162                byte_buff[i] = x;
    163                }
    164             }
    165         }
     149    {
     150
     151    /* Out of bytes in current block, so read next block
     152      */
     153    pbytes = byte_buff;
     154    if ((navail_bytes = get_byte()) < 0)
     155        return(navail_bytes);
     156    else if (navail_bytes)
     157        {
     158        for (i = 0; i < navail_bytes; ++i)
     159           {
     160           if ((x = get_byte()) < 0)
     161          return(x);
     162           byte_buff[i] = x;
     163           }
     164        }
     165    }
    166166      b1 = *pbytes++;
    167167      ret |= b1 << nbits_left;
     
    252252       */
    253253      if (c < 0)
    254         {
    255 //      free(buf);
    256         return(0);
    257         }
     254    {
     255//    free(buf);
     256    return(0);
     257    }
    258258
    259259      /* If the code is a clear code, reinitialize all necessary items.
    260260       */
    261261      if (c == clear)
    262         {
    263         curr_size = size + 1;
    264         slot = newcodes;
    265         top_slot = 1 << curr_size;
    266 
    267         /* Continue reading codes until we get a non-clear code
    268           * (Another unlikely, but possible case...)
    269           */
    270         while ((c = get_next_code()) == clear)
    271             ;
    272 
    273         /* If we get an ending code immediately after a clear code
    274           * (Yet another unlikely case), then break out of the loop.
    275           */
    276         if (c == ending)
    277             break;
    278 
    279         /* Finally, if the code is beyond the range of already set codes,
    280           * (This one had better NOT happen...  I have no idea what will
    281           * result from this, but I doubt it will look good...) then set it
    282           * to color zero.
    283           */
    284         CONDITION(c<slot,"Error occurred while reading gif");
    285         if (c >= slot)
    286             c = 0;
    287 
    288         oc = fc = c;
    289 
    290         /* And let us not forget to put the char into the buffer... And
    291           * if, on the off chance, we were exactly one pixel from the end
    292           * of the line, we have to send the buffer to the out_line()
    293           * routine...
    294           */
    295         *bufptr++ = c;
    296         if (--bufcnt == 0)
    297             {
    298 
    299 //          if ((ret = out_line(buf, linewidth)) < 0)
    300 //             {
    301 //             free(buf);
    302 //             return(ret);
    303 //             }
    304             y++;
    305             if (y<im->height())
    306               buf=im->scan_line(y);
    307             bufptr = buf;
    308             bufcnt = im->width()-1;
    309             }
    310         }
     262    {
     263    curr_size = size + 1;
     264    slot = newcodes;
     265    top_slot = 1 << curr_size;
     266
     267    /* Continue reading codes until we get a non-clear code
     268      * (Another unlikely, but possible case...)
     269      */
     270    while ((c = get_next_code()) == clear)
     271        ;
     272
     273    /* If we get an ending code immediately after a clear code
     274      * (Yet another unlikely case), then break out of the loop.
     275      */
     276    if (c == ending)
     277        break;
     278
     279    /* Finally, if the code is beyond the range of already set codes,
     280      * (This one had better NOT happen...  I have no idea what will
     281      * result from this, but I doubt it will look good...) then set it
     282      * to color zero.
     283      */
     284    CONDITION(c<slot,"Error occurred while reading gif");
     285    if (c >= slot)
     286        c = 0;
     287
     288    oc = fc = c;
     289
     290    /* And let us not forget to put the char into the buffer... And
     291      * if, on the off chance, we were exactly one pixel from the end
     292      * of the line, we have to send the buffer to the out_line()
     293      * routine...
     294      */
     295    *bufptr++ = c;
     296    if (--bufcnt == 0)
     297        {
     298
     299//        if ((ret = out_line(buf, linewidth)) < 0)
     300//           {
     301//           free(buf);
     302//           return(ret);
     303//           }
     304        y++;
     305        if (y<im->height())
     306          buf=im->scan_line(y);
     307        bufptr = buf;
     308        bufcnt = im->width()-1;
     309        }
     310    }
    311311      else
    312         {
    313 
    314         /* In this case, it's not a clear code or an ending code, so
    315           * it must be a code code...  So we can now decode the code into
    316           * a stack of character codes. (Clear as mud, right?)
    317           */
    318         code = c;
    319 
    320         /* Here we go again with one of those off chances...  If, on the
    321           * off chance, the code we got is beyond the range of those already
    322           * set up (Another thing which had better NOT happen...) we trick
    323           * the decoder into thinking it actually got the last code read.
    324           * (Hmmn... I'm not sure why this works...  But it does...)
    325           */
    326 
    327         if (code >= slot)
    328             {
    329             if (code > slot)
    330                ++bad_code_count;
    331             code = oc;
    332             *sp++ = fc;
    333             }
    334 
    335         /* Here we scan back along the linked list of prefixes, pushing
    336           * helpless characters (ie. suffixes) onto the stack as we do so.
    337           */
    338         while (code >= newcodes)
    339             {
    340             *sp++ = suffix[code];
    341             code = prefix[code];
    342             }
    343 
    344         /* Push the last character on the stack, and set up the new
    345           * prefix and suffix, and if the required slot number is greater
    346           * than that allowed by the current bit size, increase the bit
    347           * size.  (NOTE - If we are all full, we *don't* save the new
    348           * suffix and prefix...  I'm not certain if this is correct...
    349           * it might be more proper to overwrite the last code...
    350           */
    351         *sp++ = code;
    352         if (slot < top_slot)
    353             {
    354             suffix[slot] = fc = code;
    355             prefix[slot++] = oc;
    356             oc = c;
    357             }
    358         if (slot >= top_slot)
    359             if (curr_size < 12)
    360                {
    361                top_slot <<= 1;
    362                ++curr_size;
    363                }
    364 
    365         /* Now that we've pushed the decoded string (in reverse order)
    366           * onto the stack, lets pop it off and put it into our decode
    367           * buffer...  And when the decode buffer is full, write another
    368           * line...
    369           */
    370         while (sp > stack)
    371             {
    372             *bufptr++ = *(--sp);
    373             if (--bufcnt == 0)
    374                {
    375 /*             if ((ret = out_line(buf, linewidth)) < 0)
    376                   {
    377                   free(buf);
    378                   return(ret);
    379                   } */
    380                y++;
    381                if (y<im->height())
    382                 buf=im->scan_line(y);
    383 
    384                bufptr = buf;
    385                bufcnt = im->width()-1;
    386                }
    387             }
    388         }
     312    {
     313
     314    /* In this case, it's not a clear code or an ending code, so
     315      * it must be a code code...  So we can now decode the code into
     316      * a stack of character codes. (Clear as mud, right?)
     317      */
     318    code = c;
     319
     320    /* Here we go again with one of those off chances...  If, on the
     321      * off chance, the code we got is beyond the range of those already
     322      * set up (Another thing which had better NOT happen...) we trick
     323      * the decoder into thinking it actually got the last code read.
     324      * (Hmmn... I'm not sure why this works...  But it does...)
     325      */
     326
     327    if (code >= slot)
     328        {
     329        if (code > slot)
     330           ++bad_code_count;
     331        code = oc;
     332        *sp++ = fc;
     333        }
     334
     335    /* Here we scan back along the linked list of prefixes, pushing
     336      * helpless characters (ie. suffixes) onto the stack as we do so.
     337      */
     338    while (code >= newcodes)
     339        {
     340        *sp++ = suffix[code];
     341        code = prefix[code];
     342        }
     343
     344    /* Push the last character on the stack, and set up the new
     345      * prefix and suffix, and if the required slot number is greater
     346      * than that allowed by the current bit size, increase the bit
     347      * size.  (NOTE - If we are all full, we *don't* save the new
     348      * suffix and prefix...  I'm not certain if this is correct...
     349      * it might be more proper to overwrite the last code...
     350      */
     351    *sp++ = code;
     352    if (slot < top_slot)
     353        {
     354        suffix[slot] = fc = code;
     355        prefix[slot++] = oc;
     356        oc = c;
     357        }
     358    if (slot >= top_slot)
     359        if (curr_size < 12)
     360           {
     361           top_slot <<= 1;
     362           ++curr_size;
     363           }
     364
     365    /* Now that we've pushed the decoded string (in reverse order)
     366      * onto the stack, lets pop it off and put it into our decode
     367      * buffer...  And when the decode buffer is full, write another
     368      * line...
     369      */
     370    while (sp > stack)
     371        {
     372        *bufptr++ = *(--sp);
     373        if (--bufcnt == 0)
     374           {
     375/*           if ((ret = out_line(buf, linewidth)) < 0)
     376          {
     377          free(buf);
     378          return(ret);
     379          } */
     380           y++;
     381           if (y<im->height())
     382        buf=im->scan_line(y);
     383
     384           bufptr = buf;
     385           bufcnt = im->width()-1;
     386           }
     387        }
     388    }
    389389      }
    390390   ret = 0;
Note: See TracChangeset for help on using the changeset viewer.