Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. void PNG_file::decode(const char *outputFileName) {
  2.     //BEGIN DECODING HERE
  3.  
  4.     FILE * outputFile;
  5.  
  6.     unsigned char buffer = 0;
  7.  
  8.     outputFile = fopen (outputFileName,"wb");
  9.  
  10.     //Check if the file opened
  11.     if(!outputFile)
  12.         exit(1);
  13.  
  14.     unsigned int size = 0;
  15.  
  16.     //
  17.     for(int y=0; y < read_ptr->height; y++) {
  18.         int x=0;
  19.         //Write the file size into the file y==0 ensures that it only happens
  20.         //once
  21.         if(y == 0)
  22.             for(x; x < SIZE_WIDTH; x++) {
  23.                 size |= ((*(row_pointers[0]+x) & 1 ) << x);
  24.             }
  25.         for(x; x < read_ptr->width*3; x++) {
  26.             if((x > SIZE_WIDTH || y > 0) && x%BYTE_SIZE == 0) {
  27.                 fwrite(&buffer, 1, 1, outputFile);
  28.                 buffer = 0;
  29.             }
  30.             //png_bytep here = row_pointers[y]+x; for debugging
  31.             if(((read_ptr->width*y)*3+x) == size*BYTE_SIZE+SIZE_WIDTH)
  32.                 goto loop_end;
  33.             buffer |= ((*(row_pointers[y]+x) & 1) << x%BYTE_SIZE);
  34.         }
  35.     }
  36.  
  37.     //goto jumps here to break out of multiple loops
  38.     loop_end:
  39.  
  40.     fclose(outputFile);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement