Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PNG_file::decode(const char *outputFileName) {
- //BEGIN DECODING HERE
- FILE * outputFile;
- unsigned char buffer = 0;
- outputFile = fopen (outputFileName,"wb");
- //Check if the file opened
- if(!outputFile)
- exit(1);
- unsigned int size = 0;
- //
- for(int y=0; y < read_ptr->height; y++) {
- int x=0;
- //Write the file size into the file y==0 ensures that it only happens
- //once
- if(y == 0)
- for(x; x < SIZE_WIDTH; x++) {
- size |= ((*(row_pointers[0]+x) & 1 ) << x);
- }
- for(x; x < read_ptr->width*3; x++) {
- if((x > SIZE_WIDTH || y > 0) && x%BYTE_SIZE == 0) {
- fwrite(&buffer, 1, 1, outputFile);
- buffer = 0;
- }
- //png_bytep here = row_pointers[y]+x; for debugging
- if(((read_ptr->width*y)*3+x) == size*BYTE_SIZE+SIZE_WIDTH)
- goto loop_end;
- buffer |= ((*(row_pointers[y]+x) & 1) << x%BYTE_SIZE);
- }
- }
- //goto jumps here to break out of multiple loops
- loop_end:
- fclose(outputFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement