diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/TiffWriter.cpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/TiffWriter.cpp index bf1d15a85f..c1669c3db6 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/TiffWriter.cpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/TiffWriter.cpp @@ -56,27 +56,29 @@ std::pair TiffWriter::WriteImage(const std::string& filepa // Generate the offset into the Image File Directory (ifd) which we are going to write first constexpr uint32_t ifdOffset = 8; outputFile.write(reinterpret_cast(&ifdOffset), sizeof(ifdOffset)); - + const int k_NumTags = 12; std::vector tags; - tags.push_back(TIFTAG{0x00FE, 0x0004, 1, 0x00000000}); // NewSubfileType - tags.push_back(TIFTAG{0x0100, 0x0004, 1, width}); // ImageWidth - tags.push_back(TIFTAG{0x0101, 0x0004, 1, height}); // ImageLength - tags.push_back(TIFTAG{0x0102, 0x0003, 1, 8 * sizeof(char)}); // BitsPerSample - tags.push_back(TIFTAG{0x0103, 0x0003, 1, 0x0001}); // Compression - tags.push_back(TIFTAG{0x0106, 0x0003, 1, photometricInterpretation}); // PhotometricInterpretation // For SamplesPerPixel = 3 or 4 (RGB or RGBA) + tags.push_back(TIFTAG{0x00FE, 0x0004, 1, 0x00000000}); // NewSubfileType + tags.push_back(TIFTAG{0x0100, 0x0004, 1, width}); // ImageWidth + tags.push_back(TIFTAG{0x0101, 0x0004, 1, height}); // ImageLength + tags.push_back(TIFTAG{0x0102, 0x0003, 1, 8 * sizeof(char)}); // BitsPerSample + tags.push_back(TIFTAG{0x0103, 0x0003, 1, 0x0001}); // Compression + tags.push_back(TIFTAG{0x0106, 0x0003, 1, photometricInterpretation}); // PhotometricInterpretation // For SamplesPerPixel = 3 or 4 (RGB or RGBA) + // Now compute the offset to the image data so that we can put that into the tag. + // The math on this ONLY Works if we have 11 total Tags. + // IF YOU ADD MORE TAGS, YOU NEED TO ADJUST THE NEXT LINE OF CODE + int32_t imageDataOffset = static_cast(8 + (k_NumTags * 12) + 6); // Header + tags + IDF Tag entry count and Next IFD Offset + tags.push_back(TIFTAG{0x0111, 0x0004, 1, imageDataOffset}); // StripOffsets + tags.push_back(TIFTAG{0x0112, 0x0003, 1, 1}); // Orientation tags.push_back(TIFTAG{0x0115, 0x0003, 1, samplesPerPixel}); // SamplesPerPixel tags.push_back(TIFTAG{0x0116, 0x0004, 1, height}); // RowsPerStrip tags.push_back(TIFTAG{0x0117, 0x0004, 1, width * height * samplesPerPixel}); // StripByteCounts + // TIFTAG XResolution; // TIFTAG YResolution; // TIFTAG ResolutionUnit; - tags.push_back(TIFTAG{0x011c, 0x0003, 1, 0x0001}); // PlanarConfiguration - - // Now compute the offset to the image data so that we can put that into the tag. - // THESE NEXT 2 LINES MUST BE THE LAST TAG TO BE PUSHED BACK INTO THE VECTOR OR THE MATH WILL BE WRONG - const int32_t imageDataOffset = static_cast(8 + ((tags.size() + 1) * 12) + 6); // Header + tags + IDF Tag entry count and Next IFD Offset - tags.push_back(TIFTAG{0x0111, 0x0004, 1, imageDataOffset}); // StripOffsets + tags.push_back(TIFTAG{0x011c, 0x0003, 1, 0x0001}); // PlanarConfiguration // 284 // Write the number of tags to the IFD section uint16_t numEntries = static_cast(tags.size());