2010.07.17 23:46 "[Tiff] fromskew/toskew", by Sergius Bobrovsky

2010.07.20 18:04 "[Tiff] fromskew and toskew parameters", by Richard Nolde

On Sun, Jul 18, 2010 at 6:46 AM, Sergius Bobrovsky

<sergius.bobrovsky@gmail.com> wrote:

I'm trying to wrap my mind around "put routines" in tif_getimage.c and it looks like I can't understand what do fromskew and toskew params in DECLAREContigPutFunc mean.

Can someone explain me the meaning of this parameters?

If you look at tiffcp and/or tiffcrop, you will see similar definitions. The original author, Sam?, used a rather opaque syntax to provide function definitions for a variety of input/output modes rather than defining each one individually as I have chosen to do in tiffcrop. I believe that you will find the skew parameters are the buffer offsets between the start of successive read/write positions in a strip or tile. The strip or tile width is NOT the same, as there can be end of line padding to fill a byte or as required for certain compression schemes and tile layouts.

In tif_getimage.c look at the function. Note that from/to skew are only used in the case of flipping the image vertically. Since data are being read from the start of the line to the end of the line, you back up two scanlines after having done a read to get to the position where the next read will take place if you are reading from the bottom of the image back to the top of the image instead of in normal top to bottom order.

gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
{
...
        if (flip & FLIP_VERTICALLY) {
                 y = h - 1;
                 toskew = -(int32)(w + w);
         } else {
                 y = 0;
                 toskew = -(int32)(w - w);
         }

         TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
         TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING,
&subsamplinghor, &subsamplingver);
         scanline = TIFFNewScanlineSize(tif);
         fromskew = (w < imagewidth? imagewidth - w: 0);
         for (row = 0; row < h; row += nrow)
         {
                 rowstoread = rowsperstrip - (row + img->row_offset) %
rowsperstrip;
                 nrow = (row + rowstoread > h? h - row: rowstoread);
                 nrowsub = nrow;
                 if ((nrowsub%subsamplingver)!=0)
                         nrowsub+=subsamplingver-nrowsub%subsamplingver;
                 if (TIFFReadEncodedStrip(tif,
                     TIFFComputeStrip(tif,row+img->row_offset, 0),
                     buf,

                     ((row + img->row_offset)%rowsperstrip + nrowsub) * 

scanline) < 0
&& img->stoponerr)
                 {
                         ret = 0;
                         break;
                 }

                 pos = ((row + img->row_offset) % rowsperstrip) * scanline;
                 (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, 

toskew, buf + pos);
                 y += (flip & FLIP_VERTICALLY? -(int32) nrow: (int32)
nrow);
         }

Richard Nolde