Skip to content

picopng update + runtime error fix #2

Description

@alur

LiteStep is currently using a version of picopng dated 20080503. The latest version is dated 20101224. LiteStep should probably be updated to use the latest version.

On a very related note, the unFilterScanline function in picopng will throw a lot of runtime exceptions when trying to debug LiteStep.

This can be fixed by modifying all lines of the form
recon[i] = x + y;
into
recon[i] = (x + y) & 0xFF;

There are 8 lines which should be modified in the unFilterScanline function.

Here is a modified version of unFilterScanline:

void unFilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned long filterType, size_t length)
    {
      switch(filterType)
      {
        case 0: for(size_t i = 0; i < length; i++) recon[i] = scanline[i]; break;
        case 1:
          for(size_t i =         0; i < bytewidth; i++) recon[i] = scanline[i];
          for(size_t i = bytewidth; i <    length; i++) recon[i] = (scanline[i] + recon[i - bytewidth]) & 0xFF;
          break;
        case 2:
          if(precon) for(size_t i = 0; i < length; i++) recon[i] = (scanline[i] + precon[i]) & 0xFF;
          else       for(size_t i = 0; i < length; i++) recon[i] = scanline[i];
          break;
        case 3:
          if(precon)
          {
            for(size_t i =         0; i < bytewidth; i++) recon[i] = (scanline[i] + precon[i] / 2) & 0xFF;
            for(size_t i = bytewidth; i <    length; i++) recon[i] = (scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2)) & 0xFF;
          }
          else
          {
            for(size_t i =         0; i < bytewidth; i++) recon[i] = scanline[i];
            for(size_t i = bytewidth; i <    length; i++) recon[i] = (scanline[i] + recon[i - bytewidth] / 2) & 0xFF;
          }
          break;
        case 4:
          if(precon)
          {
            for(size_t i =         0; i < bytewidth; i++) recon[i] = (scanline[i] + paethPredictor(0, precon[i], 0)) & 0xFF;
            for(size_t i = bytewidth; i <    length; i++) recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth])) & 0xFF;
          }
          else
          {
            for(size_t i =         0; i < bytewidth; i++) recon[i] = scanline[i];
            for(size_t i = bytewidth; i <    length; i++) recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], 0, 0)) & 0xFF;
          }
          break;
        default: error = 36; return; //error: unexisting filter type given
      }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions