2020.02.09 12:14 "[Tiff] Writing image as strips", by David C. Partridge

2020.02.09 12:14 "[Tiff] Writing image as strips", by David C. Partridge

Existing code writes image scan line by scan line.

I'd like to change to write strips.

Is the following OK?

                        //
                        // Write the image out as Strips (i.e. not scanline by scanline)
                        // 
                        const size_t STRIP_SIZE_DEFAULT = 262144UL; // 256kB

                        //
                        // Work out how many scanlines fit into 256K
                        //
                        long rowsPerStrip = STRIP_SIZE_DEFAULT / szScanLineSize;
                        TFFSetField(TIFFTAG_ROWSPERSTRIP, rowsPerStrip);

                        //
                        // From that we derive the number of strips
                        //
                        long numStrips = h / rowsPerStrip;
                        //
                        // If it wasn't an exact division (IOW there's a remainder), add one
                        // for the final (short) strip.
                        //
                        if (0 != h % rowsPerStrip)
                                ++numStrips;

                        BYTE * curr = (BYTE *)buff;
                        tsize_t stripSize = rowsPerStrip * szScanLineSize;
                        tsize_t bytesRemaining = h * szScanLineSize;
                        tsize_t size =  stripSize;
                        for (long strip = 0, strip < numStrips, strip++)
                        {
                                if (bytesRemaining < stripSize)
                                        size = bytesRemaining;

                                tsize_t result = TIFFWriteEncodedStrip(m_tiff, strip, curr, size);
                                if (-1 == result)
                                {
         ZTRACE_RUNTIME("TIFFWriteEncodeStrip() failed");
                                        bError = true;
                                        break;
                                }
                                curr += result;
                                bytesRemaining -= result;
                        }