// Save this (preloaded) marker to disk. int JpegMarker::Save(FILE *pFile) { const int location = ftell(pFile); if (pFile == NULL) throw("Null File in JpegMarker::Save."); unsigned short markerswapped = byteswap2(marker_); int rv = fwrite(&markerswapped, sizeof(unsigned short), 1, pFile); if (rv != 1) return 0; unsigned short slice_or_length = length_; if (marker_ == Jpeg::jpeg_sos) slice_or_length = slice_; ByteSwapInPlace(&slice_or_length, 1); rv = fwrite(&slice_or_length, sizeof(unsigned short), 1, pFile); if (rv != 1) return 0; if (marker_ == Jpeg::jpeg_sos) { WriteWithStuffBytes(pFile); // Add the EOI unsigned char eoi0 = 0xff; unsigned char eoi1 = 0xd9; fwrite(&eoi0, sizeof(eoi0), 1, pFile); fwrite(&eoi1, sizeof(eoi1), 1, pFile); } else { rv = fwrite(&data_[0], sizeof(char), data_.size(), pFile); if (rv != data_.size()) return 0; } if (debug > 0) printf("Saved marker %04x length %u at %d\n", marker_, length_, location); return 1; }
TiffIfd::TiffIfd(FILE *pFile, unsigned int ifdoffset, bool loadall, unsigned int subfileoffset, bool byte_swapping) : data_(NULL), subfileoffset_(subfileoffset), byte_swapping_(byte_swapping) { if (pFile == NULL) return; int iRV= fseek(pFile, ifdoffset, SEEK_SET); if (iRV != 0) { printf("Failed seek"); fclose(pFile); return; } short nr; iRV = fread(&nr, sizeof(short), 1, pFile); if (iRV != 1) return; if (byte_swapping) ByteSwapInPlace(&nr, 1); printf("IFDSize: %d \n", nr); for(int tagindex=0 ; tagindex < nr; ++tagindex) { int pos = ftell(pFile); // printf("File pointer %d\n", pos); TiffTag *tag = new TiffTag(pFile, byte_swapping_); tags_.push_back(tag); } printf("\n DIDIFD\n"); iRV = fread(&nextifdoffset_, sizeof(unsigned int), 1, pFile); if (iRV != 1) { throw("Couldn't read nextifdoffset"); } if (byte_swapping) ByteSwapInPlace(&nextifdoffset_, 1); // This disrupts the file pointer. LoadImageData(pFile, loadall); printf("Loaded Image data\n"); if (loadall) LoadAll(pFile); printf("Listing tags\n"); ListTags(); }