AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2020.02.09 12:14 "[Tiff] Writing image as strips", by David C. Partridge
2020.02.09 15:13 "Re: [Tiff] Writing image as strips", by David C. Partridge
2020.02.09 16:52 "Re: [Tiff] Writing image as strips", by David C. Partridge
2020.02.09 17:51 "Re: [Tiff] Writing image as strips", by Bob Friesenhahn
2020.02.09 18:42 "Re: [Tiff] Writing image as strips", by David C. Partridge
2020.02.09 18:54 "Re: [Tiff] Writing image as strips", by Bob Friesenhahn

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;
                        }