]> git.saurik.com Git - wxWidgets.git/commitdiff
upgraded libtiff to 3.6.1 + security fixes (patch from Tim Kosse)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Nov 2004 22:29:47 +0000 (22:29 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Nov 2004 22:29:47 +0000 (22:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30659 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

45 files changed:
build/bakefiles/tiff.bkl
src/tiff/VERSION
src/tiff/makefile.vc
src/tiff/tif_apple.c
src/tiff/tif_aux.c
src/tiff/tif_close.c
src/tiff/tif_codec.c
src/tiff/tif_compress.c
src/tiff/tif_dir.c
src/tiff/tif_dir.h
src/tiff/tif_dirinfo.c
src/tiff/tif_dirread.c
src/tiff/tif_dirwrite.c
src/tiff/tif_dumpmode.c
src/tiff/tif_fax3.c
src/tiff/tif_fax3.h
src/tiff/tif_fax3sm.c
src/tiff/tif_flush.c
src/tiff/tif_getimage.c
src/tiff/tif_jpeg.c
src/tiff/tif_luv.c
src/tiff/tif_lzw.c
src/tiff/tif_next.c
src/tiff/tif_open.c
src/tiff/tif_packbits.c
src/tiff/tif_pixarlog.c
src/tiff/tif_predict.c
src/tiff/tif_print.c
src/tiff/tif_read.c
src/tiff/tif_strip.c
src/tiff/tif_swab.c
src/tiff/tif_thunder.c
src/tiff/tif_tile.c
src/tiff/tif_unix.c
src/tiff/tif_version.c
src/tiff/tif_win32.c
src/tiff/tif_write.c
src/tiff/tif_zip.c
src/tiff/tiff.dsp
src/tiff/tiff.h
src/tiff/tiffcomp.h
src/tiff/tiffconf.h
src/tiff/tiffio.h
src/tiff/tiffiop.h
src/tiff/uvcode.h

index 8ce3c3a3fdcb2b8292b3987672b7d95199cc397e..f2198e2f5ff600e363090655981bff8ed528b087 100644 (file)
@@ -45,6 +45,7 @@
                    src/tiff/tif_aux.c
                    src/tiff/tif_close.c
                    src/tiff/tif_codec.c
                    src/tiff/tif_aux.c
                    src/tiff/tif_close.c
                    src/tiff/tif_codec.c
+            src/tiff/tif_color.c
                    src/tiff/tif_compress.c
                    src/tiff/tif_dir.c
                    src/tiff/tif_dirinfo.c
                    src/tiff/tif_compress.c
                    src/tiff/tif_dir.c
                    src/tiff/tif_dirinfo.c
index 87ce492908ab2362771f27134bab4a075348a8f3..de4dc85aca96a228d642ce2dbf7fc4cc79d22731 100644 (file)
@@ -1 +1 @@
-3.5.2
+3.6.1-2
index deae39c8d107637c9636d8559217af6e9aaddee3..00ef34d0cbdb2b61694f73843046aff73c594c5f 100644 (file)
@@ -1,50 +1,93 @@
+#
+#      Simple MS VC++ Makefile
+#
+#      To build:
+#       C:\libtiff\libtiff> nmake /f makefile.vc all
+#
+
+# 
+# Select _CONSOLE to build a library which reports errors to stderr, or
+# _WINDOWED to build such that errors are reported via MessageBox().
+#
+WINMODE = -DTIF_PLATFORM_CONSOLE
+#WINMODE = -DTIF_PLATFORM_WINDOWED
+
+# Uncomment and edit following lines to enable JPEG support
+#JPEG_SUPPORT  = 1
+#JPEGDIR       = d:/projects/jpeg-6b
+
+CC             = cl
+INCL           = -I.
+LIBS           =
+EXTRAFLAGS     =
+
+!IFDEF JPEG_SUPPORT
+INCL           = $(INCL) -I$(JPEGDIR)
+EXTRAFLAGS     = $(EXTRAFLAGS) -DJPEG_SUPPORT
+!ENDIF
+
+CFLAGS  = /nologo /W3 $(INCL) $(WINMODE) $(EXTRAFLAGS)
+
+OBJ    = \
+       tif_aux.obj \
+       tif_close.obj \
+       tif_codec.obj \
+       tif_color.obj \
+       tif_compress.obj \
+       tif_dir.obj \
+       tif_dirinfo.obj \
+       tif_dirread.obj \
+       tif_dirwrite.obj \
+       tif_dumpmode.obj \
+       tif_error.obj \
+       tif_extension.obj \
+       tif_fax3.obj \
+       fax3sm_winnt.obj \
+       tif_getimage.obj \
+       tif_jpeg.obj \
+       tif_ojpeg.obj \
+       tif_flush.obj \
+       tif_luv.obj \
+       tif_lzw.obj \
+       tif_next.obj \
+       tif_open.obj \
+       tif_packbits.obj \
+       tif_pixarlog.obj \
+       tif_predict.obj \
+       tif_print.obj \
+       tif_read.obj \
+       tif_swab.obj \
+       tif_strip.obj \
+       tif_thunder.obj \
+       tif_tile.obj \
+       tif_win32.obj \
+       tif_version.obj \
+       tif_warning.obj \
+       tif_write.obj \
+       tif_zip.obj
+
+VERSION        = ..\VERSION
+ALPHA = ..\dist\tiff.alpha
+
+default:       libtiff.lib
+
+all:   libtiff.lib libtiff.dll
+
+libtiff.lib:   tiffvers.h $(OBJ)
+       lib /out:libtiff.lib $(OBJ)
+
+libtiff.dll:   $(OBJ)
+       link /dll /def:libtiff.def /out:libtiff.dll /implib:libtiff_i.lib \
+               $(OBJ) $(LIBS)
+       
+tiffvers.h:    $(VERSION) mkversion.c
+       $(CC) mkversion.c 
+       if exist tiffvers.h del tiffvers.h
+       .\mkversion.exe -v $(VERSION) tiffvers.h
+
+clean:
+       del *.obj *.lib libtiff.dll
+
+tif_version.obj:       tiffvers.h
 
 
-!if "$(FINAL)" == "1"
-LIBTARGET=$(WXDIR)\lib\tiff.lib
-!else if "$(FINAL)" == "hybrid"
-LIBTARGET=$(WXDIR)\lib\tiffh.lib
-!else
-LIBTARGET=$(WXDIR)\lib\tiffd.lib
-!endif
-
-OBJECTS= \
-               $D\tif_aux.obj \
-               $D\tif_close.obj \
-               $D\tif_codec.obj \
-               $D\tif_compress.obj \
-               $D\tif_dir.obj \
-               $D\tif_dirinfo.obj \
-               $D\tif_dirread.obj \
-               $D\tif_dirwrite.obj \
-               $D\tif_dumpmode.obj \
-               $D\tif_error.obj \
-               $D\tif_fax3.obj \
-               $D\tif_fax3sm.obj \
-               $D\tif_flush.obj \
-               $D\tif_getimage.obj \
-               $D\tif_jpeg.obj \
-               $D\tif_luv.obj \
-               $D\tif_lzw.obj \
-               $D\tif_next.obj \
-               $D\tif_open.obj \
-               $D\tif_packbits.obj \
-               $D\tif_pixarlog.obj \
-               $D\tif_predict.obj \
-               $D\tif_print.obj \
-               $D\tif_read.obj \
-               $D\tif_strip.obj \
-               $D\tif_swab.obj \
-               $D\tif_thunder.obj \
-               $D\tif_tile.obj \
-               $D\tif_version.obj \
-               $D\tif_warning.obj \
-               $D\tif_win32.obj \
-               $D\tif_write.obj \
-               $D\tif_zip.obj \
-
-
-
-# Pull in standard variable definitions
-
-!include ..\makelib.vc
 
 
index d691eb2edb7f4dc2fe73facb3c1f30ab9bfc4d77..1442df3c57dd06c3660a05c7840864ff873b0d64 100644 (file)
  * Create below fills in a blank creator signature and sets the file type
  * to 'TIFF'.  It is much better for the application to do this by Create'ing
  * the file first and TIFFOpen'ing it later.
  * Create below fills in a blank creator signature and sets the file type
  * to 'TIFF'.  It is much better for the application to do this by Create'ing
  * the file first and TIFFOpen'ing it later.
+ * ---------
+ * This code has been "Carbonized", and may not work with older MacOS versions.
+ * If so, grab the tif_apple.c out of an older libtiff distribution, like
+ * 3.5.5 from www.libtiff.org.
  */
 
  */
 
-#ifdef __MACH__
-         #include <ansi_prefix.mach.h>
-         #include <msl_c_version.h>
-         #include <stdint.h>
-         #undef WCHAR_MAX
-         #include <machine/ansi.h>
-#endif
 #include "tiffiop.h"
 #include "tiffiop.h"
-#include <MacErrors.h>
+#include <Errors.h>
 #include <Files.h>
 #include <Memory.h>
 #include <Files.h>
 #include <Memory.h>
+#include <Script.h>
 
 
-#if defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__) || defined(applec)
+#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__) || defined(applec)
 #define        CtoPstr c2pstr
 #endif
 
 #define        CtoPstr c2pstr
 #endif
 
@@ -149,6 +147,13 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
        return (tif);
 }
 
        return (tif);
 }
 
+static void ourc2pstr( char* inString )
+{
+       int     sLen = strlen( inString );
+       BlockMoveData( inString, &inString[1], sLen );
+       inString[0] = sLen;
+}
+
 /*
  * Open a TIFF file for read/writing.
  */
 /*
  * Open a TIFF file for read/writing.
  */
@@ -160,32 +165,38 @@ TIFFOpen(const char* name, const char* mode)
        FInfo finfo;
        short fref;
        OSErr err;
        FInfo finfo;
        short fref;
        OSErr err;
+       FSSpec  fSpec;
 
        strcpy((char*) pname, name);
 
        strcpy((char*) pname, name);
-       CtoPstr((char*) pname);
+       ourc2pstr((char*) pname);
+       
+       err = FSMakeFSSpec( 0, 0, pname, &fSpec );
 
        switch (_TIFFgetMode(mode, module)) {
        default:
                return ((TIFF*) 0);
        case O_RDWR | O_CREAT | O_TRUNC:
 
        switch (_TIFFgetMode(mode, module)) {
        default:
                return ((TIFF*) 0);
        case O_RDWR | O_CREAT | O_TRUNC:
-               if (GetFInfo(pname, 0, &finfo) == noErr)
-                       FSDelete(pname, 0);
+               if (FSpGetFInfo(&fSpec, &finfo) == noErr)
+                       FSpDelete(&fSpec);
                /* fall through */
        case O_RDWR | O_CREAT:
                /* fall through */
        case O_RDWR | O_CREAT:
-               if ((err = GetFInfo(pname, 0, &finfo)) == fnfErr) {
-                       if (Create(pname, 0, '    ', 'TIFF') != noErr)
+               if ((err = FSpGetFInfo(&fSpec, &finfo)) == fnfErr) {
+                       if (FSpCreate(&fSpec, '    ', 'TIFF', smSystemScript) != noErr)
                                goto badCreate;
                                goto badCreate;
-                       if (FSOpen(pname, 0, &fref) != noErr)
+                       if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
                                goto badOpen;
                } else if (err == noErr) {
                                goto badOpen;
                } else if (err == noErr) {
-                       if (FSOpen(pname, 0, &fref) != noErr)
+                       if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
                                goto badOpen;
                } else
                        goto badOpen;
                break;
        case O_RDONLY:
                                goto badOpen;
                } else
                        goto badOpen;
                break;
        case O_RDONLY:
+               if (FSpOpenDF(&fSpec, fsRdPerm, &fref) != noErr)
+                       goto badOpen;
+               break;
        case O_RDWR:
        case O_RDWR:
-               if (FSOpen(pname, 0, &fref) != noErr)
+               if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr)
                        goto badOpen;
                break;
        }
                        goto badOpen;
                break;
        }
index 6e8796684d64157ac1aac29a1bb02eb206fd7a9d..e3f6e39a55653771020f2a9d39d41bf1642bb294 100644 (file)
  * Auxiliary Support Routines.
  */
 #include "tiffiop.h"
  * Auxiliary Support Routines.
  */
 #include "tiffiop.h"
-
-#ifdef COLORIMETRY_SUPPORT
+#include "tif_predict.h"
 #include <math.h>
 
 #include <math.h>
 
-static void
+static int
 TIFFDefaultTransferFunction(TIFFDirectory* td)
 {
        uint16 **tf = td->td_transferfunction;
 TIFFDefaultTransferFunction(TIFFDirectory* td)
 {
        uint16 **tf = td->td_transferfunction;
-       long i, n = 1<<td->td_bitspersample;
+       tsize_t i, n, nbytes;
+
+       tf[0] = tf[1] = tf[2] = 0;
+       if (td->td_bitspersample >= sizeof(tsize_t) * 8 - 2)
+               return 0;
 
 
-       tf[0] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
+       n = 1<<td->td_bitspersample;
+       nbytes = n * sizeof (uint16);
+       if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes)))
+               return 0;
        tf[0][0] = 0;
        for (i = 1; i < n; i++) {
                double t = (double)i/((double) n-1.);
                tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5);
        }
        tf[0][0] = 0;
        for (i = 1; i < n; i++) {
                double t = (double)i/((double) n-1.);
                tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5);
        }
+
        if (td->td_samplesperpixel - td->td_extrasamples > 1) {
        if (td->td_samplesperpixel - td->td_extrasamples > 1) {
-               tf[1] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
-               _TIFFmemcpy(tf[1], tf[0], n * sizeof (uint16));
-               tf[2] = (uint16 *)_TIFFmalloc(n * sizeof (uint16));
-               _TIFFmemcpy(tf[2], tf[0], n * sizeof (uint16));
+               if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes)))
+                       goto bad;
+               _TIFFmemcpy(tf[1], tf[0], nbytes);
+               if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes)))
+                       goto bad;
+               _TIFFmemcpy(tf[2], tf[0], nbytes);
        }
        }
+       return 1;
+
+bad:
+       if (tf[0])
+               _TIFFfree(tf[0]);
+       if (tf[1])
+               _TIFFfree(tf[1]);
+       if (tf[2])
+               _TIFFfree(tf[2]);
+       tf[0] = tf[1] = tf[2] = 0;
+       return 0;
 }
 
 }
 
-static void
+static int
 TIFFDefaultRefBlackWhite(TIFFDirectory* td)
 {
        int i;
 
 TIFFDefaultRefBlackWhite(TIFFDirectory* td)
 {
        int i;
 
-       td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
+       if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float))))
+               return 0;
        for (i = 0; i < 3; i++) {
            td->td_refblackwhite[2*i+0] = 0;
            td->td_refblackwhite[2*i+1] = (float)((1L<<td->td_bitspersample)-1L);
        }
        for (i = 0; i < 3; i++) {
            td->td_refblackwhite[2*i+0] = 0;
            td->td_refblackwhite[2*i+1] = (float)((1L<<td->td_bitspersample)-1L);
        }
+       return 1;
 }
 }
-#endif
 
 /*
  * Like TIFFGetField, but return any default
 
 /*
  * Like TIFFGetField, but return any default
@@ -116,7 +137,12 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_RESOLUTIONUNIT:
                *va_arg(ap, uint16 *) = td->td_resolutionunit;
                return (1);
        case TIFFTAG_RESOLUTIONUNIT:
                *va_arg(ap, uint16 *) = td->td_resolutionunit;
                return (1);
-#ifdef CMYK_SUPPORT
+       case TIFFTAG_PREDICTOR:
+                {
+                       TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data;
+                       *va_arg(ap, uint16*) = (uint16) sp->predictor;
+                       return (1);
+                }
        case TIFFTAG_DOTRANGE:
                *va_arg(ap, uint16 *) = 0;
                *va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
        case TIFFTAG_DOTRANGE:
                *va_arg(ap, uint16 *) = 0;
                *va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;
@@ -127,7 +153,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_NUMBEROFINKS:
                *va_arg(ap, uint16 *) = td->td_ninks;
                return (1);
        case TIFFTAG_NUMBEROFINKS:
                *va_arg(ap, uint16 *) = td->td_ninks;
                return (1);
-#endif
        case TIFFTAG_EXTRASAMPLES:
                *va_arg(ap, uint16 *) = td->td_extrasamples;
                *va_arg(ap, uint16 **) = td->td_sampleinfo;
        case TIFFTAG_EXTRASAMPLES:
                *va_arg(ap, uint16 *) = td->td_extrasamples;
                *va_arg(ap, uint16 **) = td->td_sampleinfo;
@@ -143,14 +168,18 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_DATATYPE:
                *va_arg(ap, uint16 *) = td->td_sampleformat-1;
                return (1);
        case TIFFTAG_DATATYPE:
                *va_arg(ap, uint16 *) = td->td_sampleformat-1;
                return (1);
+       case TIFFTAG_SAMPLEFORMAT:
+               *va_arg(ap, uint16 *) = td->td_sampleformat;
+                return(1);
        case TIFFTAG_IMAGEDEPTH:
                *va_arg(ap, uint32 *) = td->td_imagedepth;
                return (1);
        case TIFFTAG_IMAGEDEPTH:
                *va_arg(ap, uint32 *) = td->td_imagedepth;
                return (1);
-#ifdef YCBCR_SUPPORT
        case TIFFTAG_YCBCRCOEFFICIENTS:
                if (!td->td_ycbcrcoeffs) {
                        td->td_ycbcrcoeffs = (float *)
                            _TIFFmalloc(3*sizeof (float));
        case TIFFTAG_YCBCRCOEFFICIENTS:
                if (!td->td_ycbcrcoeffs) {
                        td->td_ycbcrcoeffs = (float *)
                            _TIFFmalloc(3*sizeof (float));
+                       if (!td->td_ycbcrcoeffs)
+                               return (0);
                        /* defaults are from CCIR Recommendation 601-1 */
                        td->td_ycbcrcoeffs[0] = 0.299f;
                        td->td_ycbcrcoeffs[1] = 0.587f;
                        /* defaults are from CCIR Recommendation 601-1 */
                        td->td_ycbcrcoeffs[0] = 0.299f;
                        td->td_ycbcrcoeffs[1] = 0.587f;
@@ -165,11 +194,28 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_YCBCRPOSITIONING:
                *va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
                return (1);
        case TIFFTAG_YCBCRPOSITIONING:
                *va_arg(ap, uint16 *) = td->td_ycbcrpositioning;
                return (1);
-#endif
-#ifdef COLORIMETRY_SUPPORT
+       case TIFFTAG_WHITEPOINT:
+               if (!td->td_whitepoint) {
+                       td->td_whitepoint = (float *)
+                               _TIFFmalloc(2 * sizeof (float));
+                       if (!td->td_whitepoint)
+                               return (0);
+                       /* TIFF 6.0 specification says that it is no default
+                          value for the WhitePoint, but AdobePhotoshop TIFF
+                          Technical Note tells that it should be CIE D50. */
+                       td->td_whitepoint[0] =
+                               D50_X0 / (D50_X0 + D50_Y0 + D50_Z0);
+                       td->td_whitepoint[1] =
+                               D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0);
+               }
+               *va_arg(ap, float **) = td->td_whitepoint;
+               return (1);
        case TIFFTAG_TRANSFERFUNCTION:
        case TIFFTAG_TRANSFERFUNCTION:
-               if (!td->td_transferfunction[0])
-                       TIFFDefaultTransferFunction(td);
+               if (!td->td_transferfunction[0] &&
+                   !TIFFDefaultTransferFunction(td)) {
+                       TIFFError(tif->tif_name, "No space for \"TransferFunction\" tag");
+                       return (0);
+               }
                *va_arg(ap, uint16 **) = td->td_transferfunction[0];
                if (td->td_samplesperpixel - td->td_extrasamples > 1) {
                        *va_arg(ap, uint16 **) = td->td_transferfunction[1];
                *va_arg(ap, uint16 **) = td->td_transferfunction[0];
                if (td->td_samplesperpixel - td->td_extrasamples > 1) {
                        *va_arg(ap, uint16 **) = td->td_transferfunction[1];
@@ -177,11 +223,10 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap)
                }
                return (1);
        case TIFFTAG_REFERENCEBLACKWHITE:
                }
                return (1);
        case TIFFTAG_REFERENCEBLACKWHITE:
-               if (!td->td_refblackwhite)
-                       TIFFDefaultRefBlackWhite(td);
+               if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))
+                       return (0);
                *va_arg(ap, float **) = td->td_refblackwhite;
                return (1);
                *va_arg(ap, float **) = td->td_refblackwhite;
                return (1);
-#endif
        }
        return (0);
 }
        }
        return (0);
 }
index 3704a4bdd431ba34418d4560a49afd912f7c27f2..ab7c6281151d08781c4feee951c8fad40c16846e 100644 (file)
 void
 TIFFClose(TIFF* tif)
 {
 void
 TIFFClose(TIFF* tif)
 {
-       if (tif->tif_mode != O_RDONLY)
-               /*
-                * Flush buffered data and directory (if dirty).
-                */
-               TIFFFlush(tif);
-       (*tif->tif_cleanup)(tif);
-       TIFFFreeDirectory(tif);
-       if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
-               _TIFFfree(tif->tif_rawdata);
-       if (isMapped(tif))
-               TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
-       (void) TIFFCloseFile(tif);
-       if (tif->tif_fieldinfo)
-               _TIFFfree(tif->tif_fieldinfo);
-       _TIFFfree(tif);
+    if (tif->tif_mode != O_RDONLY)
+        /*
+         * Flush buffered data and directory (if dirty).
+         */
+        TIFFFlush(tif);
+    (*tif->tif_cleanup)(tif);
+    TIFFFreeDirectory(tif);
+
+    if (tif->tif_dirlist)
+        _TIFFfree(tif->tif_dirlist);
+        
+    /* Clean up client info links */
+    while( tif->tif_clientinfo )
+    {
+        TIFFClientInfoLink *link = tif->tif_clientinfo;
+
+        tif->tif_clientinfo = link->next;
+        _TIFFfree( link->name );
+        _TIFFfree( link );
+    }
+
+    if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
+        _TIFFfree(tif->tif_rawdata);
+    if (isMapped(tif))
+        TIFFUnmapFileContents(tif, tif->tif_base, tif->tif_size);
+    (void) TIFFCloseFile(tif);
+    if (tif->tif_nfields > 0) 
+    {
+        int  i;
+
+        for (i = 0; i < tif->tif_nfields; i++) 
+       {
+           TIFFFieldInfo *fld = tif->tif_fieldinfo[i];
+           if (fld->field_bit == FIELD_CUSTOM && 
+               strncmp("Tag ", fld->field_name, 4) == 0) 
+           {
+                _TIFFfree(fld->field_name);
+                _TIFFfree(fld);
+           }
+        }   
+      
+        _TIFFfree(tif->tif_fieldinfo);
+    }
+
+    _TIFFfree(tif);
 }
 }
index de205c76c189997cc744031b19914e508847cc13..cb9f6d7021e9c9834f8674ac65cb1163db3d756b 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -31,7 +31,7 @@
  */
 #include "tiffiop.h"
 
  */
 #include "tiffiop.h"
 
-static int LINKAGEMODE NotConfigured(TIFF*, int);
+static int NotConfigured(TIFF*, int);
 
 #ifndef        LZW_SUPPORT
 #define        TIFFInitLZW             NotConfigured
 
 #ifndef        LZW_SUPPORT
 #define        TIFFInitLZW             NotConfigured
@@ -91,6 +91,7 @@ TIFFCodec _TIFFBuiltinCODECS[] = {
     { "CCITT Group 4", COMPRESSION_CCITTFAX4,  TIFFInitCCITTFax4 },
     { "ISO JBIG",      COMPRESSION_JBIG,       TIFFInitJBIG },
     { "Deflate",       COMPRESSION_DEFLATE,    TIFFInitZIP },
     { "CCITT Group 4", COMPRESSION_CCITTFAX4,  TIFFInitCCITTFax4 },
     { "ISO JBIG",      COMPRESSION_JBIG,       TIFFInitJBIG },
     { "Deflate",       COMPRESSION_DEFLATE,    TIFFInitZIP },
+    { "AdobeDeflate",   COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP }, 
     { "PixarLog",      COMPRESSION_PIXARLOG,   TIFFInitPixarLog },
     { "SGILog",                COMPRESSION_SGILOG,     TIFFInitSGILog },
     { "SGILog24",      COMPRESSION_SGILOG24,   TIFFInitSGILog },
     { "PixarLog",      COMPRESSION_PIXARLOG,   TIFFInitPixarLog },
     { "SGILog",                COMPRESSION_SGILOG,     TIFFInitSGILog },
     { "SGILog24",      COMPRESSION_SGILOG24,   TIFFInitSGILog },
@@ -107,10 +108,43 @@ _notConfigured(TIFF* tif)
        return (0);
 }
 
        return (0);
 }
 
-static int LINKAGEMODE
+static int
 NotConfigured(TIFF* tif, int scheme)
 {
 NotConfigured(TIFF* tif, int scheme)
 {
-       tif->tif_setupdecode = _notConfigured;
-       tif->tif_setupencode = _notConfigured;
-       return (1);
+    (void) scheme;
+    
+    tif->tif_decodestatus = FALSE;
+    tif->tif_setupdecode = _notConfigured;
+    tif->tif_encodestatus = FALSE;
+    tif->tif_setupencode = _notConfigured;
+    return (1);
 }
 }
+
+/************************************************************************/
+/*                       TIFFIsCODECConfigured()                        */
+/************************************************************************/
+
+/**
+ * Check whether we have working codec for the specific coding scheme.
+ * 
+ * @return returns 1 if the codec is configured and working. Otherwise
+ * 0 will be returned.
+ */
+
+int
+TIFFIsCODECConfigured(uint16 scheme)
+{
+       const TIFFCodec* codec = TIFFFindCODEC(scheme);
+
+       if(codec == NULL) {
+            return 0;
+        }
+        if(codec->init == NULL) {
+            return 0;
+        }
+       if(codec->init != NotConfigured){
+            return 1;
+        }
+       return 0;
+}
+
index a7f9ef13ac62abd118a9799c3e20e396765a0e5a..dbc73c6f50368c486402281bf33db9237281ff15 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -36,13 +36,21 @@ TIFFNoEncode(TIFF* tif, char* method)
 {
        const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
 
 {
        const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression);
 
-       if (c)
-               TIFFError(tif->tif_name, "%s %s encoding is not implemented",
-                   c->name, method);
-       else
+       if (c) { 
+         if (! strncmp(c->name, "LZW", 3) ){ 
+           TIFFError(tif->tif_name, 
+                     "%s %s encoding is no longer implemented due to Unisys patent enforcement", 
+                     c->name, method); 
+         } else { 
+           TIFFError(tif->tif_name, "%s %s encoding is not implemented",
+                     c->name, method);
+         }
+       }
+       else { 
                TIFFError(tif->tif_name,
                TIFFError(tif->tif_name,
-                   "Compression scheme %u %s encoding is not implemented",
+                         "Compression scheme %u %s encoding is not implemented",
                    tif->tif_dir.td_compression, method);
                    tif->tif_dir.td_compression, method);
+       }
        return (-1);
 }
 
        return (-1);
 }
 
@@ -122,14 +130,16 @@ _TIFFNoPreCode(TIFF* tif, tsample_t s)
 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
 static void _TIFFvoid(TIFF* tif) { (void) tif; }
 
 static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); }
 static void _TIFFvoid(TIFF* tif) { (void) tif; }
 
-void LINKAGEMODE
+void
 _TIFFSetDefaultCompressionState(TIFF* tif)
 {
 _TIFFSetDefaultCompressionState(TIFF* tif)
 {
+       tif->tif_decodestatus = TRUE;
        tif->tif_setupdecode = _TIFFtrue;
        tif->tif_predecode = _TIFFNoPreCode;
        tif->tif_decoderow = _TIFFNoRowDecode;
        tif->tif_decodestrip = _TIFFNoStripDecode;
        tif->tif_decodetile = _TIFFNoTileDecode;
        tif->tif_setupdecode = _TIFFtrue;
        tif->tif_predecode = _TIFFNoPreCode;
        tif->tif_decoderow = _TIFFNoRowDecode;
        tif->tif_decodestrip = _TIFFNoStripDecode;
        tif->tif_decodetile = _TIFFNoTileDecode;
+       tif->tif_encodestatus = TRUE;
        tif->tif_setupencode = _TIFFtrue;
        tif->tif_preencode = _TIFFNoPreCode;
        tif->tif_postencode = _TIFFtrue;
        tif->tif_setupencode = _TIFFtrue;
        tif->tif_preencode = _TIFFNoPreCode;
        tif->tif_postencode = _TIFFtrue;
@@ -145,9 +155,9 @@ _TIFFSetDefaultCompressionState(TIFF* tif)
 }
 
 int
 }
 
 int
-TIFFSetCompressionScheme(TIFF* tif, uint16 scheme)
+TIFFSetCompressionScheme(TIFF* tif, int scheme)
 {
 {
-       const TIFFCodec *c = TIFFFindCODEC(scheme);
+       const TIFFCodec *c = TIFFFindCODEC((uint16) scheme);
 
        _TIFFSetDefaultCompressionState(tif);
        /*
 
        _TIFFSetDefaultCompressionState(tif);
        /*
@@ -200,9 +210,11 @@ TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init)
                cd->info->init = init;
                cd->next = registeredCODECS;
                registeredCODECS = cd;
                cd->info->init = init;
                cd->next = registeredCODECS;
                registeredCODECS = cd;
-       } else
+       } else {
                TIFFError("TIFFRegisterCODEC",
                    "No space to register compression scheme %s", name);
                TIFFError("TIFFRegisterCODEC",
                    "No space to register compression scheme %s", name);
+               return NULL;
+       }
        return (cd->info);
 }
 
        return (cd->info);
 }
 
index 05283c2a6dbfed222ff919eb59f6f290faa4f9c5..7b9ae207e94adebba512c1a64b2445acc5b6f546 100644 (file)
 #define DATATYPE_UINT          2       /* !unsigned integer data */
 #define DATATYPE_IEEEFP                3       /* !IEEE floating point data */
 
 #define DATATYPE_UINT          2       /* !unsigned integer data */
 #define DATATYPE_IEEEFP                3       /* !IEEE floating point data */
 
-void
-_TIFFsetByteArray(void** vpp, void* vp, long n)
+static void
+setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
 {
        if (*vpp)
                _TIFFfree(*vpp), *vpp = 0;
 {
        if (*vpp)
                _TIFFfree(*vpp), *vpp = 0;
-       if (vp && (*vpp = (void*) _TIFFmalloc(n)))
-               _TIFFmemcpy(*vpp, vp, n);
+       if (vp) {
+               tsize_t bytes = nmemb * elem_size;
+               if (elem_size && bytes / elem_size == nmemb)
+                       *vpp = (void*) _TIFFmalloc(bytes);
+               if (*vpp)
+                       _TIFFmemcpy(*vpp, vp, bytes);
+       }
 }
 }
+void _TIFFsetByteArray(void** vpp, void* vp, long n)
+    { setByteArray(vpp, vp, n, 1); }
 void _TIFFsetString(char** cpp, char* cp)
 void _TIFFsetString(char** cpp, char* cp)
-    { _TIFFsetByteArray((void**) cpp, (void*) cp, (long) (strlen(cp)+1)); }
+    { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); }
 void _TIFFsetNString(char** cpp, char* cp, long n)
 void _TIFFsetNString(char** cpp, char* cp, long n)
-    { _TIFFsetByteArray((void**) cpp, (void*) cp, n); }
+    { setByteArray((void**) cpp, (void*) cp, n, 1); }
 void _TIFFsetShortArray(uint16** wpp, uint16* wp, long n)
 void _TIFFsetShortArray(uint16** wpp, uint16* wp, long n)
-    { _TIFFsetByteArray((void**) wpp, (void*) wp, n*sizeof (uint16)); }
+    { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
 void _TIFFsetLongArray(uint32** lpp, uint32* lp, long n)
 void _TIFFsetLongArray(uint32** lpp, uint32* lp, long n)
-    { _TIFFsetByteArray((void**) lpp, (void*) lp, n*sizeof (uint32)); }
+    { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }
 void _TIFFsetFloatArray(float** fpp, float* fp, long n)
 void _TIFFsetFloatArray(float** fpp, float* fp, long n)
-    { _TIFFsetByteArray((void**) fpp, (void*) fp, n*sizeof (float)); }
+    { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); }
 void _TIFFsetDoubleArray(double** dpp, double* dp, long n)
 void _TIFFsetDoubleArray(double** dpp, double* dp, long n)
-    { _TIFFsetByteArray((void**) dpp, (void*) dp, n*sizeof (double)); }
+    { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); }
 
 /*
  * Install extra samples information.
 
 /*
  * Install extra samples information.
@@ -84,7 +91,6 @@ setExtraSamples(TIFFDirectory* td, va_list ap, int* v)
        return (1);
 }
 
        return (1);
 }
 
-#ifdef CMYK_SUPPORT
 static int
 checkInkNamesString(TIFF* tif, int slen, const char* s)
 {
 static int
 checkInkNamesString(TIFF* tif, int slen, const char* s)
 {
@@ -110,15 +116,15 @@ bad:
            td->td_samplesperpixel-i);
        return (0);
 }
            td->td_samplesperpixel-i);
        return (0);
 }
-#endif
 
 static int
 _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
 {
 
 static int
 _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
 {
+       static const char module[] = "_TIFFVSetField";
+       
        TIFFDirectory* td = &tif->tif_dir;
        int status = 1;
        uint32 v32;
        TIFFDirectory* td = &tif->tif_dir;
        int status = 1;
        uint32 v32;
-       uint16 v16;
        int i, v;
        double d;
        char* s;
        int i, v;
        double d;
        char* s;
@@ -153,14 +159,14 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                }
                break;
        case TIFFTAG_COMPRESSION:
                }
                break;
        case TIFFTAG_COMPRESSION:
-               v16 = va_arg(ap, int) & 0xffff;
+               v = va_arg(ap, int) & 0xffff;
                /*
                 * If we're changing the compression scheme,
                 * the notify the previous module so that it
                 * can cleanup any state it's setup.
                 */
                if (TIFFFieldSet(tif, FIELD_COMPRESSION)) {
                /*
                 * If we're changing the compression scheme,
                 * the notify the previous module so that it
                 * can cleanup any state it's setup.
                 */
                if (TIFFFieldSet(tif, FIELD_COMPRESSION)) {
-                       if (td->td_compression == v16)
+                       if (td->td_compression == v)
                                break;
                        (*tif->tif_cleanup)(tif);
                        tif->tif_flags &= ~TIFF_CODERSETUP;
                                break;
                        (*tif->tif_cleanup)(tif);
                        tif->tif_flags &= ~TIFF_CODERSETUP;
@@ -168,8 +174,10 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                /*
                 * Setup new compression routine state.
                 */
                /*
                 * Setup new compression routine state.
                 */
-               if( (status = TIFFSetCompressionScheme(tif, v16)) != 0 )
-                       td->td_compression = v16;
+               if( (status = TIFFSetCompressionScheme(tif, v)) != 0 )
+                    td->td_compression = (uint16) v;
+                else
+                    status = 0;
                break;
        case TIFFTAG_PHOTOMETRIC:
                td->td_photometric = (uint16) va_arg(ap, int);
                break;
        case TIFFTAG_PHOTOMETRIC:
                td->td_photometric = (uint16) va_arg(ap, int);
@@ -204,8 +212,8 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_MODEL:
                _TIFFsetString(&td->td_model, va_arg(ap, char*));
                break;
        case TIFFTAG_MODEL:
                _TIFFsetString(&td->td_model, va_arg(ap, char*));
                break;
-       case TIFFTAG_SOFTWARE:
-               _TIFFsetString(&td->td_software, va_arg(ap, char*));
+       case TIFFTAG_COPYRIGHT:
+               _TIFFsetString(&td->td_copyright, va_arg(ap, char*));
                break;
        case TIFFTAG_ORIENTATION:
                v = va_arg(ap, int);
                break;
        case TIFFTAG_ORIENTATION:
                v = va_arg(ap, int);
@@ -338,9 +346,24 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                break;
        case TIFFTAG_SAMPLEFORMAT:
                v = va_arg(ap, int);
                break;
        case TIFFTAG_SAMPLEFORMAT:
                v = va_arg(ap, int);
-               if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_VOID < v)
+               if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)
                        goto badvalue;
                td->td_sampleformat = (uint16) v;
                        goto badvalue;
                td->td_sampleformat = (uint16) v;
+
+                /*  Try to fix up the SWAB function for complex data. */
+                if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT 
+                    && td->td_bitspersample == 32
+                    && tif->tif_postdecode == _TIFFSwab32BitData )
+                    tif->tif_postdecode = _TIFFSwab16BitData;
+                else if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT 
+                          || td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP)
+                         && td->td_bitspersample == 64
+                         && tif->tif_postdecode == _TIFFSwab64BitData )
+                    tif->tif_postdecode = _TIFFSwab32BitData;
+                else if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP
+                         && td->td_bitspersample == 128
+                         && tif->tif_postdecode == NULL )
+                    tif->tif_postdecode = _TIFFSwab64BitData;
                break;
        case TIFFTAG_IMAGEDEPTH:
                td->td_imagedepth = va_arg(ap, uint32);
                break;
        case TIFFTAG_IMAGEDEPTH:
                td->td_imagedepth = va_arg(ap, uint32);
@@ -351,19 +374,43 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                        goto badvaluedbl;
                td->td_stonits = d;
                break;
                        goto badvaluedbl;
                td->td_stonits = d;
                break;
-#if SUBIFD_SUPPORT
+       /* Begin Pixar Tags */
+       case TIFFTAG_PIXAR_IMAGEFULLWIDTH:
+               td->td_imagefullwidth = va_arg(ap, uint32);
+               break;
+       case TIFFTAG_PIXAR_IMAGEFULLLENGTH:
+               td->td_imagefulllength = va_arg(ap, uint32);
+               break;
+       case TIFFTAG_PIXAR_TEXTUREFORMAT:
+               _TIFFsetString(&td->td_textureformat, va_arg(ap, char*));
+               break;
+       case TIFFTAG_PIXAR_WRAPMODES:
+               _TIFFsetString(&td->td_wrapmodes, va_arg(ap, char*));
+               break;
+       case TIFFTAG_PIXAR_FOVCOT:
+               td->td_fovcot = (float) va_arg(ap, dblparam_t);
+               break;
+       case TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN:
+               _TIFFsetFloatArray(&td->td_matrixWorldToScreen,
+                       va_arg(ap, float*), 16);
+               break;
+       case TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA:
+               _TIFFsetFloatArray(&td->td_matrixWorldToCamera,
+                       va_arg(ap, float*), 16);
+               break;
+       /* End Pixar Tags */           
+
        case TIFFTAG_SUBIFD:
                if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
                        td->td_nsubifd = (uint16) va_arg(ap, int);
                        _TIFFsetLongArray(&td->td_subifd, va_arg(ap, uint32*),
                            (long) td->td_nsubifd);
                } else {
        case TIFFTAG_SUBIFD:
                if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
                        td->td_nsubifd = (uint16) va_arg(ap, int);
                        _TIFFsetLongArray(&td->td_subifd, va_arg(ap, uint32*),
                            (long) td->td_nsubifd);
                } else {
-                       TIFFError(tif->tif_name, "Sorry, cannot nest SubIFDs");
+                       TIFFError(module, "%s: Sorry, cannot nest SubIFDs",
+                                 tif->tif_name);
                        status = 0;
                }
                break;
                        status = 0;
                }
                break;
-#endif
-#ifdef YCBCR_SUPPORT
        case TIFFTAG_YCBCRCOEFFICIENTS:
                _TIFFsetFloatArray(&td->td_ycbcrcoeffs, va_arg(ap, float*), 3);
                break;
        case TIFFTAG_YCBCRCOEFFICIENTS:
                _TIFFsetFloatArray(&td->td_ycbcrcoeffs, va_arg(ap, float*), 3);
                break;
@@ -374,8 +421,6 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, int);
                td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, int);
                break;
                td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, int);
                td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, int);
                break;
-#endif
-#ifdef COLORIMETRY_SUPPORT
        case TIFFTAG_WHITEPOINT:
                _TIFFsetFloatArray(&td->td_whitepoint, va_arg(ap, float*), 2);
                break;
        case TIFFTAG_WHITEPOINT:
                _TIFFsetFloatArray(&td->td_whitepoint, va_arg(ap, float*), 2);
                break;
@@ -392,8 +437,6 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
                /* XXX should check for null range */
                _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
                break;
                /* XXX should check for null range */
                _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
                break;
-#endif
-#ifdef CMYK_SUPPORT
        case TIFFTAG_INKSET:
                td->td_inkset = (uint16) va_arg(ap, int);
                break;
        case TIFFTAG_INKSET:
                td->td_inkset = (uint16) va_arg(ap, int);
                break;
@@ -418,71 +461,160 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_TARGETPRINTER:
                _TIFFsetString(&td->td_targetprinter, va_arg(ap, char*));
                break;
        case TIFFTAG_TARGETPRINTER:
                _TIFFsetString(&td->td_targetprinter, va_arg(ap, char*));
                break;
-#endif
-#ifdef ICC_SUPPORT
        case TIFFTAG_ICCPROFILE:
                td->td_profileLength = (uint32) va_arg(ap, uint32);
                _TIFFsetByteArray(&td->td_profileData, va_arg(ap, void*),
                    td->td_profileLength);
                break;
        case TIFFTAG_ICCPROFILE:
                td->td_profileLength = (uint32) va_arg(ap, uint32);
                _TIFFsetByteArray(&td->td_profileData, va_arg(ap, void*),
                    td->td_profileLength);
                break;
-#endif
-#ifdef PHOTOSHOP_SUPPORT
        case TIFFTAG_PHOTOSHOP:
                td->td_photoshopLength = (uint32) va_arg(ap, uint32);
                _TIFFsetByteArray (&td->td_photoshopData, va_arg(ap, void*),
                        td->td_photoshopLength);
                break;
        case TIFFTAG_PHOTOSHOP:
                td->td_photoshopLength = (uint32) va_arg(ap, uint32);
                _TIFFsetByteArray (&td->td_photoshopData, va_arg(ap, void*),
                        td->td_photoshopLength);
                break;
-#endif
-#ifdef IPTC_SUPPORT
-    case TIFFTAG_RICHTIFFIPTC: 
+       case TIFFTAG_RICHTIFFIPTC: 
                td->td_richtiffiptcLength = (uint32) va_arg(ap, uint32);
                td->td_richtiffiptcLength = (uint32) va_arg(ap, uint32);
-#ifdef PHOTOSHOP_SUPPORT
-               _TIFFsetLongArray ((uint32**)&td->td_richtiffiptcData, va_arg(ap, uint32*),
-                       td->td_richtiffiptcLength);
-#else
-               _TIFFsetByteArray (&td->td_photoshopData, va_arg(ap, void*),
-                       td->td_photoshopLength);
-#endif
+               _TIFFsetLongArray ((uint32**)&td->td_richtiffiptcData,
+                                  va_arg(ap, uint32*),
+                                  td->td_richtiffiptcLength);
                break;
                break;
-#endif
-       default:
-               /*
-                * This can happen if multiple images are open with
-                * different codecs which have private tags.  The
-                * global tag information table may then have tags
-                * that are valid for one file but not the other. 
-                * If the client tries to set a tag that is not valid
-                * for the image's codec then we'll arrive here.  This
-                * happens, for example, when tiffcp is used to convert
-                * between compression schemes and codec-specific tags
-                * are blindly copied.
-                */
-               TIFFError("TIFFSetField",
+       case TIFFTAG_XMLPACKET:
+               td->td_xmlpacketLength = (uint32) va_arg(ap, uint32);
+               _TIFFsetByteArray(&td->td_xmlpacketData, va_arg(ap, void*),
+                   td->td_xmlpacketLength);
+               break;
+        default: {
+            const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
+            TIFFTagValue *tv;
+            int           tv_size, iCustom;
+
+            /*
+             * This can happen if multiple images are open with
+             * different codecs which have private tags.  The
+             * global tag information table may then have tags
+             * that are valid for one file but not the other. 
+             * If the client tries to set a tag that is not valid
+             * for the image's codec then we'll arrive here.  This
+             * happens, for example, when tiffcp is used to convert
+             * between compression schemes and codec-specific tags
+             * are blindly copied.
+             */
+            if( fip == NULL || fip->field_bit != FIELD_CUSTOM )
+            {
+               TIFFError(module,
                    "%s: Invalid %stag \"%s\" (not supported by codec)",
                    "%s: Invalid %stag \"%s\" (not supported by codec)",
-                   tif->tif_name, isPseudoTag(tag) ? "pseduo-" : "",
+                   tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
                    _TIFFFieldWithTag(tif, tag)->field_name);
                status = 0;
                break;
                    _TIFFFieldWithTag(tif, tag)->field_name);
                status = 0;
                break;
+            }
+
+            /*
+             * Find the existing entry for this custom value.
+             */
+            tv = NULL;
+            for( iCustom = 0; iCustom < td->td_customValueCount; iCustom++ )
+            {
+                if( td->td_customValues[iCustom].info == fip )
+                {
+                    tv = td->td_customValues + iCustom;
+                    if( tv->value != NULL )
+                        _TIFFfree( tv->value );
+                    break;
+                }
+            }
+
+            /*
+             * Grow the custom list if the entry was not found.
+             */
+            if( tv == NULL )
+            {
+               TIFFTagValue    *new_customValues;
+               
+               td->td_customValueCount++;
+               new_customValues = (TIFFTagValue *)
+                       _TIFFrealloc(td->td_customValues,
+                                    sizeof(TIFFTagValue) * td->td_customValueCount);
+               if (!new_customValues) {
+                       TIFFError(module,
+               "%s: Failed to allocate space for list of custom values",
+                                 tif->tif_name);
+                       status = 0;
+                       goto end;
+               }
+
+               td->td_customValues = new_customValues;
+
+                tv = td->td_customValues + (td->td_customValueCount-1);
+                tv->info = fip;
+                tv->value = NULL;
+                tv->count = 0;
+            }
+
+            /*
+             * Set custom value ... save a copy of the custom tag value.
+             */
+            tv_size = TIFFDataWidth(fip->field_type);
+            if( fip->field_passcount )
+                tv->count = (int) va_arg(ap, int);
+            else
+                tv->count = 1;
+            if( fip->field_passcount )
+            {
+                tv->value = _TIFFmalloc(tv_size * tv->count);
+               if ( !tv->value ) {
+                       va_end(ap);
+                       return 0;
+               }
+                _TIFFmemcpy( tv->value, (void *) va_arg(ap,void*),
+                             tv->count * tv_size );
+            }
+            else if( fip->field_type == TIFF_ASCII )
+            {
+                const char *value = (const char *) va_arg(ap,const char *);
+                tv->count = strlen(value)+1;
+                tv->value = _TIFFmalloc(tv->count);
+               if ( !tv->value ) {
+                       va_end(ap);
+                       return 0;
+               }
+                strcpy( tv->value, value );
+            }
+            else
+            {
+                /* not supporting "pass by value" types yet */
+               TIFFWarning(module, " ... pass by value not implemented.");
+
+                tv->value = _TIFFmalloc(tv_size * tv->count);
+               if ( !tv->value ) {
+                       va_end(ap);
+                       return 0;
+               }
+                _TIFFmemset( tv->value, 0, tv->count * tv_size );
+                status = 0;
+            }
+          }
        }
        if (status) {
        }
        if (status) {
-               TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
-               tif->tif_flags |= TIFF_DIRTYDIRECT;
+            TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
+            tif->tif_flags |= TIFF_DIRTYDIRECT;
        }
        }
+
+end:
        va_end(ap);
        return (status);
 badvalue:
        va_end(ap);
        return (status);
 badvalue:
-       TIFFError(tif->tif_name, "%d: Bad value for \"%s\"", v,
-           _TIFFFieldWithTag(tif, tag)->field_name);
+       TIFFError(module, "%.1000s: Bad value %d for \"%s\"",
+                 tif->tif_name, v, _TIFFFieldWithTag(tif, tag)->field_name);
        va_end(ap);
        return (0);
 badvalue32:
        va_end(ap);
        return (0);
 badvalue32:
-       TIFFError(tif->tif_name, "%ld: Bad value for \"%s\"", v32,
-           _TIFFFieldWithTag(tif, tag)->field_name);
+       TIFFError(module, "%.1000s: Bad value %ld for \"%s\"",
+                  tif->tif_name, v32, _TIFFFieldWithTag(tif, tag)->field_name);
        va_end(ap);
        return (0);
 badvaluedbl:
        va_end(ap);
        return (0);
 badvaluedbl:
-       TIFFError(tif->tif_name, "%f: Bad value for \"%s\"", d,
-           _TIFFFieldWithTag(tif, tag)->field_name);
+       TIFFError(module, "%.1000s: Bad value %f for \"%s\"",
+                 tif->tif_name, d, _TIFFFieldWithTag(tif, tag)->field_name);
        va_end(ap);
        return (0);
 }
        va_end(ap);
        return (0);
 }
@@ -550,257 +682,312 @@ int
 TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
 {
        return OkToChangeTag(tif, tag) ?
 TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap)
 {
        return OkToChangeTag(tif, tag) ?
-           (*tif->tif_vsetfield)(tif, tag, ap) : 0;
+           (*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0;
 }
 
 static int
 _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
 {
 }
 
 static int
 _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
 {
-       TIFFDirectory* td = &tif->tif_dir;
+    TIFFDirectory* td = &tif->tif_dir;
+    int            ret_val = 1;
 
 
-       switch (tag) {
+    switch (tag) {
        case TIFFTAG_SUBFILETYPE:
        case TIFFTAG_SUBFILETYPE:
-               *va_arg(ap, uint32*) = td->td_subfiletype;
-               break;
+            *va_arg(ap, uint32*) = td->td_subfiletype;
+            break;
        case TIFFTAG_IMAGEWIDTH:
        case TIFFTAG_IMAGEWIDTH:
-               *va_arg(ap, uint32*) = td->td_imagewidth;
-               break;
+            *va_arg(ap, uint32*) = td->td_imagewidth;
+            break;
        case TIFFTAG_IMAGELENGTH:
        case TIFFTAG_IMAGELENGTH:
-               *va_arg(ap, uint32*) = td->td_imagelength;
-               break;
+            *va_arg(ap, uint32*) = td->td_imagelength;
+            break;
        case TIFFTAG_BITSPERSAMPLE:
        case TIFFTAG_BITSPERSAMPLE:
-               *va_arg(ap, uint16*) = td->td_bitspersample;
-               break;
+            *va_arg(ap, uint16*) = td->td_bitspersample;
+            break;
        case TIFFTAG_COMPRESSION:
        case TIFFTAG_COMPRESSION:
-               *va_arg(ap, uint16*) = td->td_compression;
-               break;
+            *va_arg(ap, uint16*) = td->td_compression;
+            break;
        case TIFFTAG_PHOTOMETRIC:
        case TIFFTAG_PHOTOMETRIC:
-               *va_arg(ap, uint16*) = td->td_photometric;
-               break;
+            *va_arg(ap, uint16*) = td->td_photometric;
+            break;
        case TIFFTAG_THRESHHOLDING:
        case TIFFTAG_THRESHHOLDING:
-               *va_arg(ap, uint16*) = td->td_threshholding;
-               break;
+            *va_arg(ap, uint16*) = td->td_threshholding;
+            break;
        case TIFFTAG_FILLORDER:
        case TIFFTAG_FILLORDER:
-               *va_arg(ap, uint16*) = td->td_fillorder;
-               break;
+            *va_arg(ap, uint16*) = td->td_fillorder;
+            break;
        case TIFFTAG_DOCUMENTNAME:
        case TIFFTAG_DOCUMENTNAME:
-               *va_arg(ap, char**) = td->td_documentname;
-               break;
+            *va_arg(ap, char**) = td->td_documentname;
+            break;
        case TIFFTAG_ARTIST:
        case TIFFTAG_ARTIST:
-               *va_arg(ap, char**) = td->td_artist;
-               break;
+            *va_arg(ap, char**) = td->td_artist;
+            break;
        case TIFFTAG_DATETIME:
        case TIFFTAG_DATETIME:
-               *va_arg(ap, char**) = td->td_datetime;
-               break;
+            *va_arg(ap, char**) = td->td_datetime;
+            break;
        case TIFFTAG_HOSTCOMPUTER:
        case TIFFTAG_HOSTCOMPUTER:
-               *va_arg(ap, char**) = td->td_hostcomputer;
-               break;
+            *va_arg(ap, char**) = td->td_hostcomputer;
+            break;
        case TIFFTAG_IMAGEDESCRIPTION:
        case TIFFTAG_IMAGEDESCRIPTION:
-               *va_arg(ap, char**) = td->td_imagedescription;
-               break;
+            *va_arg(ap, char**) = td->td_imagedescription;
+            break;
        case TIFFTAG_MAKE:
        case TIFFTAG_MAKE:
-               *va_arg(ap, char**) = td->td_make;
-               break;
+            *va_arg(ap, char**) = td->td_make;
+            break;
        case TIFFTAG_MODEL:
        case TIFFTAG_MODEL:
-               *va_arg(ap, char**) = td->td_model;
-               break;
-       case TIFFTAG_SOFTWARE:
-               *va_arg(ap, char**) = td->td_software;
-               break;
+            *va_arg(ap, char**) = td->td_model;
+            break;
+       case TIFFTAG_COPYRIGHT:
+            *va_arg(ap, char**) = td->td_copyright;
+            break;
        case TIFFTAG_ORIENTATION:
        case TIFFTAG_ORIENTATION:
-               *va_arg(ap, uint16*) = td->td_orientation;
-               break;
+            *va_arg(ap, uint16*) = td->td_orientation;
+            break;
        case TIFFTAG_SAMPLESPERPIXEL:
        case TIFFTAG_SAMPLESPERPIXEL:
-               *va_arg(ap, uint16*) = td->td_samplesperpixel;
-               break;
+            *va_arg(ap, uint16*) = td->td_samplesperpixel;
+            break;
        case TIFFTAG_ROWSPERSTRIP:
        case TIFFTAG_ROWSPERSTRIP:
-               *va_arg(ap, uint32*) = td->td_rowsperstrip;
-               break;
+            *va_arg(ap, uint32*) = td->td_rowsperstrip;
+            break;
        case TIFFTAG_MINSAMPLEVALUE:
        case TIFFTAG_MINSAMPLEVALUE:
-               *va_arg(ap, uint16*) = td->td_minsamplevalue;
-               break;
+            *va_arg(ap, uint16*) = td->td_minsamplevalue;
+            break;
        case TIFFTAG_MAXSAMPLEVALUE:
        case TIFFTAG_MAXSAMPLEVALUE:
-               *va_arg(ap, uint16*) = td->td_maxsamplevalue;
-               break;
+            *va_arg(ap, uint16*) = td->td_maxsamplevalue;
+            break;
        case TIFFTAG_SMINSAMPLEVALUE:
        case TIFFTAG_SMINSAMPLEVALUE:
-               *va_arg(ap, double*) = td->td_sminsamplevalue;
-               break;
+            *va_arg(ap, double*) = td->td_sminsamplevalue;
+            break;
        case TIFFTAG_SMAXSAMPLEVALUE:
        case TIFFTAG_SMAXSAMPLEVALUE:
-               *va_arg(ap, double*) = td->td_smaxsamplevalue;
-               break;
+            *va_arg(ap, double*) = td->td_smaxsamplevalue;
+            break;
        case TIFFTAG_XRESOLUTION:
        case TIFFTAG_XRESOLUTION:
-               *va_arg(ap, float*) = td->td_xresolution;
-               break;
+            *va_arg(ap, float*) = td->td_xresolution;
+            break;
        case TIFFTAG_YRESOLUTION:
        case TIFFTAG_YRESOLUTION:
-               *va_arg(ap, float*) = td->td_yresolution;
-               break;
+            *va_arg(ap, float*) = td->td_yresolution;
+            break;
        case TIFFTAG_PLANARCONFIG:
        case TIFFTAG_PLANARCONFIG:
-               *va_arg(ap, uint16*) = td->td_planarconfig;
-               break;
+            *va_arg(ap, uint16*) = td->td_planarconfig;
+            break;
        case TIFFTAG_XPOSITION:
        case TIFFTAG_XPOSITION:
-               *va_arg(ap, float*) = td->td_xposition;
-               break;
+            *va_arg(ap, float*) = td->td_xposition;
+            break;
        case TIFFTAG_YPOSITION:
        case TIFFTAG_YPOSITION:
-               *va_arg(ap, float*) = td->td_yposition;
-               break;
+            *va_arg(ap, float*) = td->td_yposition;
+            break;
        case TIFFTAG_PAGENAME:
        case TIFFTAG_PAGENAME:
-               *va_arg(ap, char**) = td->td_pagename;
-               break;
+            *va_arg(ap, char**) = td->td_pagename;
+            break;
        case TIFFTAG_RESOLUTIONUNIT:
        case TIFFTAG_RESOLUTIONUNIT:
-               *va_arg(ap, uint16*) = td->td_resolutionunit;
-               break;
+            *va_arg(ap, uint16*) = td->td_resolutionunit;
+            break;
        case TIFFTAG_PAGENUMBER:
        case TIFFTAG_PAGENUMBER:
-               *va_arg(ap, uint16*) = td->td_pagenumber[0];
-               *va_arg(ap, uint16*) = td->td_pagenumber[1];
-               break;
+            *va_arg(ap, uint16*) = td->td_pagenumber[0];
+            *va_arg(ap, uint16*) = td->td_pagenumber[1];
+            break;
        case TIFFTAG_HALFTONEHINTS:
        case TIFFTAG_HALFTONEHINTS:
-               *va_arg(ap, uint16*) = td->td_halftonehints[0];
-               *va_arg(ap, uint16*) = td->td_halftonehints[1];
-               break;
+            *va_arg(ap, uint16*) = td->td_halftonehints[0];
+            *va_arg(ap, uint16*) = td->td_halftonehints[1];
+            break;
        case TIFFTAG_COLORMAP:
        case TIFFTAG_COLORMAP:
-               *va_arg(ap, uint16**) = td->td_colormap[0];
-               *va_arg(ap, uint16**) = td->td_colormap[1];
-               *va_arg(ap, uint16**) = td->td_colormap[2];
-               break;
+            *va_arg(ap, uint16**) = td->td_colormap[0];
+            *va_arg(ap, uint16**) = td->td_colormap[1];
+            *va_arg(ap, uint16**) = td->td_colormap[2];
+            break;
        case TIFFTAG_STRIPOFFSETS:
        case TIFFTAG_TILEOFFSETS:
        case TIFFTAG_STRIPOFFSETS:
        case TIFFTAG_TILEOFFSETS:
-               *va_arg(ap, uint32**) = td->td_stripoffset;
-               break;
+            *va_arg(ap, uint32**) = td->td_stripoffset;
+            break;
        case TIFFTAG_STRIPBYTECOUNTS:
        case TIFFTAG_TILEBYTECOUNTS:
        case TIFFTAG_STRIPBYTECOUNTS:
        case TIFFTAG_TILEBYTECOUNTS:
-               *va_arg(ap, uint32**) = td->td_stripbytecount;
-               break;
+            *va_arg(ap, uint32**) = td->td_stripbytecount;
+            break;
        case TIFFTAG_MATTEING:
        case TIFFTAG_MATTEING:
-               *va_arg(ap, uint16*) =
-                   (td->td_extrasamples == 1 &&
-                    td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
-               break;
+            *va_arg(ap, uint16*) =
+                (td->td_extrasamples == 1 &&
+                 td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
+            break;
        case TIFFTAG_EXTRASAMPLES:
        case TIFFTAG_EXTRASAMPLES:
-               *va_arg(ap, uint16*) = td->td_extrasamples;
-               *va_arg(ap, uint16**) = td->td_sampleinfo;
-               break;
+            *va_arg(ap, uint16*) = td->td_extrasamples;
+            *va_arg(ap, uint16**) = td->td_sampleinfo;
+            break;
        case TIFFTAG_TILEWIDTH:
        case TIFFTAG_TILEWIDTH:
-               *va_arg(ap, uint32*) = td->td_tilewidth;
-               break;
+            *va_arg(ap, uint32*) = td->td_tilewidth;
+            break;
        case TIFFTAG_TILELENGTH:
        case TIFFTAG_TILELENGTH:
-               *va_arg(ap, uint32*) = td->td_tilelength;
-               break;
+            *va_arg(ap, uint32*) = td->td_tilelength;
+            break;
        case TIFFTAG_TILEDEPTH:
        case TIFFTAG_TILEDEPTH:
-               *va_arg(ap, uint32*) = td->td_tiledepth;
-               break;
+            *va_arg(ap, uint32*) = td->td_tiledepth;
+            break;
        case TIFFTAG_DATATYPE:
        case TIFFTAG_DATATYPE:
-               switch (td->td_sampleformat) {
+            switch (td->td_sampleformat) {
                case SAMPLEFORMAT_UINT:
                case SAMPLEFORMAT_UINT:
-                       *va_arg(ap, uint16*) = DATATYPE_UINT;
-                       break;
+                    *va_arg(ap, uint16*) = DATATYPE_UINT;
+                    break;
                case SAMPLEFORMAT_INT:
                case SAMPLEFORMAT_INT:
-                       *va_arg(ap, uint16*) = DATATYPE_INT;
-                       break;
+                    *va_arg(ap, uint16*) = DATATYPE_INT;
+                    break;
                case SAMPLEFORMAT_IEEEFP:
                case SAMPLEFORMAT_IEEEFP:
-                       *va_arg(ap, uint16*) = DATATYPE_IEEEFP;
-                       break;
+                    *va_arg(ap, uint16*) = DATATYPE_IEEEFP;
+                    break;
                case SAMPLEFORMAT_VOID:
                case SAMPLEFORMAT_VOID:
-                       *va_arg(ap, uint16*) = DATATYPE_VOID;
-                       break;
-               }
-               break;
+                    *va_arg(ap, uint16*) = DATATYPE_VOID;
+                    break;
+            }
+            break;
        case TIFFTAG_SAMPLEFORMAT:
        case TIFFTAG_SAMPLEFORMAT:
-               *va_arg(ap, uint16*) = td->td_sampleformat;
-               break;
+            *va_arg(ap, uint16*) = td->td_sampleformat;
+            break;
        case TIFFTAG_IMAGEDEPTH:
        case TIFFTAG_IMAGEDEPTH:
-               *va_arg(ap, uint32*) = td->td_imagedepth;
-               break;
+            *va_arg(ap, uint32*) = td->td_imagedepth;
+            break;
        case TIFFTAG_STONITS:
        case TIFFTAG_STONITS:
-               *va_arg(ap, double*) = td->td_stonits;
-               break;
-#if SUBIFD_SUPPORT
+            *va_arg(ap, double*) = td->td_stonits;
+            break;
        case TIFFTAG_SUBIFD:
        case TIFFTAG_SUBIFD:
-               *va_arg(ap, uint16*) = td->td_nsubifd;
-               *va_arg(ap, uint32**) = td->td_subifd;
-               break;
-#endif
-#ifdef YCBCR_SUPPORT
+            *va_arg(ap, uint16*) = td->td_nsubifd;
+            *va_arg(ap, uint32**) = td->td_subifd;
+            break;
        case TIFFTAG_YCBCRCOEFFICIENTS:
        case TIFFTAG_YCBCRCOEFFICIENTS:
-               *va_arg(ap, float**) = td->td_ycbcrcoeffs;
-               break;
+            *va_arg(ap, float**) = td->td_ycbcrcoeffs;
+            break;
        case TIFFTAG_YCBCRPOSITIONING:
        case TIFFTAG_YCBCRPOSITIONING:
-               *va_arg(ap, uint16*) = td->td_ycbcrpositioning;
-               break;
+            *va_arg(ap, uint16*) = td->td_ycbcrpositioning;
+            break;
        case TIFFTAG_YCBCRSUBSAMPLING:
        case TIFFTAG_YCBCRSUBSAMPLING:
-               *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0];
-               *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
-               break;
-#endif
-#ifdef COLORIMETRY_SUPPORT
+            *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0];
+            *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
+            break;
        case TIFFTAG_WHITEPOINT:
        case TIFFTAG_WHITEPOINT:
-               *va_arg(ap, float**) = td->td_whitepoint;
-               break;
+            *va_arg(ap, float**) = td->td_whitepoint;
+            break;
        case TIFFTAG_PRIMARYCHROMATICITIES:
        case TIFFTAG_PRIMARYCHROMATICITIES:
-               *va_arg(ap, float**) = td->td_primarychromas;
-               break;
+            *va_arg(ap, float**) = td->td_primarychromas;
+            break;
        case TIFFTAG_TRANSFERFUNCTION:
        case TIFFTAG_TRANSFERFUNCTION:
-               *va_arg(ap, uint16**) = td->td_transferfunction[0];
-               if (td->td_samplesperpixel - td->td_extrasamples > 1) {
-                       *va_arg(ap, uint16**) = td->td_transferfunction[1];
-                       *va_arg(ap, uint16**) = td->td_transferfunction[2];
-               }
-               break;
+            *va_arg(ap, uint16**) = td->td_transferfunction[0];
+            if (td->td_samplesperpixel - td->td_extrasamples > 1) {
+                *va_arg(ap, uint16**) = td->td_transferfunction[1];
+                *va_arg(ap, uint16**) = td->td_transferfunction[2];
+            }
+            break;
        case TIFFTAG_REFERENCEBLACKWHITE:
        case TIFFTAG_REFERENCEBLACKWHITE:
-               *va_arg(ap, float**) = td->td_refblackwhite;
-               break;
-#endif
-#ifdef CMYK_SUPPORT
+            *va_arg(ap, float**) = td->td_refblackwhite;
+            break;
        case TIFFTAG_INKSET:
        case TIFFTAG_INKSET:
-               *va_arg(ap, uint16*) = td->td_inkset;
-               break;
+            *va_arg(ap, uint16*) = td->td_inkset;
+            break;
        case TIFFTAG_DOTRANGE:
        case TIFFTAG_DOTRANGE:
-               *va_arg(ap, uint16*) = td->td_dotrange[0];
-               *va_arg(ap, uint16*) = td->td_dotrange[1];
-               break;
+            *va_arg(ap, uint16*) = td->td_dotrange[0];
+            *va_arg(ap, uint16*) = td->td_dotrange[1];
+            break;
        case TIFFTAG_INKNAMES:
        case TIFFTAG_INKNAMES:
-               *va_arg(ap, char**) = td->td_inknames;
-               break;
+            *va_arg(ap, char**) = td->td_inknames;
+            break;
        case TIFFTAG_NUMBEROFINKS:
        case TIFFTAG_NUMBEROFINKS:
-               *va_arg(ap, uint16*) = td->td_ninks;
-               break;
+            *va_arg(ap, uint16*) = td->td_ninks;
+            break;
        case TIFFTAG_TARGETPRINTER:
        case TIFFTAG_TARGETPRINTER:
-               *va_arg(ap, char**) = td->td_targetprinter;
-               break;
-#endif
-#ifdef ICC_SUPPORT
+            *va_arg(ap, char**) = td->td_targetprinter;
+            break;
        case TIFFTAG_ICCPROFILE:
        case TIFFTAG_ICCPROFILE:
-               *va_arg(ap, uint32*) = td->td_profileLength;
-               *va_arg(ap, void**) = td->td_profileData;
-               break;
-#endif
-#ifdef PHOTOSHOP_SUPPORT
+            *va_arg(ap, uint32*) = td->td_profileLength;
+            *va_arg(ap, void**) = td->td_profileData;
+            break;
        case TIFFTAG_PHOTOSHOP:
        case TIFFTAG_PHOTOSHOP:
-               *va_arg(ap, uint32*) = td->td_photoshopLength;
-               *va_arg(ap, void**) = td->td_photoshopData;
-               break;
-#endif
-#ifdef IPTC_SUPPORT
+            *va_arg(ap, uint32*) = td->td_photoshopLength;
+            *va_arg(ap, void**) = td->td_photoshopData;
+            break;
        case TIFFTAG_RICHTIFFIPTC:
        case TIFFTAG_RICHTIFFIPTC:
-               *va_arg(ap, uint32*) = td->td_richtiffiptcLength;
-               *va_arg(ap, void**) = td->td_richtiffiptcData;
-               break;
-#endif
-       default:
-               /*
-                * This can happen if multiple images are open with
-                * different codecs which have private tags.  The
-                * global tag information table may then have tags
-                * that are valid for one file but not the other. 
-                * If the client tries to get a tag that is not valid
-                * for the image's codec then we'll arrive here.
-                */
-               TIFFError("TIFFGetField",
-                   "%s: Invalid %stag \"%s\" (not supported by codec)",
-                   tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
-                   _TIFFFieldWithTag(tif, tag)->field_name);
-               break;
-       }
-       return (1);
+            *va_arg(ap, uint32*) = td->td_richtiffiptcLength;
+            *va_arg(ap, void**) = td->td_richtiffiptcData;
+            break;
+       case TIFFTAG_XMLPACKET:
+            *va_arg(ap, uint32*) = td->td_xmlpacketLength;
+            *va_arg(ap, void**) = td->td_xmlpacketData;
+            break;
+            /* Begin Pixar Tags */
+       case TIFFTAG_PIXAR_IMAGEFULLWIDTH:
+            *va_arg(ap, uint32*) = td->td_imagefullwidth;
+            break;
+       case TIFFTAG_PIXAR_IMAGEFULLLENGTH:
+            *va_arg(ap, uint32*) = td->td_imagefulllength;
+            break;
+       case TIFFTAG_PIXAR_TEXTUREFORMAT:
+            *va_arg(ap, char**) = td->td_textureformat;
+            break;
+       case TIFFTAG_PIXAR_WRAPMODES:
+            *va_arg(ap, char**) = td->td_wrapmodes;
+            break;
+       case TIFFTAG_PIXAR_FOVCOT:
+            *va_arg(ap, float*) = td->td_fovcot;
+            break;
+       case TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN:
+            *va_arg(ap, float**) = td->td_matrixWorldToScreen;
+            break;
+       case TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA:
+            *va_arg(ap, float**) = td->td_matrixWorldToCamera;
+            break;
+            /* End Pixar Tags */
+
+        default:
+        {
+            const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
+            int           i;
+            
+            /*
+             * This can happen if multiple images are open with
+             * different codecs which have private tags.  The
+             * global tag information table may then have tags
+             * that are valid for one file but not the other. 
+             * If the client tries to get a tag that is not valid
+             * for the image's codec then we'll arrive here.
+             */
+            if( fip == NULL || fip->field_bit != FIELD_CUSTOM )
+            {
+                TIFFError("_TIFFVGetField",
+                          "%s: Invalid %stag \"%s\" (not supported by codec)",
+                          tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
+                          _TIFFFieldWithTag(tif, tag)->field_name);
+                ret_val = 0;
+                break;
+            }
+
+            /*
+            ** Do we have a custom value?
+            */
+            ret_val = 0;
+            for( i = 0; i < td->td_customValueCount; i++ )
+            {
+                TIFFTagValue *tv = td->td_customValues + i;
+
+                if( tv->info->field_tag != tag )
+                    continue;
+                
+                if( fip->field_passcount )
+                {
+                    *va_arg(ap, u_short *) = (u_short) tv->count;
+                    *va_arg(ap, void **) = tv->value;
+                    ret_val = 1;
+                    break;
+                }
+                else if( fip->field_type == TIFF_ASCII )
+                {
+                    *va_arg(ap, void **) = tv->value;
+                    ret_val = 1;
+                    break;
+                }
+                else
+                {
+                    printf( "TIFFVGetField ... pass by value not imp.\n" );
+                    break;
+                }
+            }
+        }
+    }
+    return( ret_val );
 }
 
 /*
 }
 
 /*
@@ -830,7 +1017,7 @@ TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
 {
        const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
        return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ?
 {
        const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
        return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ?
-           (*tif->tif_vgetfield)(tif, tag, ap) : 0);
+           (*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0);
 }
 
 #define        CleanupField(member) {          \
 }
 
 #define        CleanupField(member) {          \
@@ -846,50 +1033,52 @@ TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap)
 void
 TIFFFreeDirectory(TIFF* tif)
 {
 void
 TIFFFreeDirectory(TIFF* tif)
 {
-       register TIFFDirectory *td = &tif->tif_dir;
+    TIFFDirectory *td = &tif->tif_dir;
+    int            i;
+
+    CleanupField(td_colormap[0]);
+    CleanupField(td_colormap[1]);
+    CleanupField(td_colormap[2]);
+    CleanupField(td_documentname);
+    CleanupField(td_artist);
+    CleanupField(td_datetime);
+    CleanupField(td_hostcomputer);
+    CleanupField(td_imagedescription);
+    CleanupField(td_make);
+    CleanupField(td_model);
+    CleanupField(td_copyright);
+    CleanupField(td_pagename);
+    CleanupField(td_sampleinfo);
+    CleanupField(td_subifd);
+    CleanupField(td_ycbcrcoeffs);
+    CleanupField(td_inknames);
+    CleanupField(td_targetprinter);
+    CleanupField(td_whitepoint);
+    CleanupField(td_primarychromas);
+    CleanupField(td_refblackwhite);
+    CleanupField(td_transferfunction[0]);
+    CleanupField(td_transferfunction[1]);
+    CleanupField(td_transferfunction[2]);
+    CleanupField(td_profileData);
+    CleanupField(td_photoshopData);
+    CleanupField(td_richtiffiptcData);
+    CleanupField(td_xmlpacketData);
+    CleanupField(td_stripoffset);
+    CleanupField(td_stripbytecount);
+    /* Begin Pixar Tags */
+    CleanupField(td_textureformat);
+    CleanupField(td_wrapmodes);
+    CleanupField(td_matrixWorldToScreen);
+    CleanupField(td_matrixWorldToCamera);
+    /* End Pixar Tags */
+
+    /* Cleanup custom tag values */
+    for( i = 0; i < td->td_customValueCount; i++ )
+        _TIFFfree( td->td_customValues[i].value );
 
 
-       CleanupField(td_colormap[0]);
-       CleanupField(td_colormap[1]);
-       CleanupField(td_colormap[2]);
-       CleanupField(td_documentname);
-       CleanupField(td_artist);
-       CleanupField(td_datetime);
-       CleanupField(td_hostcomputer);
-       CleanupField(td_imagedescription);
-       CleanupField(td_make);
-       CleanupField(td_model);
-       CleanupField(td_software);
-       CleanupField(td_pagename);
-       CleanupField(td_sampleinfo);
-#if SUBIFD_SUPPORT
-       CleanupField(td_subifd);
-#endif
-#ifdef YCBCR_SUPPORT
-       CleanupField(td_ycbcrcoeffs);
-#endif
-#ifdef CMYK_SUPPORT
-       CleanupField(td_inknames);
-       CleanupField(td_targetprinter);
-#endif
-#ifdef COLORIMETRY_SUPPORT
-       CleanupField(td_whitepoint);
-       CleanupField(td_primarychromas);
-       CleanupField(td_refblackwhite);
-       CleanupField(td_transferfunction[0]);
-       CleanupField(td_transferfunction[1]);
-       CleanupField(td_transferfunction[2]);
-#endif
-#ifdef ICC_SUPPORT
-       CleanupField(td_profileData);
-#endif
-#ifdef PHOTOSHOP_SUPPORT
-       CleanupField(td_photoshopData);
-#endif
-#ifdef IPTC_SUPPORT
-       CleanupField(td_richtiffiptcData);
-#endif
-       CleanupField(td_stripoffset);
-       CleanupField(td_stripbytecount);
+    if( td->td_customValues != NULL )
+        _TIFFfree( td->td_customValues );
+          
 }
 #undef CleanupField
 
 }
 #undef CleanupField
 
@@ -906,6 +1095,26 @@ TIFFSetTagExtender(TIFFExtendProc extender)
        return (prev);
 }
 
        return (prev);
 }
 
+/*
+ * Setup for a new directory.  Should we automatically call
+ * TIFFWriteDirectory() if the current one is dirty?
+ *
+ * The newly created directory will not exist on the file till
+ * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called.
+ */
+int
+TIFFCreateDirectory(TIFF* tif)
+{
+    TIFFDefaultDirectory(tif);
+    tif->tif_diroff = 0;
+    tif->tif_nextdiroff = 0;
+    tif->tif_curoff = 0;
+    tif->tif_row = (uint32) -1;
+    tif->tif_curstrip = (tstrip_t) -1;
+
+    return 0;
+}
+
 /*
  * Setup a default directory structure.
  */
 /*
  * Setup a default directory structure.
  */
@@ -926,21 +1135,17 @@ TIFFDefaultDirectory(TIFF* tif)
        td->td_tilelength = (uint32) -1;
        td->td_tiledepth = 1;
        td->td_resolutionunit = RESUNIT_INCH;
        td->td_tilelength = (uint32) -1;
        td->td_tiledepth = 1;
        td->td_resolutionunit = RESUNIT_INCH;
-       td->td_sampleformat = SAMPLEFORMAT_VOID;
+       td->td_sampleformat = SAMPLEFORMAT_UINT;
        td->td_imagedepth = 1;
        td->td_imagedepth = 1;
-#ifdef YCBCR_SUPPORT
        td->td_ycbcrsubsampling[0] = 2;
        td->td_ycbcrsubsampling[1] = 2;
        td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED;
        td->td_ycbcrsubsampling[0] = 2;
        td->td_ycbcrsubsampling[1] = 2;
        td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED;
-#endif
-#ifdef CMYK_SUPPORT
        td->td_inkset = INKSET_CMYK;
        td->td_ninks = 4;
        td->td_inkset = INKSET_CMYK;
        td->td_ninks = 4;
-#endif
        tif->tif_postdecode = _TIFFNoPostDecode;
        tif->tif_postdecode = _TIFFNoPostDecode;
-       tif->tif_vsetfield = _TIFFVSetField;
-       tif->tif_vgetfield = _TIFFVGetField;
-       tif->tif_printdir = NULL;
+       tif->tif_tagmethods.vsetfield = _TIFFVSetField;
+       tif->tif_tagmethods.vgetfield = _TIFFVGetField;
+       tif->tif_tagmethods.printdir = NULL;
        /*
         *  Give client code a chance to install their own
         *  tag extensions & methods, prior to compression overloads.
        /*
         *  Give client code a chance to install their own
         *  tag extensions & methods, prior to compression overloads.
@@ -957,37 +1162,73 @@ TIFFDefaultDirectory(TIFF* tif)
         * (i.e. TIFFSetField).
         */
        tif->tif_flags &= ~TIFF_DIRTYDIRECT;
         * (i.e. TIFFSetField).
         */
        tif->tif_flags &= ~TIFF_DIRTYDIRECT;
+
+        /*
+         * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
+         * we clear the ISTILED flag when setting up a new directory.
+         * Should we also be clearing stuff like INSUBIFD?
+         */
+        tif->tif_flags &= ~TIFF_ISTILED;
+
        return (1);
 }
 
 static int
 TIFFAdvanceDirectory(TIFF* tif, uint32* nextdir, toff_t* off)
 {
        return (1);
 }
 
 static int
 TIFFAdvanceDirectory(TIFF* tif, uint32* nextdir, toff_t* off)
 {
-       static const char module[] = "TIFFAdvanceDirectory";
-       uint16 dircount;
-
-       if (!SeekOK(tif, *nextdir) ||
-           !ReadOK(tif, &dircount, sizeof (uint16))) {
-               TIFFError(module, "%s: Error fetching directory count",
-                   tif->tif_name);
-               return (0);
-       }
-       if (tif->tif_flags & TIFF_SWAB)
-               TIFFSwabShort(&dircount);
-       if (off != NULL)
-               *off = TIFFSeekFile(tif,
-                   dircount*sizeof (TIFFDirEntry), SEEK_CUR);
-       else
-               (void) TIFFSeekFile(tif,
-                   dircount*sizeof (TIFFDirEntry), SEEK_CUR);
-       if (!ReadOK(tif, nextdir, sizeof (uint32))) {
-               TIFFError(module, "%s: Error fetching directory link",
-                   tif->tif_name);
-               return (0);
-       }
-       if (tif->tif_flags & TIFF_SWAB)
-               TIFFSwabLong(nextdir);
-       return (1);
+    static const char module[] = "TIFFAdvanceDirectory";
+    uint16 dircount;
+    if (isMapped(tif))
+    {
+        toff_t poff=*nextdir;
+        if (poff+sizeof(uint16) > tif->tif_size)
+        {
+            TIFFError(module, "%s: Error fetching directory count",
+                      tif->tif_name);
+            return (0);
+        }
+        _TIFFmemcpy(&dircount, tif->tif_base+poff, sizeof (uint16));
+        if (tif->tif_flags & TIFF_SWAB)
+            TIFFSwabShort(&dircount);
+        poff+=sizeof (uint16)+dircount*sizeof (TIFFDirEntry);
+        if (off != NULL)
+            *off = poff;
+        if (((toff_t) (poff+sizeof (uint32))) > tif->tif_size)
+        {
+            TIFFError(module, "%s: Error fetching directory link",
+                      tif->tif_name);
+            return (0);
+        }
+        _TIFFmemcpy(nextdir, tif->tif_base+poff, sizeof (uint32));
+        if (tif->tif_flags & TIFF_SWAB)
+            TIFFSwabLong(nextdir);
+        return (1);
+    }
+    else
+    {
+        if (!SeekOK(tif, *nextdir) ||
+            !ReadOK(tif, &dircount, sizeof (uint16))) {
+            TIFFError(module, "%s: Error fetching directory count",
+                      tif->tif_name);
+            return (0);
+        }
+        if (tif->tif_flags & TIFF_SWAB)
+            TIFFSwabShort(&dircount);
+        if (off != NULL)
+            *off = TIFFSeekFile(tif,
+                                dircount*sizeof (TIFFDirEntry), SEEK_CUR);
+        else
+            (void) TIFFSeekFile(tif,
+                                dircount*sizeof (TIFFDirEntry), SEEK_CUR);
+        if (!ReadOK(tif, nextdir, sizeof (uint32))) {
+            TIFFError(module, "%s: Error fetching directory link",
+                      tif->tif_name);
+            return (0);
+        }
+        if (tif->tif_flags & TIFF_SWAB)
+            TIFFSwabLong(nextdir);
+        return (1);
+    }
 }
 
 /*
 }
 
 /*
@@ -996,12 +1237,12 @@ TIFFAdvanceDirectory(TIFF* tif, uint32* nextdir, toff_t* off)
 tdir_t
 TIFFNumberOfDirectories(TIFF* tif)
 {
 tdir_t
 TIFFNumberOfDirectories(TIFF* tif)
 {
-       uint32 nextdir = tif->tif_header.tiff_diroff;
-       tdir_t n = 0;
-
-       while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL))
-               n++;
-       return (n);
+    toff_t nextdir = tif->tif_header.tiff_diroff;
+    tdir_t n = 0;
+    
+    while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL))
+        n++;
+    return (n);
 }
 
 /*
 }
 
 /*
@@ -1011,7 +1252,7 @@ TIFFNumberOfDirectories(TIFF* tif)
 int
 TIFFSetDirectory(TIFF* tif, tdir_t dirn)
 {
 int
 TIFFSetDirectory(TIFF* tif, tdir_t dirn)
 {
-       uint32 nextdir;
+       toff_t nextdir;
        tdir_t n;
 
        nextdir = tif->tif_header.tiff_diroff;
        tdir_t n;
 
        nextdir = tif->tif_header.tiff_diroff;
@@ -1025,6 +1266,11 @@ TIFFSetDirectory(TIFF* tif, tdir_t dirn)
         * tif_curdir after successfully reading the directory.
         */
        tif->tif_curdir = (dirn - n) - 1;
         * tif_curdir after successfully reading the directory.
         */
        tif->tif_curdir = (dirn - n) - 1;
+       /*
+        * Reset tif_dirnumber counter nad start new list of seen directories.
+        * We need this in order to prevent IFD loops.
+        */
+       tif->tif_dirnumber = 0;
        return (TIFFReadDirectory(tif));
 }
 
        return (TIFFReadDirectory(tif));
 }
 
@@ -1038,6 +1284,11 @@ int
 TIFFSetSubDirectory(TIFF* tif, uint32 diroff)
 {
        tif->tif_nextdiroff = diroff;
 TIFFSetSubDirectory(TIFF* tif, uint32 diroff)
 {
        tif->tif_nextdiroff = diroff;
+       /*
+        * Reset tif_dirnumber counter nad start new list of seen directories.
+        * We need this in order to prevent IFD loops.
+        */
+       tif->tif_dirnumber = 0;
        return (TIFFReadDirectory(tif));
 }
 
        return (TIFFReadDirectory(tif));
 }
 
@@ -1067,7 +1318,7 @@ int
 TIFFUnlinkDirectory(TIFF* tif, tdir_t dirn)
 {
        static const char module[] = "TIFFUnlinkDirectory";
 TIFFUnlinkDirectory(TIFF* tif, tdir_t dirn)
 {
        static const char module[] = "TIFFUnlinkDirectory";
-       uint32 nextdir;
+       toff_t nextdir;
        toff_t off;
        tdir_t n;
 
        toff_t off;
        tdir_t n;
 
@@ -1174,7 +1425,6 @@ TIFFReassignTagToIgnore (enum TIFFIgnoreSense task, int TIFFtagID)
       case TIS_EMPTY:
         tagcount = 0 ;                 /* Clear the list */
         return (TRUE) ;
       case TIS_EMPTY:
         tagcount = 0 ;                 /* Clear the list */
         return (TRUE) ;
-        break;
         
       default:
         break;
         
       default:
         break;
@@ -1182,3 +1432,4 @@ TIFFReassignTagToIgnore (enum TIFFIgnoreSense task, int TIFFtagID)
     
     return (FALSE);
 }
     
     return (FALSE);
 }
+
index 9d004b72fe4f8ea63865211260ece3353c6711ea..f1730810947ccb6c11f23b8fbf6a9209c61ce777 100644 (file)
@@ -34,7 +34,7 @@
  * Internal format of a TIFF directory entry.
  */
 typedef        struct {
  * Internal format of a TIFF directory entry.
  */
 typedef        struct {
-#define        FIELD_SETLONGS  3
+#define        FIELD_SETLONGS  4
        /* bit vector of fields that are set */
        u_long  td_fieldsset[FIELD_SETLONGS];
 
        /* bit vector of fields that are set */
        u_long  td_fieldsset[FIELD_SETLONGS];
 
@@ -69,7 +69,7 @@ typedef       struct {
        char*   td_imagedescription;
        char*   td_make;
        char*   td_model;
        char*   td_imagedescription;
        char*   td_make;
        char*   td_model;
-       char*   td_software;
+        char*   td_copyright;
        char*   td_pagename;
        tstrip_t td_stripsperimage;
        tstrip_t td_nstrips;            /* size of offset & bytecount arrays */
        char*   td_pagename;
        tstrip_t td_stripsperimage;
        tstrip_t td_nstrips;            /* size of offset & bytecount arrays */
@@ -110,6 +110,18 @@ typedef    struct {
        uint32  td_richtiffiptcLength;
        void    *td_richtiffiptcData;
 #endif
        uint32  td_richtiffiptcLength;
        void    *td_richtiffiptcData;
 #endif
+        /* Begin Pixar Tag values. */
+        uint32 td_imagefullwidth, td_imagefulllength;
+       char*   td_textureformat;
+       char*   td_wrapmodes;
+       float   td_fovcot;
+       float*  td_matrixWorldToScreen;
+       float*  td_matrixWorldToCamera;
+       /* End Pixar Tag Values. */
+       uint32  td_xmlpacketLength;
+       void    *td_xmlpacketData;
+               int     td_customValueCount;
+        TIFFTagValue *td_customValues;
 } TIFFDirectory;
 
 /*
 } TIFFDirectory;
 
 /*
@@ -160,7 +172,7 @@ typedef     struct {
 #define FIELD_ARTIST                   27
 #define FIELD_DATETIME                 28
 #define FIELD_HOSTCOMPUTER             29
 #define FIELD_ARTIST                   27
 #define FIELD_DATETIME                 28
 #define FIELD_HOSTCOMPUTER             29
-#define FIELD_SOFTWARE                 30
+/* unused - was FIELD_SOFTWARE          30 */
 #define        FIELD_EXTRASAMPLES              31
 #define FIELD_SAMPLEFORMAT             32
 #define        FIELD_SMINSAMPLEVALUE           33
 #define        FIELD_EXTRASAMPLES              31
 #define FIELD_SAMPLEFORMAT             32
 #define        FIELD_SMINSAMPLEVALUE           33
@@ -185,8 +197,21 @@ typedef    struct {
 #define FIELD_PHOTOSHOP                        52
 #define FIELD_RICHTIFFIPTC             53
 #define FIELD_STONITS                  54
 #define FIELD_PHOTOSHOP                        52
 #define FIELD_RICHTIFFIPTC             53
 #define FIELD_STONITS                  54
+/* Begin PIXAR */
+#define        FIELD_IMAGEFULLWIDTH            55
+#define        FIELD_IMAGEFULLLENGTH           56
+#define FIELD_TEXTUREFORMAT            57
+#define FIELD_WRAPMODES                        58
+#define FIELD_FOVCOT                   59
+#define FIELD_MATRIX_WORLDTOSCREEN     60
+#define FIELD_MATRIX_WORLDTOCAMERA     61
+#define FIELD_COPYRIGHT                        62
+#define FIELD_XMLPACKET                        63
+/*      FIELD_CUSTOM (see tiffio.h)     65 */
 /* end of support for well-known tags; codec-private tags follow */
 /* end of support for well-known tags; codec-private tags follow */
-#define        FIELD_CODEC                     55      /* base of codec-private tags */
+#define        FIELD_CODEC                     66      /* base of codec-private tags */
+
+
 /*
  * Pseudo-tags don't normally need field bits since they
  * are not written to an output file (by definition).
 /*
  * Pseudo-tags don't normally need field bits since they
  * are not written to an output file (by definition).
@@ -210,23 +235,6 @@ typedef    struct {
         ((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \
        (v) & (tif)->tif_typemask[type]))
 
         ((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \
        (v) & (tif)->tif_typemask[type]))
 
-typedef        struct {
-       ttag_t  field_tag;              /* field's tag */
-       short   field_readcount;        /* read count/TIFF_VARIABLE/TIFF_SPP */
-       short   field_writecount;       /* write count/TIFF_VARIABLE */
-       TIFFDataType field_type;        /* type of associated data */
-       u_short field_bit;              /* bit in fieldsset bit vector */
-       u_char  field_oktochange;       /* if true, can change while writing */
-       u_char  field_passcount;        /* if true, pass dir count on set */
-       char    *field_name;            /* ASCII name */
-} TIFFFieldInfo;
-
-#define        TIFF_ANY        TIFF_NOTYPE     /* for field descriptor searching */
-#define        TIFF_VARIABLE   -1              /* marker for variable length tags */
-#define        TIFF_SPP        -2              /* marker for SamplesPerPixel tags */
-#define        TIFF_VARIABLE2  -3              /* marker for uint32 var-length tags */
-
-extern const int tiffDataWidth[];      /* table of tag datatype widths */
 
 #define BITn(n)                                (((u_long)1L)<<((n)&0x1f)) 
 #define BITFIELDn(tif, n)              ((tif)->tif_dir.td_fieldsset[(n)/32]) 
 
 #define BITn(n)                                (((u_long)1L)<<((n)&0x1f)) 
 #define BITFIELDn(tif, n)              ((tif)->tif_dir.td_fieldsset[(n)/32]) 
@@ -241,11 +249,18 @@ extern    const int tiffDataWidth[];      /* table of tag datatype widths */
 extern "C" {
 #endif
 extern void _TIFFSetupFieldInfo(TIFF*);
 extern "C" {
 #endif
 extern void _TIFFSetupFieldInfo(TIFF*);
-extern void _TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], int);
 extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
 extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
-extern const TIFFFieldInfo* _TIFFFindFieldInfo(TIFF*, ttag_t, TIFFDataType);
-extern const TIFFFieldInfo* _TIFFFieldWithTag(TIFF*, ttag_t);
 extern TIFFDataType _TIFFSampleToTagType(TIFF*);
 extern TIFFDataType _TIFFSampleToTagType(TIFF*);
+extern  const TIFFFieldInfo* _TIFFFindOrRegisterFieldInfo( TIFF *tif,
+                                                          ttag_t tag,
+                                                          TIFFDataType dt );
+extern  TIFFFieldInfo* _TIFFCreateAnonFieldInfo( TIFF *tif, ttag_t tag,
+                                                 TIFFDataType dt );
+
+#define _TIFFMergeFieldInfo TIFFMergeFieldInfo
+#define _TIFFFindFieldInfo  TIFFFindFieldInfo
+#define _TIFFFieldWithTag   TIFFFieldWithTag
+    
 #if defined(__cplusplus)
 }
 #endif
 #if defined(__cplusplus)
 }
 #endif
index b7494e4bbd1b8a6f2ee6be477a3222c2f5488240..c8a02e1f69bda8b5e1f722a3e5142c2293ce3494 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  */
 #include "tiffiop.h"
 #include <stdlib.h>
  */
 #include "tiffiop.h"
 #include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
 
 /*
  * NB: NB: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
  *     If a tag can have both LONG and SHORT types
  *     then the LONG must be placed before the SHORT for
  *     writing to work properly.
 
 /*
  * NB: NB: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
  *     If a tag can have both LONG and SHORT types
  *     then the LONG must be placed before the SHORT for
  *     writing to work properly.
+ *
+ * NOTE: The second field (field_readcount) and third field (field_writecount)
+ *       sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3)
+ *       and TIFFTAG_SPP (-2). The macros should be used but would throw off 
+ *       the formatting of the code, so please interprete the -1, -2 and -3 
+ *       values accordingly.
  */
  */
-static const TIFFFieldInfo tiffFieldInfo[] = {
+#ifndef VMS
+static 
+#endif
+const TIFFFieldInfo tiffFieldInfo[] = {
     { TIFFTAG_SUBFILETYPE,      1, 1, TIFF_LONG,       FIELD_SUBFILETYPE,
       TRUE,    FALSE,  "SubfileType" },
 /* XXX SHORT for compatibility w/ old versions of the library */
     { TIFFTAG_SUBFILETYPE,      1, 1, TIFF_LONG,       FIELD_SUBFILETYPE,
       TRUE,    FALSE,  "SubfileType" },
 /* XXX SHORT for compatibility w/ old versions of the library */
@@ -54,10 +65,19 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       TRUE,    FALSE,  "ImageLength" },
     { TIFFTAG_IMAGELENGTH,      1, 1, TIFF_SHORT,      FIELD_IMAGEDIMENSIONS,
       TRUE,    FALSE,  "ImageLength" },
       TRUE,    FALSE,  "ImageLength" },
     { TIFFTAG_IMAGELENGTH,      1, 1, TIFF_SHORT,      FIELD_IMAGEDIMENSIONS,
       TRUE,    FALSE,  "ImageLength" },
+/* XXX LONG for compatibility with some broken TIFF writers */
+    { TIFFTAG_BITSPERSAMPLE,   -1,-1, TIFF_LONG,       FIELD_BITSPERSAMPLE,
+      FALSE,   FALSE,  "BitsPerSample" },
     { TIFFTAG_BITSPERSAMPLE,   -1,-1, TIFF_SHORT,      FIELD_BITSPERSAMPLE,
       FALSE,   FALSE,  "BitsPerSample" },
     { TIFFTAG_BITSPERSAMPLE,   -1,-1, TIFF_SHORT,      FIELD_BITSPERSAMPLE,
       FALSE,   FALSE,  "BitsPerSample" },
+/* XXX LONG for compatibility with some broken TIFF writers */
+    { TIFFTAG_COMPRESSION,     -1, 1, TIFF_LONG,       FIELD_COMPRESSION,
+      FALSE,   FALSE,  "Compression" },
     { TIFFTAG_COMPRESSION,     -1, 1, TIFF_SHORT,      FIELD_COMPRESSION,
       FALSE,   FALSE,  "Compression" },
     { TIFFTAG_COMPRESSION,     -1, 1, TIFF_SHORT,      FIELD_COMPRESSION,
       FALSE,   FALSE,  "Compression" },
+/* XXX LONG for compatibility with some broken TIFF writers */
+    { TIFFTAG_PHOTOMETRIC,      1, 1, TIFF_LONG,       FIELD_PHOTOMETRIC,
+      FALSE,   FALSE,  "PhotometricInterpretation" },
     { TIFFTAG_PHOTOMETRIC,      1, 1, TIFF_SHORT,      FIELD_PHOTOMETRIC,
       FALSE,   FALSE,  "PhotometricInterpretation" },
     { TIFFTAG_THRESHHOLDING,    1, 1, TIFF_SHORT,      FIELD_THRESHHOLDING,
     { TIFFTAG_PHOTOMETRIC,      1, 1, TIFF_SHORT,      FIELD_PHOTOMETRIC,
       FALSE,   FALSE,  "PhotometricInterpretation" },
     { TIFFTAG_THRESHHOLDING,    1, 1, TIFF_SHORT,      FIELD_THRESHHOLDING,
@@ -122,11 +142,9 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       TRUE,    FALSE,  "PageNumber" },
     { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT,     FIELD_IGNORE,
       TRUE,    FALSE,  "ColorResponseUnit" },
       TRUE,    FALSE,  "PageNumber" },
     { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT,     FIELD_IGNORE,
       TRUE,    FALSE,  "ColorResponseUnit" },
-#ifdef COLORIMETRY_SUPPORT
     { TIFFTAG_TRANSFERFUNCTION,        -1,-1, TIFF_SHORT,      FIELD_TRANSFERFUNCTION,
       TRUE,    FALSE,  "TransferFunction" },
     { TIFFTAG_TRANSFERFUNCTION,        -1,-1, TIFF_SHORT,      FIELD_TRANSFERFUNCTION,
       TRUE,    FALSE,  "TransferFunction" },
-#endif
-    { TIFFTAG_SOFTWARE,                -1,-1, TIFF_ASCII,      FIELD_SOFTWARE,
+    { TIFFTAG_SOFTWARE,                -1,-1, TIFF_ASCII,      FIELD_CUSTOM,
       TRUE,    FALSE,  "Software" },
     { TIFFTAG_DATETIME,                20,20, TIFF_ASCII,      FIELD_DATETIME,
       TRUE,    FALSE,  "DateTime" },
       TRUE,    FALSE,  "Software" },
     { TIFFTAG_DATETIME,                20,20, TIFF_ASCII,      FIELD_DATETIME,
       TRUE,    FALSE,  "DateTime" },
@@ -134,12 +152,10 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       TRUE,    FALSE,  "Artist" },
     { TIFFTAG_HOSTCOMPUTER,    -1,-1, TIFF_ASCII,      FIELD_HOSTCOMPUTER,
       TRUE,    FALSE,  "HostComputer" },
       TRUE,    FALSE,  "Artist" },
     { TIFFTAG_HOSTCOMPUTER,    -1,-1, TIFF_ASCII,      FIELD_HOSTCOMPUTER,
       TRUE,    FALSE,  "HostComputer" },
-#ifdef COLORIMETRY_SUPPORT
     { TIFFTAG_WHITEPOINT,       2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT,
       TRUE,    FALSE,  "WhitePoint" },
     { TIFFTAG_PRIMARYCHROMATICITIES,6,6,TIFF_RATIONAL,FIELD_PRIMARYCHROMAS,
       TRUE,    FALSE,  "PrimaryChromaticities" },
     { TIFFTAG_WHITEPOINT,       2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT,
       TRUE,    FALSE,  "WhitePoint" },
     { TIFFTAG_PRIMARYCHROMATICITIES,6,6,TIFF_RATIONAL,FIELD_PRIMARYCHROMAS,
       TRUE,    FALSE,  "PrimaryChromaticities" },
-#endif
     { TIFFTAG_COLORMAP,                -1,-1, TIFF_SHORT,      FIELD_COLORMAP,
       TRUE,    FALSE,  "ColorMap" },
     { TIFFTAG_HALFTONEHINTS,    2, 2, TIFF_SHORT,      FIELD_HALFTONEHINTS,
     { TIFFTAG_COLORMAP,                -1,-1, TIFF_SHORT,      FIELD_COLORMAP,
       TRUE,    FALSE,  "ColorMap" },
     { TIFFTAG_HALFTONEHINTS,    2, 2, TIFF_SHORT,      FIELD_HALFTONEHINTS,
@@ -158,11 +174,8 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       FALSE,   FALSE,  "TileByteCounts" },
     { TIFFTAG_TILEBYTECOUNTS,  -1, 1, TIFF_SHORT,      FIELD_STRIPBYTECOUNTS,
       FALSE,   FALSE,  "TileByteCounts" },
       FALSE,   FALSE,  "TileByteCounts" },
     { TIFFTAG_TILEBYTECOUNTS,  -1, 1, TIFF_SHORT,      FIELD_STRIPBYTECOUNTS,
       FALSE,   FALSE,  "TileByteCounts" },
-#ifdef TIFFTAG_SUBIFD
     { TIFFTAG_SUBIFD,          -1,-1, TIFF_LONG,       FIELD_SUBIFD,
       TRUE,    TRUE,   "SubIFD" },
     { TIFFTAG_SUBIFD,          -1,-1, TIFF_LONG,       FIELD_SUBIFD,
       TRUE,    TRUE,   "SubIFD" },
-#endif
-#ifdef CMYK_SUPPORT            /* 6.0 CMYK tags */
     { TIFFTAG_INKSET,           1, 1, TIFF_SHORT,      FIELD_INKSET,
       FALSE,   FALSE,  "InkSet" },
     { TIFFTAG_INKNAMES,                -1,-1, TIFF_ASCII,      FIELD_INKNAMES,
     { TIFFTAG_INKSET,           1, 1, TIFF_SHORT,      FIELD_INKSET,
       FALSE,   FALSE,  "InkSet" },
     { TIFFTAG_INKNAMES,                -1,-1, TIFF_ASCII,      FIELD_INKNAMES,
@@ -175,7 +188,6 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       FALSE,   FALSE,  "DotRange" },
     { TIFFTAG_TARGETPRINTER,   -1,-1, TIFF_ASCII,      FIELD_TARGETPRINTER,
       TRUE,    FALSE,  "TargetPrinter" },
       FALSE,   FALSE,  "DotRange" },
     { TIFFTAG_TARGETPRINTER,   -1,-1, TIFF_ASCII,      FIELD_TARGETPRINTER,
       TRUE,    FALSE,  "TargetPrinter" },
-#endif
     { TIFFTAG_EXTRASAMPLES,    -1,-1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
       FALSE,   FALSE,  "ExtraSamples" },
 /* XXX for bogus Adobe Photoshop v2.5 files */
     { TIFFTAG_EXTRASAMPLES,    -1,-1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
       FALSE,   FALSE,  "ExtraSamples" },
 /* XXX for bogus Adobe Photoshop v2.5 files */
@@ -187,21 +199,19 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
       TRUE,    FALSE,  "SMinSampleValue" },
     { TIFFTAG_SMAXSAMPLEVALUE, -2,-1, TIFF_ANY,        FIELD_SMAXSAMPLEVALUE,
       TRUE,    FALSE,  "SMaxSampleValue" },
       TRUE,    FALSE,  "SMinSampleValue" },
     { TIFFTAG_SMAXSAMPLEVALUE, -2,-1, TIFF_ANY,        FIELD_SMAXSAMPLEVALUE,
       TRUE,    FALSE,  "SMaxSampleValue" },
-#ifdef YCBCR_SUPPORT           /* 6.0 YCbCr tags */
     { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL,  FIELD_YCBCRCOEFFICIENTS,
       FALSE,   FALSE,  "YCbCrCoefficients" },
     { TIFFTAG_YCBCRSUBSAMPLING,         2, 2, TIFF_SHORT,      FIELD_YCBCRSUBSAMPLING,
       FALSE,   FALSE,  "YCbCrSubsampling" },
     { TIFFTAG_YCBCRPOSITIONING,         1, 1, TIFF_SHORT,      FIELD_YCBCRPOSITIONING,
       FALSE,   FALSE,  "YCbCrPositioning" },
     { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL,  FIELD_YCBCRCOEFFICIENTS,
       FALSE,   FALSE,  "YCbCrCoefficients" },
     { TIFFTAG_YCBCRSUBSAMPLING,         2, 2, TIFF_SHORT,      FIELD_YCBCRSUBSAMPLING,
       FALSE,   FALSE,  "YCbCrSubsampling" },
     { TIFFTAG_YCBCRPOSITIONING,         1, 1, TIFF_SHORT,      FIELD_YCBCRPOSITIONING,
       FALSE,   FALSE,  "YCbCrPositioning" },
-#endif
-#ifdef COLORIMETRY_SUPPORT
     { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL,   FIELD_REFBLACKWHITE,
       TRUE,    FALSE,  "ReferenceBlackWhite" },
 /* XXX temporarily accept LONG for backwards compatibility */
     { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG,       FIELD_REFBLACKWHITE,
       TRUE,    FALSE,  "ReferenceBlackWhite" },
     { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL,   FIELD_REFBLACKWHITE,
       TRUE,    FALSE,  "ReferenceBlackWhite" },
 /* XXX temporarily accept LONG for backwards compatibility */
     { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG,       FIELD_REFBLACKWHITE,
       TRUE,    FALSE,  "ReferenceBlackWhite" },
-#endif
+    { TIFFTAG_XMLPACKET,       -1,-3, TIFF_UNDEFINED,  FIELD_XMLPACKET,
+      FALSE,   TRUE,   "XMLPacket" },
 /* begin SGI tags */
     { TIFFTAG_MATTEING,                 1, 1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
       FALSE,   FALSE,  "Matteing" },
 /* begin SGI tags */
     { TIFFTAG_MATTEING,                 1, 1, TIFF_SHORT,      FIELD_EXTRASAMPLES,
       FALSE,   FALSE,  "Matteing" },
@@ -216,25 +226,37 @@ static const TIFFFieldInfo tiffFieldInfo[] = {
     { TIFFTAG_TILEDEPTH,        1, 1, TIFF_SHORT,      FIELD_TILEDEPTH,
       FALSE,   FALSE,  "TileDepth" },
 /* end SGI tags */
     { TIFFTAG_TILEDEPTH,        1, 1, TIFF_SHORT,      FIELD_TILEDEPTH,
       FALSE,   FALSE,  "TileDepth" },
 /* end SGI tags */
+/* begin Pixar tags */
+    { TIFFTAG_PIXAR_IMAGEFULLWIDTH,  1, 1, TIFF_LONG,  FIELD_IMAGEFULLWIDTH,
+      TRUE,    FALSE,  "ImageFullWidth" },
+    { TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG,  FIELD_IMAGEFULLLENGTH,
+      TRUE,    FALSE,  "ImageFullLength" },
+    { TIFFTAG_PIXAR_TEXTUREFORMAT,  -1,-1, TIFF_ASCII, FIELD_TEXTUREFORMAT,
+      TRUE,    FALSE,  "TextureFormat" },
+    { TIFFTAG_PIXAR_WRAPMODES,     -1,-1, TIFF_ASCII,  FIELD_WRAPMODES,
+      TRUE,    FALSE,  "TextureWrapModes" },
+    { TIFFTAG_PIXAR_FOVCOT,         1, 1, TIFF_FLOAT,  FIELD_FOVCOT,
+      TRUE,    FALSE,  "FieldOfViewCotan" },
+    { TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN,      16,16,  TIFF_FLOAT,
+      FIELD_MATRIX_WORLDTOSCREEN,      TRUE,   FALSE,  "MatrixWorldToScreen" },
+    { TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA,      16,16,  TIFF_FLOAT,
+       FIELD_MATRIX_WORLDTOCAMERA,     TRUE,   FALSE,  "MatrixWorldToCamera" },
+    { TIFFTAG_COPYRIGHT,       -1,-1, TIFF_ASCII,      FIELD_COPYRIGHT,
+      TRUE,    FALSE,  "Copyright" },
+/* end Pixar tags */
 #ifdef IPTC_SUPPORT
 #ifdef PHOTOSHOP_SUPPORT
 #ifdef IPTC_SUPPORT
 #ifdef PHOTOSHOP_SUPPORT
-    { TIFFTAG_RICHTIFFIPTC, -1,-1, TIFF_LONG,   FIELD_RICHTIFFIPTC,
+    { TIFFTAG_RICHTIFFIPTC, -1,-1, TIFF_LONG,   FIELD_RICHTIFFIPTC, 
       FALSE,    TRUE,   "RichTIFFIPTC" },
 #else
       FALSE,    TRUE,   "RichTIFFIPTC" },
 #else
-    { TIFFTAG_RICHTIFFIPTC, -1,-3, TIFF_UNDEFINED, FIELD_RICHTIFFIPTC,
+    { TIFFTAG_RICHTIFFIPTC, -1,-3, TIFF_UNDEFINED, FIELD_RICHTIFFIPTC, 
       FALSE,    TRUE,   "RichTIFFIPTC" },
 #endif
 #endif
       FALSE,    TRUE,   "RichTIFFIPTC" },
 #endif
 #endif
-#ifdef PHOTOSHOP_SUPPORT
-    { TIFFTAG_PHOTOSHOP,    -1,-3, TIFF_UNDEFINED, FIELD_PHOTOSHOP,
-      FALSE,    TRUE,   "Photoshop" },
-    { TIFFTAG_PHOTOSHOP,    -1,-1, TIFF_BYTE,   FIELD_PHOTOSHOP,
+    { TIFFTAG_PHOTOSHOP,    -1,-3, TIFF_BYTE,   FIELD_PHOTOSHOP, 
       FALSE,    TRUE,   "Photoshop" },
       FALSE,    TRUE,   "Photoshop" },
-#endif
-#ifdef ICC_SUPPORT
     { TIFFTAG_ICCPROFILE,      -1,-3, TIFF_UNDEFINED,  FIELD_ICCPROFILE,
       FALSE,   TRUE,   "ICC Profile" },
     { TIFFTAG_ICCPROFILE,      -1,-3, TIFF_UNDEFINED,  FIELD_ICCPROFILE,
       FALSE,   TRUE,   "ICC Profile" },
-#endif
     { TIFFTAG_STONITS,          1, 1, TIFF_DOUBLE,     FIELD_STONITS,
       FALSE,   FALSE,  "StoNits" },
 };
     { TIFFTAG_STONITS,          1, 1, TIFF_DOUBLE,     FIELD_STONITS,
       FALSE,   FALSE,  "StoNits" },
 };
@@ -244,13 +266,26 @@ void
 _TIFFSetupFieldInfo(TIFF* tif)
 {
        if (tif->tif_fieldinfo) {
 _TIFFSetupFieldInfo(TIFF* tif)
 {
        if (tif->tif_fieldinfo) {
+               int  i;
+
+               for (i = 0; i < tif->tif_nfields; i++) 
+               {
+                       TIFFFieldInfo *fld = tif->tif_fieldinfo[i];
+                       if (fld->field_bit == FIELD_CUSTOM && 
+                               strncmp("Tag ", fld->field_name, 4) == 0) 
+                               {
+                               _TIFFfree(fld->field_name);
+                               _TIFFfree(fld);
+                               }
+               }   
+      
                _TIFFfree(tif->tif_fieldinfo);
                tif->tif_nfields = 0;
        }
        _TIFFMergeFieldInfo(tif, tiffFieldInfo, N(tiffFieldInfo));
 }
 
                _TIFFfree(tif->tif_fieldinfo);
                tif->tif_nfields = 0;
        }
        _TIFFMergeFieldInfo(tif, tiffFieldInfo, N(tiffFieldInfo));
 }
 
-static int LINKAGEMODE
+static int
 tagCompare(const void* a, const void* b)
 {
        const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a;
 tagCompare(const void* a, const void* b)
 {
        const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a;
@@ -259,7 +294,7 @@ tagCompare(const void* a, const void* b)
        if (ta->field_tag != tb->field_tag)
                return (ta->field_tag < tb->field_tag ? -1 : 1);
        else
        if (ta->field_tag != tb->field_tag)
                return (ta->field_tag < tb->field_tag ? -1 : 1);
        else
-               return (tb->field_type < ta->field_type ? -1 : 1);
+               return ((int)tb->field_type - (int)ta->field_type);
 }
 
 void
 }
 
 void
@@ -276,17 +311,14 @@ _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n)
                tif->tif_fieldinfo = (TIFFFieldInfo**)
                    _TIFFmalloc(n * sizeof (TIFFFieldInfo*));
        }
                tif->tif_fieldinfo = (TIFFFieldInfo**)
                    _TIFFmalloc(n * sizeof (TIFFFieldInfo*));
        }
+       assert(tif->tif_fieldinfo != NULL);
        tp = &tif->tif_fieldinfo[tif->tif_nfields];
        for (i = 0; i < n; i++)
                tp[i] = (TIFFFieldInfo*) &info[i];      /* XXX */
        tp = &tif->tif_fieldinfo[tif->tif_nfields];
        for (i = 0; i < n; i++)
                tp[i] = (TIFFFieldInfo*) &info[i];      /* XXX */
-       /*
-        * NB: the core tags are presumed sorted correctly.
-        */
-       if (tif->tif_nfields > 0)
-               qsort(tif->tif_fieldinfo, (size_t) (tif->tif_nfields += n),
-                   sizeof (TIFFFieldInfo*), tagCompare);
-       else
-               tif->tif_nfields += n;
+
+        /* Sort the field info by tag number */
+        qsort(tif->tif_fieldinfo, (size_t) (tif->tif_nfields += n),
+              sizeof (TIFFFieldInfo*), tagCompare);
 }
 
 void
 }
 
 void
@@ -310,21 +342,36 @@ _TIFFPrintFieldInfo(TIFF* tif, FILE* fd)
        }
 }
 
        }
 }
 
-const int tiffDataWidth[] = {
-    1, /* nothing */
-    1, /* TIFF_BYTE */
-    1, /* TIFF_ASCII */
-    2, /* TIFF_SHORT */
-    4, /* TIFF_LONG */
-    8, /* TIFF_RATIONAL */
-    1, /* TIFF_SBYTE */
-    1, /* TIFF_UNDEFINED */
-    2, /* TIFF_SSHORT */
-    4, /* TIFF_SLONG */
-    8, /* TIFF_SRATIONAL */
-    4, /* TIFF_FLOAT */
-    8, /* TIFF_DOUBLE */
-};
+/*
+ * Return size of TIFFDataType in bytes
+ */
+int
+TIFFDataWidth(TIFFDataType type)
+{
+       switch(type)
+       {
+       case 0:  /* nothing */
+       case 1:  /* TIFF_BYTE */
+       case 2:  /* TIFF_ASCII */
+       case 6:  /* TIFF_SBYTE */
+       case 7:  /* TIFF_UNDEFINED */
+               return 1;
+       case 3:  /* TIFF_SHORT */
+       case 8:  /* TIFF_SSHORT */
+               return 2;
+       case 4:  /* TIFF_LONG */
+       case 9:  /* TIFF_SLONG */
+       case 11: /* TIFF_FLOAT */
+        case 13: /* TIFF_IFD */
+               return 4;
+       case 5:  /* TIFF_RATIONAL */
+       case 10: /* TIFF_SRATIONAL */
+       case 12: /* TIFF_DOUBLE */
+               return 8;
+       default:
+               return 0; /* will return 0 for unknown types */
+       }
+}
 
 /*
  * Return nearest TIFFDataType to the sample type of an image.
 
 /*
  * Return nearest TIFFDataType to the sample type of an image.
@@ -332,7 +379,7 @@ const int tiffDataWidth[] = {
 TIFFDataType
 _TIFFSampleToTagType(TIFF* tif)
 {
 TIFFDataType
 _TIFFSampleToTagType(TIFF* tif)
 {
-       int bps = (int) TIFFhowmany(tif->tif_dir.td_bitspersample, 8);
+       uint32 bps = TIFFhowmany8(tif->tif_dir.td_bitspersample);
 
        switch (tif->tif_dir.td_sampleformat) {
        case SAMPLEFORMAT_IEEEFP:
 
        switch (tif->tif_dir.td_sampleformat) {
        case SAMPLEFORMAT_IEEEFP:
@@ -360,7 +407,16 @@ _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt)
            (dt == TIFF_ANY || dt == last->field_type))
                return (last);
        /* NB: if table gets big, use sorted search (e.g. binary search) */
            (dt == TIFF_ANY || dt == last->field_type))
                return (last);
        /* NB: if table gets big, use sorted search (e.g. binary search) */
-       for (i = 0, n = tif->tif_nfields; i < n; i++) {
+       if(dt != TIFF_ANY) {
+            TIFFFieldInfo key = {0, 0, 0, 0, 0, 0, 0, 0};
+            key.field_tag = tag;
+            key.field_type = dt;
+            return((const TIFFFieldInfo *) bsearch(&key, 
+                                                  tif->tif_fieldinfo, 
+                                                  tif->tif_nfields,
+                                                  sizeof(TIFFFieldInfo), 
+                                                  tagCompare));
+        } else for (i = 0, n = tif->tif_nfields; i < n; i++) {
                const TIFFFieldInfo* fip = tif->tif_fieldinfo[i];
                if (fip->field_tag == tag &&
                    (dt == TIFF_ANY || fip->field_type == dt))
                const TIFFFieldInfo* fip = tif->tif_fieldinfo[i];
                if (fip->field_tag == tag &&
                    (dt == TIFF_ANY || fip->field_type == dt))
@@ -369,9 +425,6 @@ _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt)
        return ((const TIFFFieldInfo *)0);
 }
 
        return ((const TIFFFieldInfo *)0);
 }
 
-#include <assert.h>
-#include <stdio.h>
-
 const TIFFFieldInfo*
 _TIFFFieldWithTag(TIFF* tif, ttag_t tag)
 {
 const TIFFFieldInfo*
 _TIFFFieldWithTag(TIFF* tif, ttag_t tag)
 {
@@ -384,3 +437,50 @@ _TIFFFieldWithTag(TIFF* tif, ttag_t tag)
        }
        return (fip);
 }
        }
        return (fip);
 }
+
+const TIFFFieldInfo*
+_TIFFFindOrRegisterFieldInfo( TIFF *tif, ttag_t tag, TIFFDataType dt )
+
+{
+    const TIFFFieldInfo *fld;
+
+    fld = _TIFFFindFieldInfo( tif, tag, dt );
+    if( fld == NULL )
+    {
+        fld = _TIFFCreateAnonFieldInfo( tif, tag, dt );
+        _TIFFMergeFieldInfo( tif, fld, 1 );
+    }
+
+    return fld;
+}
+
+TIFFFieldInfo*
+_TIFFCreateAnonFieldInfo(TIFF *tif, ttag_t tag, TIFFDataType field_type)
+{
+    TIFFFieldInfo *fld;
+
+    fld = (TIFFFieldInfo *) _TIFFmalloc(sizeof (TIFFFieldInfo));
+    if (fld == NULL)
+       return NULL;
+    _TIFFmemset( fld, 0, sizeof(TIFFFieldInfo) );
+
+    fld->field_tag = tag;
+    fld->field_readcount = TIFF_VARIABLE;
+    fld->field_writecount = TIFF_VARIABLE;
+    fld->field_type = field_type;
+    fld->field_bit = FIELD_CUSTOM;
+    fld->field_oktochange = TRUE;
+    fld->field_passcount = TRUE;
+    fld->field_name = (char *) _TIFFmalloc(32);
+    if (fld->field_name == NULL) {
+       _TIFFfree(fld);
+       return NULL;
+    }
+
+    /* note that this name is a special sign to TIFFClose() and
+     * _TIFFSetupFieldInfo() to free the field
+     */
+    sprintf(fld->field_name, "Tag %d", (int) tag);
+
+    return fld;    
+}
index 1cf72f94b2a67dc669eb8dfdfe0a3a8401d7d164..4c4991a62a6f09c8a76652f00a8d0d269dac2f09 100644 (file)
@@ -41,7 +41,7 @@ extern        void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*);
 extern void TIFFCvtIEEEDoubleToNative(TIFF*, uint32, double*);
 #endif
 
 extern void TIFFCvtIEEEDoubleToNative(TIFF*, uint32, double*);
 #endif
 
-static void EstimateStripByteCounts(TIFF*, TIFFDirEntry*, uint16);
+static int EstimateStripByteCounts(TIFF*, TIFFDirEntry*, uint16);
 static void MissingRequired(TIFF*, const char*);
 static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32);
 static tsize_t TIFFFetchData(TIFF*, TIFFDirEntry*, char*);
 static void MissingRequired(TIFF*, const char*);
 static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32);
 static tsize_t TIFFFetchData(TIFF*, TIFFDirEntry*, char*);
@@ -62,11 +62,17 @@ static      int TIFFFetchShortPair(TIFF*, TIFFDirEntry*);
 static void ChopUpSingleUncompressedStrip(TIFF*);
 
 static char *
 static void ChopUpSingleUncompressedStrip(TIFF*);
 
 static char *
-CheckMalloc(TIFF* tif, tsize_t n, const char* what)
+CheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what)
 {
 {
-       char *cp = (char*)_TIFFmalloc(n);
+       char    *cp = NULL;
+       tsize_t bytes = nmemb * elem_size;
+
+       if (elem_size && bytes / elem_size == nmemb)
+               cp = (char*)_TIFFmalloc(bytes);
+
        if (cp == NULL)
                TIFFError(tif->tif_name, "No space %s", what);
        if (cp == NULL)
                TIFFError(tif->tif_name, "No space %s", what);
+       
        return (cp);
 }
 
        return (cp);
 }
 
@@ -78,6 +84,8 @@ CheckMalloc(TIFF* tif, tsize_t n, const char* what)
 int
 TIFFReadDirectory(TIFF* tif)
 {
 int
 TIFFReadDirectory(TIFF* tif)
 {
+       static const char module[] = "TIFFReadDirectory";
+
        register TIFFDirEntry* dp;
        register int n;
        register TIFFDirectory* td;
        register TIFFDirEntry* dp;
        register int n;
        register TIFFDirectory* td;
@@ -88,13 +96,36 @@ TIFFReadDirectory(TIFF* tif)
        const TIFFFieldInfo* fip;
        int fix;
        uint16 dircount;
        const TIFFFieldInfo* fip;
        int fix;
        uint16 dircount;
-       uint32 nextdiroff;
+       toff_t nextdiroff;
        char* cp;
        int diroutoforderwarning = 0;
        char* cp;
        int diroutoforderwarning = 0;
+       toff_t* new_dirlist;
 
        tif->tif_diroff = tif->tif_nextdiroff;
        if (tif->tif_diroff == 0)               /* no more directories */
                return (0);
 
        tif->tif_diroff = tif->tif_nextdiroff;
        if (tif->tif_diroff == 0)               /* no more directories */
                return (0);
+
+       /*
+        * XXX: Trick to prevent IFD looping. The one can create TIFF file
+        * with looped directory pointers. We will maintain a list of already
+        * seen directories and check every IFD offset against this list.
+        */
+       for (n = 0; n < tif->tif_dirnumber; n++) {
+               if (tif->tif_dirlist[n] == tif->tif_diroff)
+                       return (0);
+       }
+       tif->tif_dirnumber++;
+       new_dirlist = _TIFFrealloc(tif->tif_dirlist,
+                                  tif->tif_dirnumber * sizeof(toff_t));
+       if (!new_dirlist) {
+               TIFFError(module,
+                         "%.1000s: Failed to allocate space for IFD list",
+                         tif->tif_name);
+               return (0);
+       }
+       tif->tif_dirlist = new_dirlist;
+       tif->tif_dirlist[tif->tif_dirnumber - 1] = tif->tif_diroff;
+
        /*
         * Cleanup any previous compression state.
         */
        /*
         * Cleanup any previous compression state.
         */
@@ -103,23 +134,27 @@ TIFFReadDirectory(TIFF* tif)
        nextdiroff = 0;
        if (!isMapped(tif)) {
                if (!SeekOK(tif, tif->tif_diroff)) {
        nextdiroff = 0;
        if (!isMapped(tif)) {
                if (!SeekOK(tif, tif->tif_diroff)) {
-                       TIFFError(tif->tif_name,
-                           "Seek error accessing TIFF directory");
+                       TIFFError(module,
+                           "%.1000s: Seek error accessing TIFF directory",
+                            tif->tif_name);
                        return (0);
                }
                if (!ReadOK(tif, &dircount, sizeof (uint16))) {
                        return (0);
                }
                if (!ReadOK(tif, &dircount, sizeof (uint16))) {
-                       TIFFError(tif->tif_name,
-                           "Can not read TIFF directory count");
+                       TIFFError(module,
+                           "%.1000s: Can not read TIFF directory count",
+                            tif->tif_name);
                        return (0);
                }
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&dircount);
                dir = (TIFFDirEntry *)CheckMalloc(tif,
                        return (0);
                }
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&dircount);
                dir = (TIFFDirEntry *)CheckMalloc(tif,
-                   dircount * sizeof (TIFFDirEntry), "to read TIFF directory");
+                   dircount, sizeof (TIFFDirEntry), "to read TIFF directory");
                if (dir == NULL)
                        return (0);
                if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) {
                if (dir == NULL)
                        return (0);
                if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) {
-                       TIFFError(tif->tif_name, "Can not read TIFF directory");
+                       TIFFError(module,
+                                  "%.100s: Can not read TIFF directory",
+                                  tif->tif_name);
                        goto bad;
                }
                /*
                        goto bad;
                }
                /*
@@ -130,8 +165,9 @@ TIFFReadDirectory(TIFF* tif)
                toff_t off = tif->tif_diroff;
 
                if (off + sizeof (uint16) > tif->tif_size) {
                toff_t off = tif->tif_diroff;
 
                if (off + sizeof (uint16) > tif->tif_size) {
-                       TIFFError(tif->tif_name,
-                           "Can not read TIFF directory count");
+                       TIFFError(module,
+                           "%.1000s: Can not read TIFF directory count",
+                            tif->tif_name);
                        return (0);
                } else
                        _TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16));
                        return (0);
                } else
                        _TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16));
@@ -139,15 +175,18 @@ TIFFReadDirectory(TIFF* tif)
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&dircount);
                dir = (TIFFDirEntry *)CheckMalloc(tif,
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&dircount);
                dir = (TIFFDirEntry *)CheckMalloc(tif,
-                   dircount * sizeof (TIFFDirEntry), "to read TIFF directory");
+                   dircount, sizeof (TIFFDirEntry), "to read TIFF directory");
                if (dir == NULL)
                        return (0);
                if (off + dircount*sizeof (TIFFDirEntry) > tif->tif_size) {
                if (dir == NULL)
                        return (0);
                if (off + dircount*sizeof (TIFFDirEntry) > tif->tif_size) {
-                       TIFFError(tif->tif_name, "Can not read TIFF directory");
+                       TIFFError(module,
+                                  "%.1000s: Can not read TIFF directory",
+                                  tif->tif_name);
                        goto bad;
                        goto bad;
-               } else
+               } else {
                        _TIFFmemcpy(dir, tif->tif_base + off,
                        _TIFFmemcpy(dir, tif->tif_base + off,
-                           dircount*sizeof (TIFFDirEntry));
+                                   dircount*sizeof (TIFFDirEntry));
+               }
                off += dircount* sizeof (TIFFDirEntry);
                if (off + sizeof (uint32) <= tif->tif_size)
                        _TIFFmemcpy(&nextdiroff, tif->tif_base+off, sizeof (uint32));
                off += dircount* sizeof (TIFFDirEntry);
                if (off + sizeof (uint32) <= tif->tif_size)
                        _TIFFmemcpy(&nextdiroff, tif->tif_base+off, sizeof (uint32));
@@ -218,9 +257,9 @@ TIFFReadDirectory(TIFF* tif)
                if( TIFFReassignTagToIgnore(TIS_EXTRACT, dp->tdir_tag) )
                     dp->tdir_tag = IGNORE;
 
                if( TIFFReassignTagToIgnore(TIS_EXTRACT, dp->tdir_tag) )
                     dp->tdir_tag = IGNORE;
 
-               if (dp->tdir_tag == IGNORE)
-                    continue;
-                
+               if (fix >= tif->tif_nfields || dp->tdir_tag == IGNORE)
+                       continue;
+               
                /*
                 * Silicon Beach (at least) writes unordered
                 * directory tags (violating the spec).  Handle
                /*
                 * Silicon Beach (at least) writes unordered
                 * directory tags (violating the spec).  Handle
@@ -228,23 +267,32 @@ TIFFReadDirectory(TIFF* tif)
                 */
                if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) {
                        if (!diroutoforderwarning) {
                 */
                if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) {
                        if (!diroutoforderwarning) {
-                               TIFFWarning(tif->tif_name,
-       "invalid TIFF directory; tags are not sorted in ascending order");
+                               TIFFWarning(module,
+"%.1000s: invalid TIFF directory; tags are not sorted in ascending order",
+                                            tif->tif_name);
                                diroutoforderwarning = 1;
                        }
                        fix = 0;                        /* O(n^2) */
                }
                while (fix < tif->tif_nfields &&
                                diroutoforderwarning = 1;
                        }
                        fix = 0;                        /* O(n^2) */
                }
                while (fix < tif->tif_nfields &&
-                   tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
+                      tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
                        fix++;
                        fix++;
-               if (fix == tif->tif_nfields ||
+               if (fix >= tif->tif_nfields ||
                    tif->tif_fieldinfo[fix]->field_tag != dp->tdir_tag) {
                    tif->tif_fieldinfo[fix]->field_tag != dp->tdir_tag) {
-                       TIFFWarning(tif->tif_name,
-                           "unknown field with tag %d (0x%x) ignored",
-                           dp->tdir_tag,  dp->tdir_tag);
-                       dp->tdir_tag = IGNORE;
-                       fix = 0;                        /* restart search */
-                       continue;
+
+                    TIFFWarning(module,
+                       "%.1000s: unknown field with tag %d (0x%x) encountered",
+                                tif->tif_name, dp->tdir_tag,  dp->tdir_tag);
+
+                    TIFFMergeFieldInfo( tif,
+                                        _TIFFCreateAnonFieldInfo( tif,
+                                              dp->tdir_tag,
+                                             (TIFFDataType) dp->tdir_type ),
+                                        1 );
+                    fix = 0;
+                    while (fix < tif->tif_nfields &&
+                           tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag)
+                       fix++;
                }
                /*
                 * Null out old tags that we ignore.
                }
                /*
                 * Null out old tags that we ignore.
@@ -264,9 +312,10 @@ TIFFReadDirectory(TIFF* tif)
                        fip++, fix++;
                        if (fix == tif->tif_nfields ||
                            fip->field_tag != dp->tdir_tag) {
                        fip++, fix++;
                        if (fix == tif->tif_nfields ||
                            fip->field_tag != dp->tdir_tag) {
-                               TIFFWarning(tif->tif_name,
-                                  "wrong data type %d for \"%s\"; tag ignored",
-                                   dp->tdir_type, fip[-1].field_name);
+                               TIFFWarning(module,
+                       "%.1000s: wrong data type %d for \"%s\"; tag ignored",
+                                           tif->tif_name, dp->tdir_type,
+                                           fip[-1].field_name);
                                goto ignore;
                        }
                }
                                goto ignore;
                        }
                }
@@ -350,6 +399,11 @@ TIFFReadDirectory(TIFF* tif)
                td->td_nstrips = TIFFNumberOfTiles(tif);
                tif->tif_flags |= TIFF_ISTILED;
        }
                td->td_nstrips = TIFFNumberOfTiles(tif);
                tif->tif_flags |= TIFF_ISTILED;
        }
+       if (!td->td_nstrips) {
+               TIFFError(module, "%s: cannot handle zero number of %s",
+                         tif->tif_name, isTiled(tif) ? "tiles" : "strips");
+               goto bad;
+       }
        td->td_stripsperimage = td->td_nstrips;
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
                td->td_stripsperimage /= td->td_samplesperpixel;
        td->td_stripsperimage = td->td_nstrips;
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
                td->td_stripsperimage /= td->td_samplesperpixel;
@@ -426,7 +480,7 @@ TIFFReadDirectory(TIFF* tif)
                                        break;
                        }
                        v *= sizeof (uint16);
                                        break;
                        }
                        v *= sizeof (uint16);
-                       cp = CheckMalloc(tif, dp->tdir_count * sizeof (uint16),
+                       cp = CheckMalloc(tif, dp->tdir_count, sizeof (uint16),
                            "to read \"TransferFunction\" tag");
                        if (cp != NULL) {
                                if (TIFFFetchData(tif, dp, cp)) {
                            "to read \"TransferFunction\" tag");
                        if (cp != NULL) {
                                if (TIFFFetchData(tif, dp, cp)) {
@@ -501,14 +555,23 @@ TIFFReadDirectory(TIFF* tif)
                    MissingRequired(tif, "StripByteCounts");
                    goto bad;
                }
                    MissingRequired(tif, "StripByteCounts");
                    goto bad;
                }
-               TIFFWarning(tif->tif_name,
-"TIFF directory is missing required \"%s\" field, calculating from imagelength",
-                   _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
-               EstimateStripByteCounts(tif, dir, dircount);
+               TIFFWarning(module,
+                       "%.1000s: TIFF directory is missing required "
+                       "\"%s\" field, calculating from imagelength",
+                       tif->tif_name,
+                       _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
+               if (EstimateStripByteCounts(tif, dir, dircount) < 0)
+                   goto bad;
+/* 
+ * Assume we have wrong StripByteCount value (in case of single strip) in
+ * following cases:
+ *   - it is equal to zero along with StripOffset;
+ *   - it is larger than file itself (in case of uncompressed image).
+ */
 #define        BYTECOUNTLOOKSBAD \
 #define        BYTECOUNTLOOKSBAD \
-    (td->td_stripbytecount[0] == 0 || \
-    (td->td_compression == COMPRESSION_NONE && \
-     td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]))
+    ( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \
+      (td->td_compression == COMPRESSION_NONE && \
+       td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) )
        } else if (td->td_nstrips == 1 && BYTECOUNTLOOKSBAD) {
                /*
                 * Plexus (and others) sometimes give a value
        } else if (td->td_nstrips == 1 && BYTECOUNTLOOKSBAD) {
                /*
                 * Plexus (and others) sometimes give a value
@@ -517,13 +580,17 @@ TIFFReadDirectory(TIFF* tif)
                 * simple case of estimating the size of a one
                 * strip image.
                 */
                 * simple case of estimating the size of a one
                 * strip image.
                 */
-               TIFFWarning(tif->tif_name,
-           "Bogus \"%s\" field, ignoring and calculating from imagelength",
-                   _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
-               EstimateStripByteCounts(tif, dir, dircount);
+               TIFFWarning(module,
+       "%.1000s: Bogus \"%s\" field, ignoring and calculating from imagelength",
+                            tif->tif_name,
+                           _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);
+               if(EstimateStripByteCounts(tif, dir, dircount) < 0)
+                   goto bad;
        }
        }
-       if (dir)
+       if (dir) {
                _TIFFfree((char *)dir);
                _TIFFfree((char *)dir);
+               dir = NULL;
+       }
        if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
                td->td_maxsamplevalue = (uint16)((1L<<td->td_bitspersample)-1);
        /*
        if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
                td->td_maxsamplevalue = (uint16)((1L<<td->td_bitspersample)-1);
        /*
@@ -552,6 +619,17 @@ TIFFReadDirectory(TIFF* tif)
        tif->tif_curtile = (ttile_t) -1;
        tif->tif_tilesize = TIFFTileSize(tif);
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
        tif->tif_curtile = (ttile_t) -1;
        tif->tif_tilesize = TIFFTileSize(tif);
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
+
+       if (!tif->tif_tilesize) {
+               TIFFError(module, "%s: cannot handle zero tile size",
+                         tif->tif_name);
+               return (0);
+       }
+       if (!tif->tif_scanlinesize) {
+               TIFFError(module, "%s: cannot handle zero scanline size",
+                         tif->tif_name);
+               return (0);
+       }
        return (1);
 bad:
        if (dir)
        return (1);
 bad:
        if (dir)
@@ -559,9 +637,11 @@ bad:
        return (0);
 }
 
        return (0);
 }
 
-static void
+static int
 EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
 {
 EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
 {
+       static const char module[] = "EstimateStripByteCounts";
+
        register TIFFDirEntry *dp;
        register TIFFDirectory *td = &tif->tif_dir;
        uint16 i;
        register TIFFDirEntry *dp;
        register TIFFDirectory *td = &tif->tif_dir;
        uint16 i;
@@ -569,7 +649,7 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
        if (td->td_stripbytecount)
                _TIFFfree(td->td_stripbytecount);
        td->td_stripbytecount = (uint32*)
        if (td->td_stripbytecount)
                _TIFFfree(td->td_stripbytecount);
        td->td_stripbytecount = (uint32*)
-           CheckMalloc(tif, td->td_nstrips * sizeof (uint32),
+           CheckMalloc(tif, td->td_nstrips, sizeof (uint32),
                "for \"StripByteCounts\" array");
        if (td->td_compression != COMPRESSION_NONE) {
                uint32 space = (uint32)(sizeof (TIFFHeader)
                "for \"StripByteCounts\" array");
        if (td->td_compression != COMPRESSION_NONE) {
                uint32 space = (uint32)(sizeof (TIFFHeader)
@@ -580,8 +660,16 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
                uint16 n;
 
                /* calculate amount of space used by indirect values */
                uint16 n;
 
                /* calculate amount of space used by indirect values */
-               for (dp = dir, n = dircount; n > 0; n--, dp++) {
-                       uint32 cc = dp->tdir_count*tiffDataWidth[dp->tdir_type];
+               for (dp = dir, n = dircount; n > 0; n--, dp++)
+               {
+                       uint32 cc = TIFFDataWidth((TIFFDataType) dp->tdir_type);
+                       if (cc == 0) {
+                               TIFFError(module,
+                       "%.1000s: Cannot determine size of unknown tag type %d",
+                                         tif->tif_name, dp->tdir_type);
+                               return -1;
+                       }
+                       cc = cc * dp->tdir_count;
                        if (cc > sizeof (uint32))
                                space += cc;
                }
                        if (cc > sizeof (uint32))
                                space += cc;
                }
@@ -598,7 +686,8 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
                 * of data in the strip and trim this number back accordingly.
                 */ 
                i--;
                 * of data in the strip and trim this number back accordingly.
                 */ 
                i--;
-               if (td->td_stripoffset[i] + td->td_stripbytecount[i] > filesize)
+               if (((toff_t)(td->td_stripoffset[i]+td->td_stripbytecount[i]))
+                                                               > filesize)
                        td->td_stripbytecount[i] =
                            filesize - td->td_stripoffset[i];
        } else {
                        td->td_stripbytecount[i] =
                            filesize - td->td_stripoffset[i];
        } else {
@@ -610,13 +699,17 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
        TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
        if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
                td->td_rowsperstrip = td->td_imagelength;
        TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
        if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
                td->td_rowsperstrip = td->td_imagelength;
+       return 1;
 }
 
 static void
 MissingRequired(TIFF* tif, const char* tagname)
 {
 }
 
 static void
 MissingRequired(TIFF* tif, const char* tagname)
 {
-       TIFFError(tif->tif_name,
-           "TIFF directory is missing required \"%s\" field", tagname);
+       static const char module[] = "MissingRequired";
+
+       TIFFError(module,
+                 "%.1000s: TIFF directory is missing required \"%s\" field",
+                 tif->tif_name, tagname);
 }
 
 /*
 }
 
 /*
@@ -644,7 +737,7 @@ CheckDirCount(TIFF* tif, TIFFDirEntry* dir, uint32 count)
 static tsize_t
 TIFFFetchData(TIFF* tif, TIFFDirEntry* dir, char* cp)
 {
 static tsize_t
 TIFFFetchData(TIFF* tif, TIFFDirEntry* dir, char* cp)
 {
-       int w = tiffDataWidth[dir->tdir_type];
+       int w = TIFFDataWidth((TIFFDataType) dir->tdir_type);
        tsize_t cc = dir->tdir_count * w;
 
        if (!isMapped(tif)) {
        tsize_t cc = dir->tdir_count * w;
 
        if (!isMapped(tif)) {
@@ -755,28 +848,44 @@ TIFFFetchFloat(TIFF* tif, TIFFDirEntry* dir)
 static int
 TIFFFetchByteArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
 {
 static int
 TIFFFetchByteArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
 {
-       if (dir->tdir_count <= 4) {
-               /*
-                * Extract data from offset field.
-                */
-               if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
-                       switch (dir->tdir_count) {
-                       case 4: v[3] = dir->tdir_offset & 0xff;
-                       case 3: v[2] = (dir->tdir_offset >> 8) & 0xff;
-                       case 2: v[1] = (dir->tdir_offset >> 16) & 0xff;
-                       case 1: v[0] = dir->tdir_offset >> 24;
-                       }
-               } else {
-                       switch (dir->tdir_count) {
-                       case 4: v[3] = dir->tdir_offset >> 24;
-                       case 3: v[2] = (dir->tdir_offset >> 16) & 0xff;
-                       case 2: v[1] = (dir->tdir_offset >> 8) & 0xff;
-                       case 1: v[0] = dir->tdir_offset & 0xff;
-                       }
+    if (dir->tdir_count <= 4) {
+        /*
+         * Extract data from offset field.
+         */
+        if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
+           if (dir->tdir_type == TIFF_SBYTE)
+                switch (dir->tdir_count) {
+                    case 4: v[3] = (signed char)(dir->tdir_offset & 0xff);
+                    case 3: v[2] = (signed char)((dir->tdir_offset >> 8) & 0xff);
+                    case 2: v[1] = (signed char)((dir->tdir_offset >> 16) & 0xff);
+                   case 1: v[0] = (signed char)(dir->tdir_offset >> 24);       
+                }
+           else
+                switch (dir->tdir_count) {
+                    case 4: v[3] = (uint16)(dir->tdir_offset & 0xff);
+                    case 3: v[2] = (uint16)((dir->tdir_offset >> 8) & 0xff);
+                    case 2: v[1] = (uint16)((dir->tdir_offset >> 16) & 0xff);
+                   case 1: v[0] = (uint16)(dir->tdir_offset >> 24);    
+                }
+       } else {
+           if (dir->tdir_type == TIFF_SBYTE)
+                switch (dir->tdir_count) {
+                    case 4: v[3] = (signed char)(dir->tdir_offset >> 24);
+                    case 3: v[2] = (signed char)((dir->tdir_offset >> 16) & 0xff);
+                    case 2: v[1] = (signed char)((dir->tdir_offset >> 8) & 0xff);
+                    case 1: v[0] = (signed char)(dir->tdir_offset & 0xff);
                }
                }
-               return (1);
-       } else
-               return (TIFFFetchData(tif, dir, (char*) v) != 0);       /* XXX */
+           else
+                switch (dir->tdir_count) {
+                    case 4: v[3] = (uint16)(dir->tdir_offset >> 24);
+                    case 3: v[2] = (uint16)((dir->tdir_offset >> 16) & 0xff);
+                    case 2: v[1] = (uint16)((dir->tdir_offset >> 8) & 0xff);
+                    case 1: v[0] = (uint16)(dir->tdir_offset & 0xff);
+               }
+       }
+        return (1);
+    } else
+        return (TIFFFetchData(tif, dir, (char*) v) != 0);      /* XXX */
 }
 
 /*
 }
 
 /*
@@ -788,13 +897,13 @@ TIFFFetchShortArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
        if (dir->tdir_count <= 2) {
                if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
                        switch (dir->tdir_count) {
        if (dir->tdir_count <= 2) {
                if (tif->tif_header.tiff_magic == TIFF_BIGENDIAN) {
                        switch (dir->tdir_count) {
-                       case 2: v[1] = dir->tdir_offset & 0xffff;
-                       case 1: v[0] = dir->tdir_offset >> 16;
+                       case 2: v[1] = (uint16) (dir->tdir_offset & 0xffff);
+                       case 1: v[0] = (uint16) (dir->tdir_offset >> 16);
                        }
                } else {
                        switch (dir->tdir_count) {
                        }
                } else {
                        switch (dir->tdir_count) {
-                       case 2: v[1] = dir->tdir_offset >> 16;
-                       case 1: v[0] = dir->tdir_offset & 0xffff;
+                       case 2: v[1] = (uint16) (dir->tdir_offset >> 16);
+                       case 1: v[0] = (uint16) (dir->tdir_offset & 0xffff);
                        }
                }
                return (1);
                        }
                }
                return (1);
@@ -808,7 +917,7 @@ TIFFFetchShortArray(TIFF* tif, TIFFDirEntry* dir, uint16* v)
 static int
 TIFFFetchShortPair(TIFF* tif, TIFFDirEntry* dir)
 {
 static int
 TIFFFetchShortPair(TIFF* tif, TIFFDirEntry* dir)
 {
-       uint16 v[2];
+       uint16 v[4];
        int ok = 0;
 
        switch (dir->tdir_type) {
        int ok = 0;
 
        switch (dir->tdir_type) {
@@ -849,7 +958,7 @@ TIFFFetchRationalArray(TIFF* tif, TIFFDirEntry* dir, float* v)
        uint32* l;
 
        l = (uint32*)CheckMalloc(tif,
        uint32* l;
 
        l = (uint32*)CheckMalloc(tif,
-           dir->tdir_count*tiffDataWidth[dir->tdir_type],
+           dir->tdir_count, TIFFDataWidth((TIFFDataType) dir->tdir_type),
            "to fetch array of rationals");
        if (l) {
                if (TIFFFetchData(tif, dir, (char *)l)) {
            "to fetch array of rationals");
        if (l) {
                if (TIFFFetchData(tif, dir, (char *)l)) {
@@ -980,7 +1089,7 @@ TIFFFetchAnyArray(TIFF* tif, TIFFDirEntry* dir, double* v)
                /* TIFF_ASCII */
                /* TIFF_UNDEFINED */
                TIFFError(tif->tif_name,
                /* TIFF_ASCII */
                /* TIFF_UNDEFINED */
                TIFFError(tif->tif_name,
-                   "Cannot read TIFF_ANY type %d for field \"%s\"",
+                   "cannot read TIFF_ANY type %d for field \"%s\"",
                    _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name);
                return (0);
        }
                    _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name);
                return (0);
        }
@@ -1005,35 +1114,35 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp)
                case TIFF_SBYTE:
                        /* NB: always expand BYTE values to shorts */
                        cp = CheckMalloc(tif,
                case TIFF_SBYTE:
                        /* NB: always expand BYTE values to shorts */
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (uint16), mesg);
+                           dp->tdir_count, sizeof (uint16), mesg);
                        ok = cp && TIFFFetchByteArray(tif, dp, (uint16*) cp);
                        break;
                case TIFF_SHORT:
                case TIFF_SSHORT:
                        cp = CheckMalloc(tif,
                        ok = cp && TIFFFetchByteArray(tif, dp, (uint16*) cp);
                        break;
                case TIFF_SHORT:
                case TIFF_SSHORT:
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (uint16), mesg);
+                           dp->tdir_count, sizeof (uint16), mesg);
                        ok = cp && TIFFFetchShortArray(tif, dp, (uint16*) cp);
                        break;
                case TIFF_LONG:
                case TIFF_SLONG:
                        cp = CheckMalloc(tif,
                        ok = cp && TIFFFetchShortArray(tif, dp, (uint16*) cp);
                        break;
                case TIFF_LONG:
                case TIFF_SLONG:
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (uint32), mesg);
+                           dp->tdir_count, sizeof (uint32), mesg);
                        ok = cp && TIFFFetchLongArray(tif, dp, (uint32*) cp);
                        break;
                case TIFF_RATIONAL:
                case TIFF_SRATIONAL:
                        cp = CheckMalloc(tif,
                        ok = cp && TIFFFetchLongArray(tif, dp, (uint32*) cp);
                        break;
                case TIFF_RATIONAL:
                case TIFF_SRATIONAL:
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (float), mesg);
+                           dp->tdir_count, sizeof (float), mesg);
                        ok = cp && TIFFFetchRationalArray(tif, dp, (float*) cp);
                        break;
                case TIFF_FLOAT:
                        cp = CheckMalloc(tif,
                        ok = cp && TIFFFetchRationalArray(tif, dp, (float*) cp);
                        break;
                case TIFF_FLOAT:
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (float), mesg);
+                           dp->tdir_count, sizeof (float), mesg);
                        ok = cp && TIFFFetchFloatArray(tif, dp, (float*) cp);
                        break;
                case TIFF_DOUBLE:
                        cp = CheckMalloc(tif,
                        ok = cp && TIFFFetchFloatArray(tif, dp, (float*) cp);
                        break;
                case TIFF_DOUBLE:
                        cp = CheckMalloc(tif,
-                           dp->tdir_count * sizeof (double), mesg);
+                           dp->tdir_count, sizeof (double), mesg);
                        ok = cp && TIFFFetchDoubleArray(tif, dp, (double*) cp);
                        break;
                case TIFF_ASCII:
                        ok = cp && TIFFFetchDoubleArray(tif, dp, (double*) cp);
                        break;
                case TIFF_ASCII:
@@ -1042,7 +1151,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp)
                         * Some vendors write strings w/o the trailing
                         * NULL byte, so always append one just in case.
                         */
                         * Some vendors write strings w/o the trailing
                         * NULL byte, so always append one just in case.
                         */
-                       cp = CheckMalloc(tif, dp->tdir_count+1, mesg);
+                       cp = CheckMalloc(tif, dp->tdir_count+1, 1, mesg);
                        if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
                                cp[dp->tdir_count] = '\0';      /* XXX */
                        break;
                        if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
                                cp[dp->tdir_count] = '\0';      /* XXX */
                        break;
@@ -1144,8 +1253,9 @@ TIFFFetchPerSampleShorts(TIFF* tif, TIFFDirEntry* dir, int* pl)
                uint16* v = buf;
 
                if (samples > NITEMS(buf))
                uint16* v = buf;
 
                if (samples > NITEMS(buf))
-                       v = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
-               if (TIFFFetchShortArray(tif, dir, v)) {
+                       v = (uint16*) CheckMalloc(tif, samples, sizeof (uint16),
+                                                 "to fetch per-sample values");
+               if (v && TIFFFetchShortArray(tif, dir, v)) {
                        int i;
                        for (i = 1; i < samples; i++)
                                if (v[i] != v[0]) {
                        int i;
                        for (i = 1; i < samples; i++)
                                if (v[i] != v[0]) {
@@ -1158,7 +1268,7 @@ TIFFFetchPerSampleShorts(TIFF* tif, TIFFDirEntry* dir, int* pl)
                        status = 1;
                }
        bad:
                        status = 1;
                }
        bad:
-               if (v != buf)
+               if (v && v != buf)
                        _TIFFfree((char*) v);
        }
        return (status);
                        _TIFFfree((char*) v);
        }
        return (status);
@@ -1180,8 +1290,9 @@ TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl)
                double* v = buf;
 
                if (samples > NITEMS(buf))
                double* v = buf;
 
                if (samples > NITEMS(buf))
-                       v = (double*) _TIFFmalloc(samples * sizeof (double));
-               if (TIFFFetchAnyArray(tif, dir, v)) {
+                       v = (double*) CheckMalloc(tif, samples, sizeof (double),
+                                                 "to fetch per-sample values");
+               if (v && TIFFFetchAnyArray(tif, dir, v)) {
                        int i;
                        for (i = 1; i < samples; i++)
                                if (v[i] != v[0]) {
                        int i;
                        for (i = 1; i < samples; i++)
                                if (v[i] != v[0]) {
@@ -1194,7 +1305,7 @@ TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl)
                        status = 1;
                }
        bad:
                        status = 1;
                }
        bad:
-               if (v != buf)
+               if (v && v != buf)
                        _TIFFfree(v);
        }
        return (status);
                        _TIFFfree(v);
        }
        return (status);
@@ -1212,32 +1323,58 @@ TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, long nstrips, uint32** lpp)
        register uint32* lp;
        int status;
 
        register uint32* lp;
        int status;
 
-       if (!CheckDirCount(tif, dir, (uint32) nstrips))
-               return (0);
+        CheckDirCount(tif, dir, (uint32) nstrips);
+
        /*
         * Allocate space for strip information.
         */
        if (*lpp == NULL &&
            (*lpp = (uint32 *)CheckMalloc(tif,
        /*
         * Allocate space for strip information.
         */
        if (*lpp == NULL &&
            (*lpp = (uint32 *)CheckMalloc(tif,
-             nstrips * sizeof (uint32), "for strip array")) == NULL)
+             nstrips, sizeof (uint32), "for strip array")) == NULL)
                return (0);
        lp = *lpp;
                return (0);
        lp = *lpp;
+        memset( lp, 0, sizeof(uint32) * nstrips );
+
        if (dir->tdir_type == (int)TIFF_SHORT) {
                /*
                 * Handle uint16->uint32 expansion.
                 */
                uint16* dp = (uint16*) CheckMalloc(tif,
        if (dir->tdir_type == (int)TIFF_SHORT) {
                /*
                 * Handle uint16->uint32 expansion.
                 */
                uint16* dp = (uint16*) CheckMalloc(tif,
-                   dir->tdir_count* sizeof (uint16), "to fetch strip tag");
+                   dir->tdir_count, sizeof (uint16), "to fetch strip tag");
                if (dp == NULL)
                        return (0);
                if( (status = TIFFFetchShortArray(tif, dir, dp)) != 0 ) {
                if (dp == NULL)
                        return (0);
                if( (status = TIFFFetchShortArray(tif, dir, dp)) != 0 ) {
-                       register uint16* wp = dp;
-                       while (nstrips-- > 0)
-                               *lp++ = *wp++;
+                    int i;
+                    
+                    for( i = 0; i < nstrips && i < (int) dir->tdir_count; i++ )
+                    {
+                        lp[i] = dp[i];
+                    }
                }
                _TIFFfree((char*) dp);
                }
                _TIFFfree((char*) dp);
+
+        } else if( nstrips != (int) dir->tdir_count ) {
+            /* Special case to correct length */
+
+            uint32* dp = (uint32*) CheckMalloc(tif,
+                   dir->tdir_count, sizeof (uint32), "to fetch strip tag");
+            if (dp == NULL)
+                return (0);
+
+            status = TIFFFetchLongArray(tif, dir, dp);
+            if( status != 0 ) {
+                int i;
+
+                for( i = 0; i < nstrips && i < (int) dir->tdir_count; i++ )
+                {
+                    lp[i] = dp[i];
+                }
+            }
+
+            _TIFFfree( (char *) dp );
        } else
        } else
-               status = TIFFFetchLongArray(tif, dir, lp);
+            status = TIFFFetchLongArray(tif, dir, lp);
+        
        return (status);
 }
 
        return (status);
 }
 
@@ -1252,8 +1389,12 @@ TIFFFetchExtraSamples(TIFF* tif, TIFFDirEntry* dir)
        uint16* v = buf;
        int status;
 
        uint16* v = buf;
        int status;
 
-       if (dir->tdir_count > NITEMS(buf))
-               v = (uint16*) _TIFFmalloc(dir->tdir_count * sizeof (uint16));
+       if (dir->tdir_count > NITEMS(buf)) {
+               v = (uint16*) CheckMalloc(tif, dir->tdir_count, sizeof (uint16),
+                                         "to fetch extra samples");
+               if (!v)
+                       return (0);
+       }
        if (dir->tdir_type == TIFF_BYTE)
                status = TIFFFetchByteArray(tif, dir, v);
        else
        if (dir->tdir_type == TIFF_BYTE)
                status = TIFFFetchByteArray(tif, dir, v);
        else
@@ -1282,10 +1423,10 @@ TIFFFetchRefBlackWhite(TIFF* tif, TIFFDirEntry* dir)
        /*
         * Handle LONG's for backward compatibility.
         */
        /*
         * Handle LONG's for backward compatibility.
         */
-       cp = CheckMalloc(tif, dir->tdir_count * sizeof (uint32), mesg);
+       cp = CheckMalloc(tif, dir->tdir_count, sizeof (uint32), mesg);
        if( (ok = (cp && TIFFFetchLongArray(tif, dir, (uint32*) cp))) != 0) {
                float* fp = (float*)
        if( (ok = (cp && TIFFFetchLongArray(tif, dir, (uint32*) cp))) != 0) {
                float* fp = (float*)
-                   CheckMalloc(tif, dir->tdir_count * sizeof (float), mesg);
+                   CheckMalloc(tif, dir->tdir_count, sizeof (float), mesg);
                if( (ok = (fp != NULL)) != 0 ) {
                        uint32 i;
                        for (i = 0; i < dir->tdir_count; i++)
                if( (ok = (fp != NULL)) != 0 ) {
                        uint32 i;
                        for (i = 0; i < dir->tdir_count; i++)
@@ -1325,17 +1466,20 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
        if (rowbytes > 8192) {
                stripbytes = rowbytes;
                rowsperstrip = 1;
        if (rowbytes > 8192) {
                stripbytes = rowbytes;
                rowsperstrip = 1;
-       } else {
+       } else if (rowbytes > 0 ) {
                rowsperstrip = 8192 / rowbytes;
                stripbytes = rowbytes * rowsperstrip;
        }
                rowsperstrip = 8192 / rowbytes;
                stripbytes = rowbytes * rowsperstrip;
        }
+        else
+            return;
+
        /* never increase the number of strips in an image */
        if (rowsperstrip >= td->td_rowsperstrip)
                return;
        nstrips = (tstrip_t) TIFFhowmany(bytecount, stripbytes);
        /* never increase the number of strips in an image */
        if (rowsperstrip >= td->td_rowsperstrip)
                return;
        nstrips = (tstrip_t) TIFFhowmany(bytecount, stripbytes);
-       newcounts = (uint32*) CheckMalloc(tif, nstrips * sizeof (uint32),
+       newcounts = (uint32*) CheckMalloc(tif, nstrips, sizeof (uint32),
                                "for chopped \"StripByteCounts\" array");
                                "for chopped \"StripByteCounts\" array");
-       newoffsets = (uint32*) CheckMalloc(tif, nstrips * sizeof (uint32),
+       newoffsets = (uint32*) CheckMalloc(tif, nstrips, sizeof (uint32),
                                "for chopped \"StripOffsets\" array");
        if (newcounts == NULL || newoffsets == NULL) {
                /*
                                "for chopped \"StripOffsets\" array");
        if (newcounts == NULL || newoffsets == NULL) {
                /*
@@ -1354,7 +1498,7 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
         * the broken-up format.
         */
        for (strip = 0; strip < nstrips; strip++) {
         * the broken-up format.
         */
        for (strip = 0; strip < nstrips; strip++) {
-               if (stripbytes > bytecount)
+               if (stripbytes > (tsize_t) bytecount)
                        stripbytes = bytecount;
                newcounts[strip] = stripbytes;
                newoffsets[strip] = offset;
                        stripbytes = bytecount;
                newcounts[strip] = stripbytes;
                newoffsets[strip] = offset;
index ed4b0118c020dd7b5b7c4af4b911489fd467d221..df120153f20a4b426a630c49e20c62107bfb52cf 100644 (file)
@@ -41,6 +41,7 @@ extern        void TIFFCvtNativeToIEEEDouble(TIFF*, uint32, double*);
 
 static int TIFFWriteNormalTag(TIFF*, TIFFDirEntry*, const TIFFFieldInfo*);
 static void TIFFSetupShortLong(TIFF*, ttag_t, TIFFDirEntry*, uint32);
 
 static int TIFFWriteNormalTag(TIFF*, TIFFDirEntry*, const TIFFFieldInfo*);
 static void TIFFSetupShortLong(TIFF*, ttag_t, TIFFDirEntry*, uint32);
+static void TIFFSetupShort(TIFF*, ttag_t, TIFFDirEntry*, uint16);
 static int TIFFSetupShortPair(TIFF*, ttag_t, TIFFDirEntry*);
 static int TIFFWritePerSampleShorts(TIFF*, ttag_t, TIFFDirEntry*);
 static int TIFFWritePerSampleAnys(TIFF*, TIFFDataType, ttag_t, TIFFDirEntry*);
 static int TIFFSetupShortPair(TIFF*, ttag_t, TIFFDirEntry*);
 static int TIFFWritePerSampleShorts(TIFF*, ttag_t, TIFFDirEntry*);
 static int TIFFWritePerSampleAnys(TIFF*, TIFFDataType, ttag_t, TIFFDirEntry*);
@@ -87,11 +88,11 @@ static      int TIFFWriteRational(TIFF*,
  * handle overwriting a directory with auxiliary
  * storage that's been changed.
  */
  * handle overwriting a directory with auxiliary
  * storage that's been changed.
  */
-int
-TIFFWriteDirectory(TIFF* tif)
+static int
+_TIFFWriteDirectory(TIFF* tif, int done)
 {
        uint16 dircount;
 {
        uint16 dircount;
-       uint32 diroff;
+       toff_t diroff;
        ttag_t tag;
        uint32 nfields;
        tsize_t dirsize;
        ttag_t tag;
        uint32 nfields;
        tsize_t dirsize;
@@ -108,30 +109,34 @@ TIFFWriteDirectory(TIFF* tif)
         * different characteristics get the right buffers
         * setup for them.
         */
         * different characteristics get the right buffers
         * setup for them.
         */
-       if (tif->tif_flags & TIFF_POSTENCODE) {
-               tif->tif_flags &= ~TIFF_POSTENCODE;
-               if (!(*tif->tif_postencode)(tif)) {
-                       TIFFError(tif->tif_name,
-                           "Error post-encoding before directory write");
-                       return (0);
-               }
+       if (done)
+       {
+           if (tif->tif_flags & TIFF_POSTENCODE) {
+                   tif->tif_flags &= ~TIFF_POSTENCODE;
+                   if (!(*tif->tif_postencode)(tif)) {
+                           TIFFError(tif->tif_name,
+                               "Error post-encoding before directory write");
+                           return (0);
+                   }
+           }
+           (*tif->tif_close)(tif);             /* shutdown encoder */
+           /*
+            * Flush any data that might have been written
+            * by the compression close+cleanup routines.
+            */
+           if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) {
+                   TIFFError(tif->tif_name,
+                       "Error flushing data before directory write");
+                   return (0);
+           }
+           if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
+                   _TIFFfree(tif->tif_rawdata);
+                   tif->tif_rawdata = NULL;
+                   tif->tif_rawcc = 0;
+                   tif->tif_rawdatasize = 0;
+           }
+           tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);
        }
        }
-       (*tif->tif_close)(tif);                 /* shutdown encoder */
-       /*
-        * Flush any data that might have been written
-        * by the compression close+cleanup routines.
-        */
-       if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) {
-               TIFFError(tif->tif_name,
-                   "Error flushing data before directory write");
-               return (0);
-       }
-       if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
-               _TIFFfree(tif->tif_rawdata);
-               tif->tif_rawdata = NULL;
-               tif->tif_rawcc = 0;
-       }
-       tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);
 
        td = &tif->tif_dir;
        /*
 
        td = &tif->tif_dir;
        /*
@@ -141,8 +146,9 @@ TIFFWriteDirectory(TIFF* tif)
         */
        nfields = 0;
        for (b = 0; b <= FIELD_LAST; b++)
         */
        nfields = 0;
        for (b = 0; b <= FIELD_LAST; b++)
-               if (TIFFFieldSet(tif, b))
+               if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM)
                        nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
                        nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
+        nfields += td->td_customValueCount;
        dirsize = nfields * sizeof (TIFFDirEntry);
        data = (char*) _TIFFmalloc(dirsize);
        if (data == NULL) {
        dirsize = nfields * sizeof (TIFFDirEntry);
        data = (char*) _TIFFmalloc(dirsize);
        if (data == NULL) {
@@ -180,12 +186,35 @@ TIFFWriteDirectory(TIFF* tif)
        }                                                               /*XXX*/
        for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
                const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];
        }                                                               /*XXX*/
        for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
                const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];
-               if (!FieldSet(fields, fip->field_bit))
-                       continue;
-               switch (fip->field_bit) {
+
+                /*
+                ** For custom fields, we test to see if the custom field
+                ** is set or not.  For normal fields, we just use the
+                ** FieldSet test. 
+                */
+                if( fip->field_bit == FIELD_CUSTOM )
+                {
+                    int ci, is_set = FALSE;
+
+                    for( ci = 0; ci < td->td_customValueCount; ci++ )
+                        is_set |= (td->td_customValues[ci].info == fip);
+
+                    if( !is_set )
+                        continue;
+                }
+               else if (!FieldSet(fields, fip->field_bit))
+                    continue;
+
+
+                /*
+                ** Handle other fields.
+                */
+               switch (fip->field_bit)
+                {
                case FIELD_STRIPOFFSETS:
                        /*
                         * We use one field bit for both strip and tile
                case FIELD_STRIPOFFSETS:
                        /*
                         * We use one field bit for both strip and tile
+
                         * offsets, and so must be careful in selecting
                         * the appropriate field descriptor (so that tags
                         * are written in sorted order).
                         * offsets, and so must be careful in selecting
                         * the appropriate field descriptor (so that tags
                         * are written in sorted order).
@@ -234,6 +263,14 @@ TIFFWriteDirectory(TIFF* tif)
                        TIFFSetupShortLong(tif, TIFFTAG_TILELENGTH,
                            dir, td->td_tilelength);
                        break;
                        TIFFSetupShortLong(tif, TIFFTAG_TILELENGTH,
                            dir, td->td_tilelength);
                        break;
+               case FIELD_COMPRESSION:
+                       TIFFSetupShort(tif, TIFFTAG_COMPRESSION,
+                           dir, td->td_compression);
+                       break;
+               case FIELD_PHOTOMETRIC:
+                       TIFFSetupShort(tif, TIFFTAG_PHOTOMETRIC,
+                           dir, td->td_photometric);
+                       break;
                case FIELD_POSITION:
                        WriteRationalPair(TIFF_RATIONAL,
                            TIFFTAG_XPOSITION, td->td_xposition,
                case FIELD_POSITION:
                        WriteRationalPair(TIFF_RATIONAL,
                            TIFFTAG_XPOSITION, td->td_xposition,
@@ -294,7 +331,7 @@ TIFFWriteDirectory(TIFF* tif)
                         */
                        if (dir->tdir_count > 0) {
                                tif->tif_flags |= TIFF_INSUBIFD;
                         */
                        if (dir->tdir_count > 0) {
                                tif->tif_flags |= TIFF_INSUBIFD;
-                               tif->tif_nsubifd = dir->tdir_count;
+                               tif->tif_nsubifd = (uint16) dir->tdir_count;
                                if (dir->tdir_count > 1)
                                        tif->tif_subifdoff = dir->tdir_offset;
                                else
                                if (dir->tdir_count > 1)
                                        tif->tif_subifdoff = dir->tdir_offset;
                                else
@@ -311,8 +348,11 @@ TIFFWriteDirectory(TIFF* tif)
                        break;
                }
                dir++;
                        break;
                }
                dir++;
-               ResetFieldBit(fields, fip->field_bit);
+                
+                if( fip->field_bit != FIELD_CUSTOM )
+                    ResetFieldBit(fields, fip->field_bit);
        }
        }
+
        /*
         * Write directory.
         */
        /*
         * Write directory.
         */
@@ -350,20 +390,18 @@ TIFFWriteDirectory(TIFF* tif)
                TIFFError(tif->tif_name, "Error writing directory link");
                goto bad;
        }
                TIFFError(tif->tif_name, "Error writing directory link");
                goto bad;
        }
-       TIFFFreeDirectory(tif);
-       _TIFFfree(data);
-       tif->tif_flags &= ~TIFF_DIRTYDIRECT;
-       (*tif->tif_cleanup)(tif);
+       if (done) {
+               TIFFFreeDirectory(tif);
+               tif->tif_flags &= ~TIFF_DIRTYDIRECT;
+               (*tif->tif_cleanup)(tif);
 
 
-       /*
-        * Reset directory-related state for subsequent
-        * directories.
-        */
-       TIFFDefaultDirectory(tif);
-       tif->tif_diroff = 0;
-       tif->tif_curoff = 0;
-       tif->tif_row = (uint32) -1;
-       tif->tif_curstrip = (tstrip_t) -1;
+               /*
+               * Reset directory-related state for subsequent
+               * directories.
+               */
+               TIFFCreateDirectory(tif);
+       }
+       _TIFFfree(data);
        return (1);
 bad:
        _TIFFfree(data);
        return (1);
 bad:
        _TIFFfree(data);
@@ -371,6 +409,30 @@ bad:
 }
 #undef WriteRationalPair
 
 }
 #undef WriteRationalPair
 
+int
+TIFFWriteDirectory(TIFF* tif)
+{
+       return _TIFFWriteDirectory(tif, TRUE);
+}
+
+/*
+ * Similar to TIFFWriteDirectory(), writes the directory out
+ * but leaves all data structures in memory so that it can be
+ * written again.  This will make a partially written TIFF file
+ * readable before it is successfully completed/closed.
+ */ 
+int
+TIFFCheckpointDirectory(TIFF* tif)
+{
+       int rc;
+       /* Setup the strips arrays, if they haven't already been. */
+       if (tif->tif_dir.td_stripoffset == NULL)
+           (void) TIFFSetupStrips(tif);
+       rc = _TIFFWriteDirectory(tif, FALSE);
+       (void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END));
+       return rc;
+}
+
 /*
  * Process tags that are not special cased.
  */
 /*
  * Process tags that are not special cased.
  */
@@ -380,7 +442,7 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
        u_short wc = (u_short) fip->field_writecount;
        uint32 wc2;
 
        u_short wc = (u_short) fip->field_writecount;
        uint32 wc2;
 
-       dir->tdir_tag = fip->field_tag;
+       dir->tdir_tag = (uint16) fip->field_tag;
        dir->tdir_type = (u_short) fip->field_type;
        dir->tdir_count = wc;
 #define        WRITEF(x,y)     x(tif, fip->field_type, fip->field_tag, dir, wc, y)
        dir->tdir_type = (u_short) fip->field_type;
        dir->tdir_count = wc;
 #define        WRITEF(x,y)     x(tif, fip->field_type, fip->field_tag, dir, wc, y)
@@ -389,81 +451,123 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
        case TIFF_SSHORT:
                if (wc > 1) {
                        uint16* wp;
        case TIFF_SSHORT:
                if (wc > 1) {
                        uint16* wp;
-                       if (wc == (u_short) TIFF_VARIABLE)
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount)
                                TIFFGetField(tif, fip->field_tag, &wc, &wp);
                        else
                                TIFFGetField(tif, fip->field_tag, &wp);
                        if (!WRITEF(TIFFWriteShortArray, wp))
                                return (0);
                } else {
                                TIFFGetField(tif, fip->field_tag, &wc, &wp);
                        else
                                TIFFGetField(tif, fip->field_tag, &wp);
                        if (!WRITEF(TIFFWriteShortArray, wp))
                                return (0);
                } else {
-                       uint16 sv;
-                       TIFFGetField(tif, fip->field_tag, &sv);
-                       dir->tdir_offset =
-                           TIFFInsertData(tif, dir->tdir_type, sv);
+                       if (fip->field_passcount) {
+                               uint16* wp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &wp);
+                               if (!WRITEF(TIFFWriteShortArray, wp))
+                                       return 0;
+                       } else {
+                               uint16 sv;
+                               TIFFGetField(tif, fip->field_tag, &sv);
+                               dir->tdir_offset =
+                                       TIFFInsertData(tif, dir->tdir_type, sv);
+                       }
                }
                break;
        case TIFF_LONG:
        case TIFF_SLONG:
                }
                break;
        case TIFF_LONG:
        case TIFF_SLONG:
+       case TIFF_IFD:
                if (wc > 1) {
                        uint32* lp;
                if (wc > 1) {
                        uint32* lp;
-                       if (wc == (u_short) TIFF_VARIABLE)
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount)
                                TIFFGetField(tif, fip->field_tag, &wc, &lp);
                        else
                                TIFFGetField(tif, fip->field_tag, &lp);
                        if (!WRITEF(TIFFWriteLongArray, lp))
                                return (0);
                } else {
                                TIFFGetField(tif, fip->field_tag, &wc, &lp);
                        else
                                TIFFGetField(tif, fip->field_tag, &lp);
                        if (!WRITEF(TIFFWriteLongArray, lp))
                                return (0);
                } else {
-                       /* XXX handle LONG->SHORT conversion */
-                       TIFFGetField(tif, fip->field_tag, &dir->tdir_offset);
+                       if (fip->field_passcount) {
+                               uint32* lp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &lp);
+                               if (!WRITEF(TIFFWriteLongArray, lp))
+                                       return 0;
+                       } else {
+                               /* XXX handle LONG->SHORT conversion */
+                               TIFFGetField(tif, fip->field_tag,
+                                            &dir->tdir_offset);
+                       }
                }
                break;
        case TIFF_RATIONAL:
        case TIFF_SRATIONAL:
                if (wc > 1) {
                        float* fp;
                }
                break;
        case TIFF_RATIONAL:
        case TIFF_SRATIONAL:
                if (wc > 1) {
                        float* fp;
-                       if (wc == (u_short) TIFF_VARIABLE)
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount)
                                TIFFGetField(tif, fip->field_tag, &wc, &fp);
                        else
                                TIFFGetField(tif, fip->field_tag, &fp);
                        if (!WRITEF(TIFFWriteRationalArray, fp))
                                return (0);
                } else {
                                TIFFGetField(tif, fip->field_tag, &wc, &fp);
                        else
                                TIFFGetField(tif, fip->field_tag, &fp);
                        if (!WRITEF(TIFFWriteRationalArray, fp))
                                return (0);
                } else {
-                       float fv;
-                       TIFFGetField(tif, fip->field_tag, &fv);
-                       if (!WRITEF(TIFFWriteRationalArray, &fv))
-                               return (0);
+                       if (fip->field_passcount) {
+                               float* fp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &fp);
+                               if (!WRITEF(TIFFWriteRationalArray, fp))
+                                       return 0;
+                       } else {
+                               float fv;
+                               TIFFGetField(tif, fip->field_tag, &fv);
+                               if (!WRITEF(TIFFWriteRationalArray, &fv))
+                                       return (0);
+                       }
                }
                break;
        case TIFF_FLOAT:
                if (wc > 1) {
                        float* fp;
                }
                break;
        case TIFF_FLOAT:
                if (wc > 1) {
                        float* fp;
-                       if (wc == (u_short) TIFF_VARIABLE)
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount)
                                TIFFGetField(tif, fip->field_tag, &wc, &fp);
                        else
                                TIFFGetField(tif, fip->field_tag, &fp);
                        if (!WRITEF(TIFFWriteFloatArray, fp))
                                return (0);
                } else {
                                TIFFGetField(tif, fip->field_tag, &wc, &fp);
                        else
                                TIFFGetField(tif, fip->field_tag, &fp);
                        if (!WRITEF(TIFFWriteFloatArray, fp))
                                return (0);
                } else {
-                       float fv;
-                       TIFFGetField(tif, fip->field_tag, &fv);
-                       if (!WRITEF(TIFFWriteFloatArray, &fv))
-                               return (0);
+                       if (fip->field_passcount) {
+                               float* fp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &fp);
+                               if (!WRITEF(TIFFWriteFloatArray, fp))
+                                       return 0;
+                       } else {
+                               float fv;
+                               TIFFGetField(tif, fip->field_tag, &fv);
+                               if (!WRITEF(TIFFWriteFloatArray, &fv))
+                                       return (0);
+                       }
                }
                break;
        case TIFF_DOUBLE:
                if (wc > 1) {
                        double* dp;
                }
                break;
        case TIFF_DOUBLE:
                if (wc > 1) {
                        double* dp;
-                       if (wc == (u_short) TIFF_VARIABLE)
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount)
                                TIFFGetField(tif, fip->field_tag, &wc, &dp);
                        else
                                TIFFGetField(tif, fip->field_tag, &dp);
                        if (!WRITEF(TIFFWriteDoubleArray, dp))
                                return (0);
                } else {
                                TIFFGetField(tif, fip->field_tag, &wc, &dp);
                        else
                                TIFFGetField(tif, fip->field_tag, &dp);
                        if (!WRITEF(TIFFWriteDoubleArray, dp))
                                return (0);
                } else {
-                       double dv;
-                       TIFFGetField(tif, fip->field_tag, &dv);
-                       if (!WRITEF(TIFFWriteDoubleArray, &dv))
-                               return (0);
+                       if (fip->field_passcount) {
+                               double* dp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &dp);
+                               if (!WRITEF(TIFFWriteDoubleArray, dp))
+                                       return 0;
+                       } else {
+                               double dv;
+                               TIFFGetField(tif, fip->field_tag, &dv);
+                               if (!WRITEF(TIFFWriteDoubleArray, &dv))
+                                       return (0);
+                       }
                }
                break;
        case TIFF_ASCII:
                }
                break;
        case TIFF_ASCII:
@@ -479,20 +583,32 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
            correctness not verified (FW, 99/08) */
         case TIFF_BYTE:
         case TIFF_SBYTE:          
            correctness not verified (FW, 99/08) */
         case TIFF_BYTE:
         case TIFF_SBYTE:          
-                if (wc > 1) {
-                    char* cp;
-                    if (wc == (u_short) TIFF_VARIABLE) {
-                        TIFFGetField(tif, fip->field_tag, &wc, &cp);
-                        dir->tdir_count = wc;
-                    } else
-                        TIFFGetField(tif, fip->field_tag, &cp);
-                    if (!TIFFWriteByteArray(tif, dir, cp))
-                        return (0);
+               if (wc > 1) {
+                       char* cp;
+                       if (wc == (u_short) TIFF_VARIABLE
+                           || fip->field_passcount) {
+                               TIFFGetField(tif, fip->field_tag, &wc, &cp);
+                               dir->tdir_count = wc;
+                       } else if (wc == (u_short) TIFF_VARIABLE2) {
+                               TIFFGetField(tif, fip->field_tag, &wc2, &cp);
+                               dir->tdir_count = wc2;
+                       } else
+                               TIFFGetField(tif, fip->field_tag, &cp);
+                       if (!TIFFWriteByteArray(tif, dir, cp))
+                               return (0);
                 } else {
                 } else {
-                    char cv;
-                    TIFFGetField(tif, fip->field_tag, &cv);
-                    if (!TIFFWriteByteArray(tif, dir, &cv))
-                        return (0);
+                       if (fip->field_passcount) {
+                               char* cp;
+                               TIFFGetField(tif, fip->field_tag, &wc, &cp);
+                               dir->tdir_count = wc;
+                               if (!TIFFWriteByteArray(tif, dir, cp))
+                                       return 0;
+                       } else {
+                               char cv;
+                               TIFFGetField(tif, fip->field_tag, &cv);
+                               if (!TIFFWriteByteArray(tif, dir, &cv))
+                                       return (0);
+                       }
                 }
                 break;
 
                 }
                 break;
 
@@ -525,7 +641,7 @@ TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
 static void
 TIFFSetupShortLong(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint32 v)
 {
 static void
 TIFFSetupShortLong(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint32 v)
 {
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_count = 1;
        if (v > 0xffffL) {
                dir->tdir_type = (short) TIFF_LONG;
        dir->tdir_count = 1;
        if (v > 0xffffL) {
                dir->tdir_type = (short) TIFF_LONG;
@@ -535,6 +651,18 @@ TIFFSetupShortLong(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint32 v)
                dir->tdir_offset = TIFFInsertData(tif, (int) TIFF_SHORT, v);
        }
 }
                dir->tdir_offset = TIFFInsertData(tif, (int) TIFF_SHORT, v);
        }
 }
+
+/*
+ * Setup a SHORT directory entry
+ */
+static void
+TIFFSetupShort(TIFF* tif, ttag_t tag, TIFFDirEntry* dir, uint16 v)
+{
+       dir->tdir_tag = (uint16) tag;
+       dir->tdir_count = 1;
+       dir->tdir_type = (short) TIFF_SHORT;
+       dir->tdir_offset = TIFFInsertData(tif, (int) TIFF_SHORT, v);
+}
 #undef MakeShortDirent
 
 #ifndef TIFFWriteRational
 #undef MakeShortDirent
 
 #ifndef TIFFWriteRational
@@ -564,8 +692,14 @@ TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
        uint16* w = buf;
        int i, status, samples = tif->tif_dir.td_samplesperpixel;
 
        uint16* w = buf;
        int i, status, samples = tif->tif_dir.td_samplesperpixel;
 
-       if (samples > NITEMS(buf))
+       if (samples > NITEMS(buf)) {
                w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
                w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
+               if (w == NULL) {
+                       TIFFError(tif->tif_name,
+                           "No space to write per-sample shorts");
+                       return (0);
+               }
+       }
        TIFFGetField(tif, tag, &v);
        for (i = 0; i < samples; i++)
                w[i] = v;
        TIFFGetField(tif, tag, &v);
        for (i = 0; i < samples; i++)
                w[i] = v;
@@ -589,8 +723,14 @@ TIFFWritePerSampleAnys(TIFF* tif,
        int i, status;
        int samples = (int) tif->tif_dir.td_samplesperpixel;
 
        int i, status;
        int samples = (int) tif->tif_dir.td_samplesperpixel;
 
-       if (samples > NITEMS(buf))
+       if (samples > NITEMS(buf)) {
                w = (double*) _TIFFmalloc(samples * sizeof (double));
                w = (double*) _TIFFmalloc(samples * sizeof (double));
+               if (w == NULL) {
+                       TIFFError(tif->tif_name,
+                           "No space to write per-sample values");
+                       return (0);
+               }
+       }
        TIFFGetField(tif, tag, &v);
        for (i = 0; i < samples; i++)
                w[i] = v;
        TIFFGetField(tif, tag, &v);
        for (i = 0; i < samples; i++)
                w[i] = v;
@@ -625,7 +765,7 @@ TIFFWriteShortTable(TIFF* tif,
 {
        uint32 i, off;
 
 {
        uint32 i, off;
 
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) TIFF_SHORT;
        /* XXX -- yech, fool TIFFWriteData */
        dir->tdir_count = (uint32) (1L<<tif->tif_dir.td_bitspersample);
        dir->tdir_type = (short) TIFF_SHORT;
        /* XXX -- yech, fool TIFFWriteData */
        dir->tdir_count = (uint32) (1L<<tif->tif_dir.td_bitspersample);
@@ -660,7 +800,7 @@ static int
 TIFFWriteShortArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint16* v)
 {
 TIFFWriteShortArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint16* v)
 {
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        if (n <= 2) {
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        if (n <= 2) {
@@ -686,7 +826,7 @@ static int
 TIFFWriteLongArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint32* v)
 {
 TIFFWriteLongArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, uint32* v)
 {
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        if (n == 1) {
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        if (n == 1) {
@@ -708,10 +848,15 @@ TIFFWriteRationalArray(TIFF* tif,
        uint32* t;
        int status;
 
        uint32* t;
        int status;
 
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        t = (uint32*) _TIFFmalloc(2*n * sizeof (uint32));
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        t = (uint32*) _TIFFmalloc(2*n * sizeof (uint32));
+       if (t == NULL) {
+               TIFFError(tif->tif_name,
+                   "No space to write RATIONAL array");
+               return (0);
+       }
        for (i = 0; i < n; i++) {
                float fv = v[i];
                int sign = 1;
        for (i = 0; i < n; i++) {
                float fv = v[i];
                int sign = 1;
@@ -731,7 +876,7 @@ TIFFWriteRationalArray(TIFF* tif,
                        while (fv < 1L<<(31-3) && den < 1L<<(31-3))
                                fv *= 1<<3, den *= 1L<<3;
                }
                        while (fv < 1L<<(31-3) && den < 1L<<(31-3))
                                fv *= 1<<3, den *= 1L<<3;
                }
-               t[2*i+0] = sign * (fv + 0.5);
+               t[2*i+0] = (uint32) (sign * (fv + 0.5));
                t[2*i+1] = den;
        }
        status = TIFFWriteData(tif, dir, (char *)t);
                t[2*i+1] = den;
        }
        status = TIFFWriteData(tif, dir, (char *)t);
@@ -743,7 +888,7 @@ static int
 TIFFWriteFloatArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, float* v)
 {
 TIFFWriteFloatArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, float* v)
 {
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        TIFFCvtNativeToIEEEFloat(tif, n, v);
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        TIFFCvtNativeToIEEEFloat(tif, n, v);
@@ -758,7 +903,7 @@ static int
 TIFFWriteDoubleArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, double* v)
 {
 TIFFWriteDoubleArray(TIFF* tif,
     TIFFDataType type, ttag_t tag, TIFFDirEntry* dir, uint32 n, double* v)
 {
-       dir->tdir_tag = tag;
+       dir->tdir_tag = (uint16) tag;
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        TIFFCvtNativeToIEEEDouble(tif, n, v);
        dir->tdir_type = (short) type;
        dir->tdir_count = n;
        TIFFCvtNativeToIEEEDouble(tif, n, v);
@@ -782,14 +927,20 @@ TIFFWriteAnyArray(TIFF* tif,
        char* w = buf;
        int i, status = 0;
 
        char* w = buf;
        int i, status = 0;
 
-       if (n * tiffDataWidth[type] > sizeof buf)
-               w = (char*) _TIFFmalloc(n * tiffDataWidth[type]);
+       if (n * TIFFDataWidth(type) > sizeof buf) {
+               w = (char*) _TIFFmalloc(n * TIFFDataWidth(type));
+               if (w == NULL) {
+                       TIFFError(tif->tif_name,
+                           "No space to write array");
+                       return (0);
+               }
+       }
        switch (type) {
        case TIFF_BYTE:
                { uint8* bp = (uint8*) w;
        switch (type) {
        case TIFF_BYTE:
                { uint8* bp = (uint8*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (uint8) v[i];
                        bp[i] = (uint8) v[i];
-                 dir->tdir_tag = tag;
+                 dir->tdir_tag = (uint16) tag;
                  dir->tdir_type = (short) type;
                  dir->tdir_count = n;
                  if (!TIFFWriteByteArray(tif, dir, (char*) bp))
                  dir->tdir_type = (short) type;
                  dir->tdir_count = n;
                  if (!TIFFWriteByteArray(tif, dir, (char*) bp))
@@ -798,9 +949,9 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_SBYTE:
                { int8* bp = (int8*) w;
                break;
        case TIFF_SBYTE:
                { int8* bp = (int8*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (int8) v[i];
                        bp[i] = (int8) v[i];
-                 dir->tdir_tag = tag;
+                 dir->tdir_tag = (uint16) tag;
                  dir->tdir_type = (short) type;
                  dir->tdir_count = n;
                  if (!TIFFWriteByteArray(tif, dir, (char*) bp))
                  dir->tdir_type = (short) type;
                  dir->tdir_count = n;
                  if (!TIFFWriteByteArray(tif, dir, (char*) bp))
@@ -809,7 +960,7 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_SHORT:
                { uint16* bp = (uint16*) w;
                break;
        case TIFF_SHORT:
                { uint16* bp = (uint16*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (uint16) v[i];
                  if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
                                goto out;
                        bp[i] = (uint16) v[i];
                  if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
                                goto out;
@@ -817,7 +968,7 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_SSHORT:
                { int16* bp = (int16*) w;
                break;
        case TIFF_SSHORT:
                { int16* bp = (int16*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (int16) v[i];
                  if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
                        goto out;
                        bp[i] = (int16) v[i];
                  if (!TIFFWriteShortArray(tif, type, tag, dir, n, (uint16*)bp))
                        goto out;
@@ -825,7 +976,7 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_LONG:
                { uint32* bp = (uint32*) w;
                break;
        case TIFF_LONG:
                { uint32* bp = (uint32*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (uint32) v[i];
                  if (!TIFFWriteLongArray(tif, type, tag, dir, n, bp))
                        goto out;
                        bp[i] = (uint32) v[i];
                  if (!TIFFWriteLongArray(tif, type, tag, dir, n, bp))
                        goto out;
@@ -833,7 +984,7 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_SLONG:
                { int32* bp = (int32*) w;
                break;
        case TIFF_SLONG:
                { int32* bp = (int32*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (int32) v[i];
                  if (!TIFFWriteLongArray(tif, type, tag, dir, n, (uint32*) bp))
                        goto out;
                        bp[i] = (int32) v[i];
                  if (!TIFFWriteLongArray(tif, type, tag, dir, n, (uint32*) bp))
                        goto out;
@@ -841,7 +992,7 @@ TIFFWriteAnyArray(TIFF* tif,
                break;
        case TIFF_FLOAT:
                { float* bp = (float*) w;
                break;
        case TIFF_FLOAT:
                { float* bp = (float*) w;
-                 for (i = 0; i < n; i++)
+                 for (i = 0; i < (int) n; i++)
                        bp[i] = (float) v[i];
                  if (!TIFFWriteFloatArray(tif, type, tag, dir, n, bp))
                        goto out;
                        bp[i] = (float) v[i];
                  if (!TIFFWriteFloatArray(tif, type, tag, dir, n, bp))
                        goto out;
@@ -931,7 +1082,7 @@ TIFFWriteData(TIFF* tif, TIFFDirEntry* dir, char* cp)
                }
        }
        dir->tdir_offset = tif->tif_dataoff;
                }
        }
        dir->tdir_offset = tif->tif_dataoff;
-       cc = dir->tdir_count * tiffDataWidth[dir->tdir_type];
+       cc = dir->tdir_count * TIFFDataWidth((TIFFDataType) dir->tdir_type);
        if (SeekOK(tif, dir->tdir_offset) &&
            WriteOK(tif, cp, cc)) {
                tif->tif_dataoff += (cc + 1) & ~1;
        if (SeekOK(tif, dir->tdir_offset) &&
            WriteOK(tif, cp, cc)) {
                tif->tif_dataoff += (cc + 1) & ~1;
@@ -942,6 +1093,87 @@ TIFFWriteData(TIFF* tif, TIFFDirEntry* dir, char* cp)
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * Similar to TIFFWriteDirectory(), but if the directory has already
+ * been written once, it is relocated to the end of the file, in case it
+ * has changed in size.  Note that this will result in the loss of the 
+ * previously used directory space. 
+ */ 
+
+int 
+TIFFRewriteDirectory( TIFF *tif )
+{
+    static const char module[] = "TIFFRewriteDirectory";
+
+    /* We don't need to do anything special if it hasn't been written. */
+    if( tif->tif_diroff == 0 )
+        return TIFFWriteDirectory( tif );
+
+    /*
+    ** Find and zero the pointer to this directory, so that TIFFLinkDirectory
+    ** will cause it to be added after this directories current pre-link.
+    */
+    
+    /* Is it the first directory in the file? */
+    if (tif->tif_header.tiff_diroff == tif->tif_diroff) 
+    {
+        tif->tif_header.tiff_diroff = 0;
+        tif->tif_diroff = 0;
+
+#if defined(__hpux) && defined(__LP64__)
+#define HDROFF(f) ((toff_t)(unsigned long) &(((TIFFHeader*) 0)->f))
+#else
+#define        HDROFF(f)       ((toff_t) &(((TIFFHeader*) 0)->f))
+#endif
+        TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
+        if (!WriteOK(tif, &(tif->tif_header.tiff_diroff), 
+                     sizeof (tif->tif_diroff))) 
+        {
+            TIFFError(tif->tif_name, "Error updating TIFF header");
+            return (0);
+        }
+    }
+    else
+    {
+        toff_t  nextdir, off;
+
+       nextdir = tif->tif_header.tiff_diroff;
+       do {
+               uint16 dircount;
+
+               if (!SeekOK(tif, nextdir) ||
+                   !ReadOK(tif, &dircount, sizeof (dircount))) {
+                       TIFFError(module, "Error fetching directory count");
+                       return (0);
+               }
+               if (tif->tif_flags & TIFF_SWAB)
+                       TIFFSwabShort(&dircount);
+               (void) TIFFSeekFile(tif,
+                   dircount * sizeof (TIFFDirEntry), SEEK_CUR);
+               if (!ReadOK(tif, &nextdir, sizeof (nextdir))) {
+                       TIFFError(module, "Error fetching directory link");
+                       return (0);
+               }
+               if (tif->tif_flags & TIFF_SWAB)
+                       TIFFSwabLong(&nextdir);
+       } while (nextdir != tif->tif_diroff && nextdir != 0);
+        off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
+        (void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
+        tif->tif_diroff = 0;
+       if (!WriteOK(tif, &(tif->tif_diroff), sizeof (nextdir))) {
+               TIFFError(module, "Error writing directory link");
+               return (0);
+       }
+    }
+
+    /*
+    ** Now use TIFFWriteDirectory() normally.
+    */
+
+    return TIFFWriteDirectory( tif );
+}
+
+
 /*
  * Link the current directory into the
  * directory chain for the file.
 /*
  * Link the current directory into the
  * directory chain for the file.
@@ -950,11 +1182,11 @@ static int
 TIFFLinkDirectory(TIFF* tif)
 {
        static const char module[] = "TIFFLinkDirectory";
 TIFFLinkDirectory(TIFF* tif)
 {
        static const char module[] = "TIFFLinkDirectory";
-       uint32 nextdir;
-       uint32 diroff;
+       toff_t nextdir;
+       toff_t diroff, off;
 
        tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
 
        tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
-       diroff = (uint32) tif->tif_diroff;
+       diroff = tif->tif_diroff;
        if (tif->tif_flags & TIFF_SWAB)
                TIFFSwabLong(&diroff);
 #if SUBIFD_SUPPORT
        if (tif->tif_flags & TIFF_SWAB)
                TIFFSwabLong(&diroff);
 #if SUBIFD_SUPPORT
@@ -982,7 +1214,7 @@ TIFFLinkDirectory(TIFF* tif)
                /*
                 * First directory, overwrite offset in header.
                 */
                /*
                 * First directory, overwrite offset in header.
                 */
-               tif->tif_header.tiff_diroff = (uint32) tif->tif_diroff;
+               tif->tif_header.tiff_diroff = tif->tif_diroff;
 #define        HDROFF(f)       ((toff_t) &(((TIFFHeader*) 0)->f))
                (void) TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
                if (!WriteOK(tif, &diroff, sizeof (diroff))) {
 #define        HDROFF(f)       ((toff_t) &(((TIFFHeader*) 0)->f))
                (void) TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
                if (!WriteOK(tif, &diroff, sizeof (diroff))) {
@@ -1014,7 +1246,8 @@ TIFFLinkDirectory(TIFF* tif)
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabLong(&nextdir);
        } while (nextdir != 0);
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabLong(&nextdir);
        } while (nextdir != 0);
-       (void) TIFFSeekFile(tif, -(toff_t) sizeof (nextdir), SEEK_CUR);
+        off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
+        (void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
                TIFFError(module, "Error writing directory link");
                return (0);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
                TIFFError(module, "Error writing directory link");
                return (0);
index 3fbcc11643de356b19410d410e3b98ff5168fb93..ccb57f71c10f4eb7ca163b1d6109770dd1038ba1 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  * "Null" Compression Algorithm Support.
  */
 #include "tiffiop.h"
  * "Null" Compression Algorithm Support.
  */
 #include "tiffiop.h"
+#include <assert.h>
 
 /*
  * Encode a hunk of pixels.
  */
 
 /*
  * Encode a hunk of pixels.
  */
-static int LINKAGEMODE
+static int
 DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
        (void) s;
 DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 {
        (void) s;
@@ -44,6 +45,9 @@ DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
                n = cc;
                if (tif->tif_rawcc + n > tif->tif_rawdatasize)
                        n = tif->tif_rawdatasize - tif->tif_rawcc;
                n = cc;
                if (tif->tif_rawcc + n > tif->tif_rawdatasize)
                        n = tif->tif_rawdatasize - tif->tif_rawcc;
+
+                assert( n > 0 );
+                
                /*
                 * Avoid copy if client has setup raw
                 * data buffer to avoid extra copy.
                /*
                 * Avoid copy if client has setup raw
                 * data buffer to avoid extra copy.
@@ -64,7 +68,7 @@ DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
 /*
  * Decode a hunk of pixels.
  */
 /*
  * Decode a hunk of pixels.
  */
-static int LINKAGEMODE
+static int
 DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        (void) s;
 DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        (void) s;
@@ -88,7 +92,7 @@ DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 /*
  * Seek forwards nrows in the current strip.
  */
 /*
  * Seek forwards nrows in the current strip.
  */
-static int LINKAGEMODE
+static int
 DumpModeSeek(TIFF* tif, uint32 nrows)
 {
        tif->tif_rawcp += nrows * tif->tif_scanlinesize;
 DumpModeSeek(TIFF* tif, uint32 nrows)
 {
        tif->tif_rawcp += nrows * tif->tif_scanlinesize;
index 8f100d87aa6510e1cfb17c0696cfd887894a4db8..e816107fc01979233aef31aa8e5875f8b69aa6aa 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
 #include <assert.h>
 #include <stdio.h>
 
 #include <assert.h>
 #include <stdio.h>
 
-/*
- * NB: define PURIFY if you're using purify and you want
- * to avoid some harmless array bounds complaints that
- * can happen in the _TIFFFax3fillruns routine.
- */
-
 /*
  * Compression+decompression state blocks are
  * derived from this ``base state'' block.
  */
 typedef struct {
 /*
  * Compression+decompression state blocks are
  * derived from this ``base state'' block.
  */
 typedef struct {
+        int     rw_mode;                /* O_RDONLY for decode, else encode */
        int     mode;                   /* operating mode */
        uint32  rowbytes;               /* bytes in a decoded scanline */
        uint32  rowpixels;              /* pixels in a scanline */
        int     mode;                   /* operating mode */
        uint32  rowbytes;               /* bytes in a decoded scanline */
        uint32  rowpixels;              /* pixels in a scanline */
@@ -71,8 +66,11 @@ typedef struct {
 } Fax3BaseState;
 #define        Fax3State(tif)          ((Fax3BaseState*) (tif)->tif_data)
 
 } Fax3BaseState;
 #define        Fax3State(tif)          ((Fax3BaseState*) (tif)->tif_data)
 
+typedef enum { G3_1D, G3_2D } Ttag;
 typedef struct {
        Fax3BaseState b;
 typedef struct {
        Fax3BaseState b;
+
+       /* Decoder state info */
        const u_char* bitmap;           /* bit reversal table */
        uint32  data;                   /* current i/o byte/word */
        int     bit;                    /* current i/o bit in byte */
        const u_char* bitmap;           /* bit reversal table */
        uint32  data;                   /* current i/o byte/word */
        int     bit;                    /* current i/o bit in byte */
@@ -81,19 +79,15 @@ typedef struct {
        uint32* runs;                   /* b&w runs for current/previous row */
        uint32* refruns;                /* runs for reference line */
        uint32* curruns;                /* runs for current line */
        uint32* runs;                   /* b&w runs for current/previous row */
        uint32* refruns;                /* runs for reference line */
        uint32* curruns;                /* runs for current line */
-} Fax3DecodeState;
-#define        DecoderState(tif)       ((Fax3DecodeState*) Fax3State(tif))
 
 
-typedef struct {
-    Fax3BaseState b;
-    int    data;                /* current i/o byte */
-    int    bit;                 /* current i/o bit in byte */
-    enum { G3_1D, G3_2D } tag;  /* encoding state */
-    u_char*    refline;         /* reference line for 2d decoding */
-    int    k;                   /* #rows left that can be 2d encoded */
-    int    maxk;                /* max #rows that can be 2d encoded */
-} Fax3EncodeState;
-#define        EncoderState(tif)       ((Fax3EncodeState*) Fax3State(tif))
+       /* Encoder state info */
+       Ttag    tag;                    /* encoding state */
+       u_char* refline;                /* reference line for 2d decoding */
+       int     k;                      /* #rows left that can be 2d encoded */
+       int     maxk;                   /* max #rows that can be 2d encoded */
+} Fax3CodecState;
+#define        DecoderState(tif)       ((Fax3CodecState*) Fax3State(tif))
+#define        EncoderState(tif)       ((Fax3CodecState*) Fax3State(tif))
 
 #define        is2DEncoding(sp) \
        (sp->b.groupoptions & GROUP3OPT_2DENCODING)
 
 #define        is2DEncoding(sp) \
        (sp->b.groupoptions & GROUP3OPT_2DENCODING)
@@ -109,7 +103,7 @@ typedef struct {
  */
 #define        DECLARE_STATE(tif, sp, mod)                                     \
     static const char module[] = mod;                                  \
  */
 #define        DECLARE_STATE(tif, sp, mod)                                     \
     static const char module[] = mod;                                  \
-    Fax3DecodeState* sp = DecoderState(tif);                           \
+    Fax3CodecState* sp = DecoderState(tif);                            \
     int a0;                            /* reference element */         \
     int lastx = sp->b.rowpixels;       /* last element in row */       \
     uint32 BitAcc;                     /* bit accumulator */           \
     int a0;                            /* reference element */         \
     int lastx = sp->b.rowpixels;       /* last element in row */       \
     uint32 BitAcc;                     /* bit accumulator */           \
@@ -153,7 +147,7 @@ typedef struct {
 static int
 Fax3PreDecode(TIFF* tif, tsample_t s)
 {
 static int
 Fax3PreDecode(TIFF* tif, tsample_t s)
 {
-       Fax3DecodeState* sp = DecoderState(tif);
+       Fax3CodecState* sp = DecoderState(tif);
 
        (void) s;
        assert(sp != NULL);
 
        (void) s;
        assert(sp != NULL);
@@ -170,7 +164,7 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
        sp->bitmap =
            TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB);
        if (sp->refruns) {              /* init reference line to white */
        sp->bitmap =
            TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB);
        if (sp->refruns) {              /* init reference line to white */
-               sp->refruns[0] = sp->b.rowpixels;
+               sp->refruns[0] = (uint32) sp->b.rowpixels;
                sp->refruns[1] = 0;
        }
        return (1);
                sp->refruns[1] = 0;
        }
        return (1);
@@ -182,7 +176,7 @@ Fax3PreDecode(TIFF* tif, tsample_t s)
  * overriding the definitions used by the decoder.
  */
 
  * overriding the definitions used by the decoder.
  */
 
-static void LINKAGEMODE
+static void
 Fax3Unexpected(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFError(module, "%s: Bad code word at scanline %d (x %lu)",
 Fax3Unexpected(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFError(module, "%s: Bad code word at scanline %d (x %lu)",
@@ -190,7 +184,7 @@ Fax3Unexpected(const char* module, TIFF* tif, uint32 a0)
 }
 #define        unexpected(table, a0)   Fax3Unexpected(module, tif, a0)
 
 }
 #define        unexpected(table, a0)   Fax3Unexpected(module, tif, a0)
 
-static void LINKAGEMODE
+static void
 Fax3Extension(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFError(module,
 Fax3Extension(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFError(module,
@@ -199,7 +193,7 @@ Fax3Extension(const char* module, TIFF* tif, uint32 a0)
 }
 #define        extension(a0)   Fax3Extension(module, tif, a0)
 
 }
 #define        extension(a0)   Fax3Extension(module, tif, a0)
 
-static void LINKAGEMODE
+static void
 Fax3BadLength(const char* module, TIFF* tif, uint32 a0, uint32 lastx)
 {
        TIFFWarning(module, "%s: %s at scanline %d (got %lu, expected %lu)",
 Fax3BadLength(const char* module, TIFF* tif, uint32 a0, uint32 lastx)
 {
        TIFFWarning(module, "%s: %s at scanline %d (got %lu, expected %lu)",
@@ -209,7 +203,7 @@ Fax3BadLength(const char* module, TIFF* tif, uint32 a0, uint32 lastx)
 }
 #define        badlength(a0,lastx)     Fax3BadLength(module, tif, a0, lastx)
 
 }
 #define        badlength(a0,lastx)     Fax3BadLength(module, tif, a0, lastx)
 
-static void LINKAGEMODE
+static void
 Fax3PrematureEOF(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFWarning(module, "%s: Premature EOF at scanline %d (x %lu)",
 Fax3PrematureEOF(const char* module, TIFF* tif, uint32 a0)
 {
        TIFFWarning(module, "%s: Premature EOF at scanline %d (x %lu)",
@@ -222,7 +216,7 @@ Fax3PrematureEOF(const char* module, TIFF* tif, uint32 a0)
 /*
  * Decode the requested amount of G3 1D-encoded data.
  */
 /*
  * Decode the requested amount of G3 1D-encoded data.
  */
-static int LINKAGEMODE
+static int
 Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE(tif, sp, "Fax3Decode1D");
 Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE(tif, sp, "Fax3Decode1D");
@@ -244,8 +238,6 @@ Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                (*sp->fill)(buf, thisrun, pa, lastx);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
                (*sp->fill)(buf, thisrun, pa, lastx);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
-               if (occ != 0)
-                       tif->tif_row++;
                continue;
        EOF1D:                          /* premature EOF */
                CLEANUP_RUNS();
                continue;
        EOF1D:                          /* premature EOF */
                CLEANUP_RUNS();
@@ -262,7 +254,7 @@ Fax3Decode1D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 /*
  * Decode the requested amount of G3 2D-encoded data.
  */
 /*
  * Decode the requested amount of G3 2D-encoded data.
  */
-static int LINKAGEMODE
+static int
 Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE_2D(tif, sp, "Fax3Decode2D");
 Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE_2D(tif, sp, "Fax3Decode2D");
@@ -298,8 +290,6 @@ Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                SWAP(uint32*, sp->curruns, sp->refruns);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
                SWAP(uint32*, sp->curruns, sp->refruns);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
-               if (occ != 0)
-                       tif->tif_row++;
                continue;
        EOF2D:                          /* premature EOF */
                CLEANUP_RUNS();
                continue;
        EOF2D:                          /* premature EOF */
                CLEANUP_RUNS();
@@ -319,7 +309,7 @@ Fax3Decode2D(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
  * this is <8 bytes.  We optimize the code here to reflect the
  * machine characteristics.
  */
  * this is <8 bytes.  We optimize the code here to reflect the
  * machine characteristics.
  */
-#if defined(__alpha) || _MIPS_SZLONG == 64
+#if defined(__alpha) || _MIPS_SZLONG == 64 || defined(__LP64__) || defined(__arch64__)
 #define FILL(n, cp)                                                        \
     switch (n) {                                                           \
     case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\
 #define FILL(n, cp)                                                        \
     switch (n) {                                                           \
     case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\
@@ -372,8 +362,8 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
        x = 0;
        for (; runs < erun; runs += 2) {
            run = runs[0];
        x = 0;
        for (; runs < erun; runs += 2) {
            run = runs[0];
-           if (x+run > lastx)
-               run = runs[0] = lastx - x;
+           if (x+run > lastx || run > lastx )
+               run = runs[0] = (uint32) (lastx - x);
            if (run) {
                cp = buf + (x>>3);
                bx = x&7;
            if (run) {
                cp = buf + (x>>3);
                bx = x&7;
@@ -400,18 +390,14 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
                        ZERO(n, cp);
                        run &= 7;
                    }
                        ZERO(n, cp);
                        run &= 7;
                    }
-#ifdef PURIFY
                    if (run)
                        cp[0] &= 0xff >> run;
                    if (run)
                        cp[0] &= 0xff >> run;
-#else
-                   cp[0] &= 0xff >> run;
-#endif
                } else
                    cp[0] &= ~(_fillmasks[run]>>bx);
                x += runs[0];
            }
            run = runs[1];
                } else
                    cp[0] &= ~(_fillmasks[run]>>bx);
                x += runs[0];
            }
            run = runs[1];
-           if (x+run > lastx)
+           if (x+run > lastx || run > lastx )
                run = runs[1] = lastx - x;
            if (run) {
                cp = buf + (x>>3);
                run = runs[1] = lastx - x;
            if (run) {
                cp = buf + (x>>3);
@@ -439,12 +425,8 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
                        FILL(n, cp);
                        run &= 7;
                    }
                        FILL(n, cp);
                        run &= 7;
                    }
-#ifdef PURIFY
                    if (run)
                        cp[0] |= 0xff00 >> run;
                    if (run)
                        cp[0] |= 0xff00 >> run;
-#else
-                   cp[0] |= 0xff00 >> run;
-#endif
                } else
                    cp[0] |= _fillmasks[run]>>bx;
                x += runs[1];
                } else
                    cp[0] |= _fillmasks[run]>>bx;
                x += runs[1];
@@ -455,6 +437,21 @@ _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32 lastx)
 #undef ZERO
 #undef FILL
 
 #undef ZERO
 #undef FILL
 
+static char *
+CheckMalloc(TIFF* tif, size_t nmemb, size_t elem_size, const char* what)
+{
+       char    *cp = NULL;
+       tsize_t bytes = nmemb * elem_size;
+
+       if (elem_size && bytes / elem_size == nmemb)
+               cp = (char*) _TIFFmalloc(bytes);
+
+       if (cp == NULL)
+               TIFFError(tif->tif_name, "No space %s", what);
+       
+       return (cp);
+}
+
 /*
  * Setup G3/G4-related compression/decompression state
  * before data is processed.  This routine is called once
 /*
  * Setup G3/G4-related compression/decompression state
  * before data is processed.  This routine is called once
@@ -469,6 +466,8 @@ Fax3SetupState(TIFF* tif)
        Fax3BaseState* sp = Fax3State(tif);
        long rowbytes, rowpixels;
        int needsRefLine;
        Fax3BaseState* sp = Fax3State(tif);
        long rowbytes, rowpixels;
        int needsRefLine;
+       Fax3CodecState* dsp = DecoderState(tif);
+       uint32 nruns;
 
        if (td->td_bitspersample != 1) {
                TIFFError(tif->tif_name,
 
        if (td->td_bitspersample != 1) {
                TIFFError(tif->tif_name,
@@ -494,31 +493,26 @@ Fax3SetupState(TIFF* tif)
            (sp->groupoptions & GROUP3OPT_2DENCODING) ||
            td->td_compression == COMPRESSION_CCITTFAX4
        );
            (sp->groupoptions & GROUP3OPT_2DENCODING) ||
            td->td_compression == COMPRESSION_CCITTFAX4
        );
-       if (tif->tif_mode == O_RDONLY) {        /* 1d/2d decoding */
-               Fax3DecodeState* dsp = DecoderState(tif);
-               uint32 nruns = needsRefLine ?
-                    2*TIFFroundup(rowpixels,32) : rowpixels;
 
 
-               dsp->runs = (uint32*) _TIFFmalloc((2*nruns+3)*sizeof (uint32));
+       nruns = needsRefLine ? 2*TIFFroundup(rowpixels,32) : rowpixels;
 
 
-               if (dsp->runs == NULL) {
-                       TIFFError("Fax3SetupState",
-                           "%s: No space for Group 3/4 run arrays",
-                           tif->tif_name);
-                       return (0);
-               }
-               dsp->curruns = dsp->runs;
-               if (needsRefLine)
-                       dsp->refruns = dsp->runs + (nruns>>1);
-               else
-                       dsp->refruns = NULL;
-               if (is2DEncoding(dsp)) {        /* NB: default is 1D routine */
-                       tif->tif_decoderow = Fax3Decode2D;
-                       tif->tif_decodestrip = Fax3Decode2D;
-                       tif->tif_decodetile = Fax3Decode2D;
-               }
-       } else if (needsRefLine) {              /* 2d encoding */
-               Fax3EncodeState* esp = EncoderState(tif);
+       dsp->runs = (uint32*) CheckMalloc(tif, 2*nruns+3, sizeof (uint32),
+                                         "for Group 3/4 run arrays");
+       if (dsp->runs == NULL)
+               return (0);
+       dsp->curruns = dsp->runs;
+       if (needsRefLine)
+               dsp->refruns = dsp->runs + (nruns>>1);
+       else
+               dsp->refruns = NULL;
+       if (is2DEncoding(dsp)) {        /* NB: default is 1D routine */
+               tif->tif_decoderow = Fax3Decode2D;
+               tif->tif_decodestrip = Fax3Decode2D;
+               tif->tif_decodetile = Fax3Decode2D;
+       }
+
+       if (needsRefLine) {             /* 2d encoding */
+               Fax3CodecState* esp = EncoderState(tif);
                /*
                 * 2d encoding requires a scanline
                 * buffer for the ``reference line''; the
                /*
                 * 2d encoding requires a scanline
                 * buffer for the ``reference line''; the
@@ -545,14 +539,14 @@ Fax3SetupState(TIFF* tif)
 #define        Fax3FlushBits(tif, sp) {                                \
        if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize)         \
                (void) TIFFFlushData1(tif);                     \
 #define        Fax3FlushBits(tif, sp) {                                \
        if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize)         \
                (void) TIFFFlushData1(tif);                     \
-       *(tif)->tif_rawcp++ = (sp)->data;                       \
+       *(tif)->tif_rawcp++ = (tidataval_t) (sp)->data;         \
        (tif)->tif_rawcc++;                                     \
        (sp)->data = 0, (sp)->bit = 8;                          \
 }
 #define        _FlushBits(tif) {                                       \
        if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize)         \
                (void) TIFFFlushData1(tif);                     \
        (tif)->tif_rawcc++;                                     \
        (sp)->data = 0, (sp)->bit = 8;                          \
 }
 #define        _FlushBits(tif) {                                       \
        if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize)         \
                (void) TIFFFlushData1(tif);                     \
-       *(tif)->tif_rawcp++ = data;                             \
+       *(tif)->tif_rawcp++ = (tidataval_t) data;               \
        (tif)->tif_rawcc++;                                     \
        data = 0, bit = 8;                                      \
 }
        (tif)->tif_rawcc++;                                     \
        data = 0, bit = 8;                                      \
 }
@@ -575,11 +569,11 @@ static const int _msbmask[9] =
  * the output stream.  Values are
  * assumed to be at most 16 bits.
  */
  * the output stream.  Values are
  * assumed to be at most 16 bits.
  */
-static void LINKAGEMODE
+static void
 Fax3PutBits(TIFF* tif, u_int bits, u_int length)
 {
 Fax3PutBits(TIFF* tif, u_int bits, u_int length)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
-       int bit = sp->bit;
+       Fax3CodecState* sp = EncoderState(tif);
+       u_int bit = sp->bit;
        int data = sp->data;
 
        _PutBits(tif, bits, length);
        int data = sp->data;
 
        _PutBits(tif, bits, length);
@@ -610,11 +604,11 @@ Fax3PutBits(TIFF* tif, u_int bits, u_int length)
  * appropriate table that holds the make-up and
  * terminating codes is supplied.
  */
  * appropriate table that holds the make-up and
  * terminating codes is supplied.
  */
-static void LINKAGEMODE
+static void
 putspan(TIFF* tif, int32 span, const tableentry* tab)
 {
 putspan(TIFF* tif, int32 span, const tableentry* tab)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
-       int bit = sp->bit;
+       Fax3CodecState* sp = EncoderState(tif);
+       u_int bit = sp->bit;
        int data = sp->data;
        u_int code, length;
 
        int data = sp->data;
        u_int code, length;
 
@@ -653,13 +647,13 @@ putspan(TIFF* tif, int32 span, const tableentry* tab)
  * here.  We also handle writing the tag bit for the next
  * scanline when doing 2d encoding.
  */
  * here.  We also handle writing the tag bit for the next
  * scanline when doing 2d encoding.
  */
-static void LINKAGEMODE
+static void
 Fax3PutEOL(TIFF* tif)
 {
 Fax3PutEOL(TIFF* tif)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
-       int bit = sp->bit;
+       Fax3CodecState* sp = EncoderState(tif);
+       u_int bit = sp->bit;
        int data = sp->data;
        int data = sp->data;
-       u_int code, length;
+       u_int code, length, tparm;
 
        if (sp->b.groupoptions & GROUP3OPT_FILLBITS) {
                /*
 
        if (sp->b.groupoptions & GROUP3OPT_FILLBITS) {
                /*
@@ -674,17 +668,13 @@ Fax3PutEOL(TIFF* tif)
                        else
                                align = sp->bit - align;
                        code = 0;
                        else
                                align = sp->bit - align;
                        code = 0;
-                       _PutBits(tif, 0, align);
+                       tparm=align; 
+                       _PutBits(tif, 0, tparm);
                }
        }
        code = EOL, length = 12;
        if (is2DEncoding(sp))
                }
        }
        code = EOL, length = 12;
        if (is2DEncoding(sp))
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-               code = (code<<1) | (sp->tag == Fax3EncodeState::G3_1D), length++;
-#else
                code = (code<<1) | (sp->tag == G3_1D), length++;
                code = (code<<1) | (sp->tag == G3_1D), length++;
-#endif
        _PutBits(tif, code, length);
 
        sp->data = data;
        _PutBits(tif, code, length);
 
        sp->data = data;
@@ -697,18 +687,13 @@ Fax3PutEOL(TIFF* tif)
 static int
 Fax3PreEncode(TIFF* tif, tsample_t s)
 {
 static int
 Fax3PreEncode(TIFF* tif, tsample_t s)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
+       Fax3CodecState* sp = EncoderState(tif);
 
        (void) s;
        assert(sp != NULL);
        sp->bit = 8;
        sp->data = 0;
 
        (void) s;
        assert(sp != NULL);
        sp->bit = 8;
        sp->data = 0;
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-       sp->tag = Fax3EncodeState::G3_1D;
-#else
        sp->tag = G3_1D;
        sp->tag = G3_1D;
-#endif
        /*
         * This is necessary for Group 4; otherwise it isn't
         * needed because the first scanline of each strip ends
        /*
         * This is necessary for Group 4; otherwise it isn't
         * needed because the first scanline of each strip ends
@@ -789,7 +774,7 @@ static      int32 find1span(u_char*, int32, int32);
  * table.  The ``base'' of the bit string is supplied
  * along with the start+end bit indices.
  */
  * table.  The ``base'' of the bit string is supplied
  * along with the start+end bit indices.
  */
-INLINE static int32 LINKAGEMODE
+INLINE static int32
 find0span(u_char* bp, int32 bs, int32 be)
 {
        int32 bits = be - bs;
 find0span(u_char* bp, int32 bs, int32 be)
 {
        int32 bits = be - bs;
@@ -848,7 +833,7 @@ find0span(u_char* bp, int32 bs, int32 be)
        return (span);
 }
 
        return (span);
 }
 
-INLINE static int32 LINKAGEMODE
+INLINE static int32
 find1span(u_char* bp, int32 bs, int32 be)
 {
        int32 bits = be - bs;
 find1span(u_char* bp, int32 bs, int32 be)
 {
        int32 bits = be - bs;
@@ -927,11 +912,12 @@ find1span(u_char* bp, int32 bs, int32 be)
  * a sequence of all-white or all-black spans
  * of pixels encoded with Huffman codes.
  */
  * a sequence of all-white or all-black spans
  * of pixels encoded with Huffman codes.
  */
-static int LINKAGEMODE
+static int
 Fax3Encode1DRow(TIFF* tif, u_char* bp, uint32 bits)
 {
 Fax3Encode1DRow(TIFF* tif, u_char* bp, uint32 bits)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
-       int32 bs = 0, span;
+       Fax3CodecState* sp = EncoderState(tif);
+       int32 span;
+        uint32 bs = 0;
 
        for (;;) {
                span = find0span(bp, bs, bits);         /* white span */
 
        for (;;) {
                span = find0span(bp, bs, bits);         /* white span */
@@ -973,14 +959,14 @@ static const tableentry vcodes[7] = {
  * 2d-encode a row of pixels.  Consult the CCITT
  * documentation for the algorithm.
  */
  * 2d-encode a row of pixels.  Consult the CCITT
  * documentation for the algorithm.
  */
-static int LINKAGEMODE
+static int
 Fax3Encode2DRow(TIFF* tif, u_char* bp, u_char* rp, uint32 bits)
 {
 #define        PIXEL(buf,ix)   ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1)
 Fax3Encode2DRow(TIFF* tif, u_char* bp, u_char* rp, uint32 bits)
 {
 #define        PIXEL(buf,ix)   ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1)
-       int32 a0 = 0;
-       int32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0));
-       int32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0));
-       int32 a2, b2;
+        uint32 a0 = 0;
+       uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0));
+       uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0));
+       uint32 a2, b2;
 
        for (;;) {
                b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1));
 
        for (;;) {
                b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1));
@@ -1018,42 +1004,27 @@ Fax3Encode2DRow(TIFF* tif, u_char* bp, u_char* rp, uint32 bits)
 /*
  * Encode a buffer of pixels.
  */
 /*
  * Encode a buffer of pixels.
  */
-static int LINKAGEMODE
+static int
 Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
 Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
+       Fax3CodecState* sp = EncoderState(tif);
 
        (void) s;
        while ((long)cc > 0) {
                if ((sp->b.mode & FAXMODE_NOEOL) == 0)
                        Fax3PutEOL(tif);
                if (is2DEncoding(sp)) {
 
        (void) s;
        while ((long)cc > 0) {
                if ((sp->b.mode & FAXMODE_NOEOL) == 0)
                        Fax3PutEOL(tif);
                if (is2DEncoding(sp)) {
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-                       if (sp->tag == Fax3EncodeState::G3_1D) {
-#else
                        if (sp->tag == G3_1D) {
                        if (sp->tag == G3_1D) {
-#endif
                                if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels))
                                        return (0);
                                if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels))
                                        return (0);
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-                               sp->tag = Fax3EncodeState::G3_2D;
-#else
                                sp->tag = G3_2D;
                                sp->tag = G3_2D;
-#endif
                        } else {
                                if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->b.rowpixels))
                                        return (0);
                                sp->k--;
                        }
                        if (sp->k == 0) {
                        } else {
                                if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->b.rowpixels))
                                        return (0);
                                sp->k--;
                        }
                        if (sp->k == 0) {
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-                               sp->tag = Fax3EncodeState::G3_1D;
-#else
                                sp->tag = G3_1D;
                                sp->tag = G3_1D;
-#endif
                                sp->k = sp->maxk-1;
                        } else
                                _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
                                sp->k = sp->maxk-1;
                        } else
                                _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
@@ -1063,8 +1034,6 @@ Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                }
                bp += sp->b.rowbytes;
                cc -= sp->b.rowbytes;
                }
                bp += sp->b.rowbytes;
                cc -= sp->b.rowbytes;
-               if (cc != 0)
-                       tif->tif_row++;
        }
        return (1);
 }
        }
        return (1);
 }
@@ -1072,7 +1041,7 @@ Fax3Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 static int
 Fax3PostEncode(TIFF* tif)
 {
 static int
 Fax3PostEncode(TIFF* tif)
 {
-       Fax3EncodeState* sp = EncoderState(tif);
+       Fax3CodecState* sp = EncoderState(tif);
 
        if (sp->bit != 8)
                Fax3FlushBits(tif, sp);
 
        if (sp->bit != 8)
                Fax3FlushBits(tif, sp);
@@ -1083,18 +1052,13 @@ static void
 Fax3Close(TIFF* tif)
 {
        if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) {
 Fax3Close(TIFF* tif)
 {
        if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) {
-               Fax3EncodeState* sp = EncoderState(tif);
+               Fax3CodecState* sp = EncoderState(tif);
                u_int code = EOL;
                u_int length = 12;
                int i;
 
                if (is2DEncoding(sp))
                u_int code = EOL;
                u_int length = 12;
                int i;
 
                if (is2DEncoding(sp))
-#if defined(__VISAGECPP30__)
-/* VA 3.0 is just plain wierd. */
-                       code = (code<<1) | (sp->tag == Fax3EncodeState::G3_1D), length++;
-#else
                        code = (code<<1) | (sp->tag == G3_1D), length++;
                        code = (code<<1) | (sp->tag == G3_1D), length++;
-#endif
                for (i = 0; i < 6; i++)
                        Fax3PutBits(tif, code, length);
                Fax3FlushBits(tif, sp);
                for (i = 0; i < 6; i++)
                        Fax3PutBits(tif, code, length);
                Fax3FlushBits(tif, sp);
@@ -1105,15 +1069,13 @@ static void
 Fax3Cleanup(TIFF* tif)
 {
        if (tif->tif_data) {
 Fax3Cleanup(TIFF* tif)
 {
        if (tif->tif_data) {
-               if (tif->tif_mode == O_RDONLY) {
-                       Fax3DecodeState* sp = DecoderState(tif);
-                       if (sp->runs)
-                               _TIFFfree(sp->runs);
-               } else {
-                       Fax3EncodeState* sp = EncoderState(tif);
-                       if (sp->refline)
-                               _TIFFfree(sp->refline);
-               }
+               Fax3CodecState* sp = DecoderState(tif);
+
+               if (sp->runs)
+                       _TIFFfree(sp->runs);
+               if (sp->refline)
+                       _TIFFfree(sp->refline);
+
                if (Fax3State(tif)->subaddress)
                        _TIFFfree(Fax3State(tif)->subaddress);
                _TIFFfree(tif->tif_data);
                if (Fax3State(tif)->subaddress)
                        _TIFFfree(Fax3State(tif)->subaddress);
                _TIFFfree(tif->tif_data);
@@ -1172,8 +1134,7 @@ Fax3VSetField(TIFF* tif, ttag_t tag, va_list ap)
                sp->mode = va_arg(ap, int);
                return (1);                     /* NB: pseudo tag */
        case TIFFTAG_FAXFILLFUNC:
                sp->mode = va_arg(ap, int);
                return (1);                     /* NB: pseudo tag */
        case TIFFTAG_FAXFILLFUNC:
-               if (tif->tif_mode == O_RDONLY)
-                       DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc);
+               DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc);
                return (1);                     /* NB: pseudo tag */
        case TIFFTAG_GROUP3OPTIONS:
        case TIFFTAG_GROUP4OPTIONS:
                return (1);                     /* NB: pseudo tag */
        case TIFFTAG_GROUP3OPTIONS:
        case TIFFTAG_GROUP4OPTIONS:
@@ -1215,8 +1176,7 @@ Fax3VGetField(TIFF* tif, ttag_t tag, va_list ap)
                *va_arg(ap, int*) = sp->mode;
                break;
        case TIFFTAG_FAXFILLFUNC:
                *va_arg(ap, int*) = sp->mode;
                break;
        case TIFFTAG_FAXFILLFUNC:
-               if (tif->tif_mode == O_RDONLY)
-                       *va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill;
+               *va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill;
                break;
        case TIFFTAG_GROUP3OPTIONS:
        case TIFFTAG_GROUP4OPTIONS:
                break;
        case TIFFTAG_GROUP3OPTIONS:
        case TIFFTAG_GROUP4OPTIONS:
@@ -1246,7 +1206,7 @@ Fax3VGetField(TIFF* tif, ttag_t tag, va_list ap)
        return (1);
 }
 
        return (1);
 }
 
-static void LINKAGEMODE
+static void
 Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
 {
        Fax3BaseState* sp = Fax3State(tif);
 Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
 {
        Fax3BaseState* sp = Fax3State(tif);
@@ -1302,7 +1262,7 @@ Fax3PrintDir(TIFF* tif, FILE* fd, long flags)
                    (u_long) sp->recvtime);
 }
 
                    (u_long) sp->recvtime);
 }
 
-static int LINKAGEMODE
+static int
 InitCCITTFax3(TIFF* tif)
 {
        Fax3BaseState* sp;
 InitCCITTFax3(TIFF* tif)
 {
        Fax3BaseState* sp;
@@ -1310,43 +1270,36 @@ InitCCITTFax3(TIFF* tif)
        /*
         * Allocate state block so tag methods have storage to record values.
         */
        /*
         * Allocate state block so tag methods have storage to record values.
         */
-       if (tif->tif_mode == O_RDONLY)
-#if defined(__VISAGECPP__)
-               tif->tif_data = (tidata_t)_TIFFmalloc(sizeof (Fax3DecodeState));
-       else
-               tif->tif_data = (tidata_t)_TIFFmalloc(sizeof (Fax3EncodeState));
-#else
-               tif->tif_data = _TIFFmalloc(sizeof (Fax3DecodeState));
-       else
-               tif->tif_data = _TIFFmalloc(sizeof (Fax3EncodeState));
-#endif
+       tif->tif_data = (tidata_t)
+               _TIFFmalloc(sizeof (Fax3CodecState));
+
        if (tif->tif_data == NULL) {
                TIFFError("TIFFInitCCITTFax3",
                    "%s: No space for state block", tif->tif_name);
                return (0);
        }
        if (tif->tif_data == NULL) {
                TIFFError("TIFFInitCCITTFax3",
                    "%s: No space for state block", tif->tif_name);
                return (0);
        }
+
        sp = Fax3State(tif);
        sp = Fax3State(tif);
+        sp->rw_mode = tif->tif_mode;
 
        /*
         * Merge codec-specific tag information and
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo));
 
        /*
         * Merge codec-specific tag information and
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = Fax3VGetField;     /* hook for codec tags */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = Fax3VSetField;     /* hook for codec tags */
-       tif->tif_printdir = Fax3PrintDir;       /* hook for codec tags */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield = Fax3VGetField;  /* hook for codec tags */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield = Fax3VSetField;  /* hook for codec tags */
+       tif->tif_tagmethods.printdir = Fax3PrintDir;    /* hook for codec tags */
        sp->groupoptions = 0;   
        sp->recvparams = 0;
        sp->subaddress = NULL;
 
        sp->groupoptions = 0;   
        sp->recvparams = 0;
        sp->subaddress = NULL;
 
-       if (tif->tif_mode == O_RDONLY) {
-               tif->tif_flags |= TIFF_NOBITREV;/* decoder does bit reversal */
-               DecoderState(tif)->runs = NULL;
-               TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns);
-       } else
-               EncoderState(tif)->refline = NULL;
+       tif->tif_flags |= TIFF_NOBITREV;        /* decoder does bit reversal */
+       DecoderState(tif)->runs = NULL;
+       TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns);
+       EncoderState(tif)->refline = NULL;
 
        /*
         * Install codec methods.
 
        /*
         * Install codec methods.
@@ -1391,7 +1344,7 @@ TIFFInitCCITTFax3(TIFF* tif, int scheme)
 /*
  * Decode the requested amount of G4-encoded data.
  */
 /*
  * Decode the requested amount of G4-encoded data.
  */
-static int LINKAGEMODE
+static int
 Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE_2D(tif, sp, "Fax4Decode");
 Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE_2D(tif, sp, "Fax4Decode");
@@ -1410,15 +1363,22 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                fflush(stdout);
 #endif
                EXPAND2D(EOFG4);
                fflush(stdout);
 #endif
                EXPAND2D(EOFG4);
+                if (EOLcnt)
+                    goto EOFG4;
                (*sp->fill)(buf, thisrun, pa, lastx);
                SETVAL(0);              /* imaginary change for reference */
                SWAP(uint32*, sp->curruns, sp->refruns);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
                (*sp->fill)(buf, thisrun, pa, lastx);
                SETVAL(0);              /* imaginary change for reference */
                SWAP(uint32*, sp->curruns, sp->refruns);
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
-               if (occ != 0)
-                       tif->tif_row++;
                continue;
        EOFG4:
                continue;
        EOFG4:
+                NeedBits16( 13, BADG4 );
+        BADG4:
+#ifdef FAX3_DEBUG
+                if( GetBits(13) != 0x1001 )
+                    fputs( "Bad RTC\n", stderr );
+#endif                
+                ClrBits( 13 );
                (*sp->fill)(buf, thisrun, pa, lastx);
                UNCACHE_STATE(tif, sp);
                return (-1);
                (*sp->fill)(buf, thisrun, pa, lastx);
                UNCACHE_STATE(tif, sp);
                return (-1);
@@ -1431,10 +1391,10 @@ Fax4Decode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 /*
  * Encode the requested amount of data.
  */
 /*
  * Encode the requested amount of data.
  */
-static int LINKAGEMODE
+static int
 Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
 Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
-       Fax3EncodeState *sp = EncoderState(tif);
+       Fax3CodecState *sp = EncoderState(tif);
 
        (void) s;
        while ((long)cc > 0) {
 
        (void) s;
        while ((long)cc > 0) {
@@ -1443,8 +1403,6 @@ Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
                bp += sp->b.rowbytes;
                cc -= sp->b.rowbytes;
                _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes);
                bp += sp->b.rowbytes;
                cc -= sp->b.rowbytes;
-               if (cc != 0)
-                       tif->tif_row++;
        }
        return (1);
 }
        }
        return (1);
 }
@@ -1452,7 +1410,7 @@ Fax4Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 static int
 Fax4PostEncode(TIFF* tif)
 {
 static int
 Fax4PostEncode(TIFF* tif)
 {
-       Fax3EncodeState *sp = EncoderState(tif);
+       Fax3CodecState *sp = EncoderState(tif);
 
        /* terminate strip w/ EOFB */
        Fax3PutBits(tif, EOL, 12);
 
        /* terminate strip w/ EOFB */
        Fax3PutBits(tif, EOL, 12);
@@ -1491,7 +1449,7 @@ TIFFInitCCITTFax4(TIFF* tif, int scheme)
 /*
  * Decode the requested amount of RLE-encoded data.
  */
 /*
  * Decode the requested amount of RLE-encoded data.
  */
-static int LINKAGEMODE
+static int
 Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE(tif, sp, "Fax3DecodeRLE");
 Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        DECLARE_STATE(tif, sp, "Fax3DecodeRLE");
@@ -1525,8 +1483,6 @@ Fax3DecodeRLE(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                }
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
                }
                buf += sp->b.rowbytes;
                occ -= sp->b.rowbytes;
-               if (occ != 0)
-                       tif->tif_row++;
                continue;
        EOFRLE:                         /* premature EOF */
                (*sp->fill)(buf, thisrun, pa, lastx);
                continue;
        EOFRLE:                         /* premature EOF */
                (*sp->fill)(buf, thisrun, pa, lastx);
index a9f1fcb23b389f4dd08a641abae475ecb911bbf8..e64b145debf2990e9c6508b04d476168b9c6c7f8 100644 (file)
@@ -360,6 +360,8 @@ static const char* StateNames[] = {
     doneBlack1d:                                                       \
        if (a0 >= lastx)                                                \
            goto done1d;                                                \
     doneBlack1d:                                                       \
        if (a0 >= lastx)                                                \
            goto done1d;                                                \
+        if( *(pa-1) == 0 && *(pa-2) == 0 )                             \
+            pa -= 2;                                                    \
     }                                                                  \
 eof1d:                                                                 \
     prematureEOF(a0);                                                  \
     }                                                                  \
 eof1d:                                                                 \
     prematureEOF(a0);                                                  \
@@ -485,9 +487,10 @@ done1d:                                                                    \
            goto eol2d;                                                 \
        case S_EOL:                                                     \
            *pa++ = lastx - a0;                                         \
            goto eol2d;                                                 \
        case S_EOL:                                                     \
            *pa++ = lastx - a0;                                         \
-           NeedBits8(5,eof2d);                                         \
-           if (GetBits(5))                                             \
+           NeedBits8(4,eof2d);                                         \
+           if (GetBits(4))                                             \
                unexpected("EOL", a0);                                  \
                unexpected("EOL", a0);                                  \
+            ClrBits(4);                                                 \
            EOLcnt = 1;                                                 \
            goto eol2d;                                                 \
        default:                                                        \
            EOLcnt = 1;                                                 \
            goto eol2d;                                                 \
        default:                                                        \
index 7890951422cb33eb19c29105f86386369419b910..04de9bbf8b9ffe9bcfe7ea076470707e1b034191 100644 (file)
 #include "tiff.h"
 #include "tif_fax3.h"
  const TIFFFaxTabEnt TIFFFaxMainTable[128] = {
 #include "tiff.h"
 #include "tif_fax3.h"
  const TIFFFaxTabEnt TIFFFaxMainTable[128] = {
-       { 12,7,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 5,6,2 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 5,7,3 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 4,6,2 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 6,7,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 5,6,2 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 4,7,3 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 4,6,2 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
-       { 1,4,0 },
-       { 3,1,0 },
-       { 5,3,1 },
-       { 3,1,0 },
-       { 2,3,0 },
-       { 3,1,0 },
-       { 4,3,1 },
-       { 3,1,0 },
+12,7,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,1,4,0,3,1,0,5,3,1,3,1,0,
+2,3,0,3,1,0,4,3,1,3,1,0,5,6,2,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,
+1,4,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,5,7,3,3,1,0,5,3,1,3,1,0,
+2,3,0,3,1,0,4,3,1,3,1,0,1,4,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,
+4,6,2,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,1,4,0,3,1,0,5,3,1,3,1,0,
+2,3,0,3,1,0,4,3,1,3,1,0,6,7,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,
+1,4,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,5,6,2,3,1,0,5,3,1,3,1,0,
+2,3,0,3,1,0,4,3,1,3,1,0,1,4,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,
+4,7,3,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,1,4,0,3,1,0,5,3,1,3,1,0,
+2,3,0,3,1,0,4,3,1,3,1,0,4,6,2,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0,
+1,4,0,3,1,0,5,3,1,3,1,0,2,3,0,3,1,0,4,3,1,3,1,0
 };
  const TIFFFaxTabEnt TIFFFaxWhiteTable[4096] = {
 };
  const TIFFFaxTabEnt TIFFFaxWhiteTable[4096] = {
-       { 12,11,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,11,1792 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 11,11,1856 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2112 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2368 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 11,12,1984 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,11,1920 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2240 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 11,12,2496 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 12,11,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,11,1792 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,11,1856 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 11,12,2176 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2432 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2048 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 11,11,1920 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1472 },
-       { 7,4,5 },
-
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1216 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,960 },
-       { 7,4,6 },
-
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,704 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2304 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,832 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1600 },
-       { 7,4,5 },
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1344 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1088 },
-       { 7,4,6 },
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 0,0,0 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,39 },
-       { 7,6,16 },
-       { 9,8,576 },
-       { 7,4,6 },
-
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,55 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,45 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,8,53 },
-       { 7,5,9 },
-       { 9,8,448 },
-       { 7,4,6 },
-       { 7,8,35 },
-       { 9,5,128 },
-       { 7,8,51 },
-       { 7,6,15 },
-       { 7,8,63 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1536 },
-       { 7,4,5 },
-       { 7,8,43 },
-       { 7,6,17 },
-       { 9,9,1280 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,29 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-
-       { 7,8,33 },
-       { 9,5,128 },
-       { 7,8,49 },
-       { 7,6,14 },
-       { 7,8,61 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,47 },
-       { 7,4,3 },
-       { 7,8,59 },
-       { 7,4,5 },
-
-       { 7,8,41 },
-       { 7,6,16 },
-       { 9,9,1024 },
-       { 7,4,6 },
-       { 7,8,31 },
-       { 7,5,8 },
-       { 7,8,57 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,9,768 },
-       { 7,4,6 },
-       { 7,8,37 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-
-       { 9,8,320 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 11,12,2560 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,7,20 },
-       { 9,5,128 },
-       { 7,7,24 },
-       { 7,6,14 },
-       { 7,7,28 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,7,23 },
-       { 7,4,3 },
-       { 7,7,27 },
-       { 7,4,5 },
-       { 7,8,40 },
-       { 7,6,16 },
-       { 9,9,896 },
-       { 7,4,6 },
-       { 7,7,19 },
-       { 7,5,8 },
-       { 7,8,56 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,46 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,8,54 },
-       { 7,5,9 },
-       { 9,8,512 },
-       { 7,4,6 },
-
-       { 7,8,36 },
-       { 9,5,128 },
-       { 7,8,52 },
-       { 7,6,15 },
-       { 7,8,0 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,6,13 },
-       { 7,4,3 },
-       { 9,9,1728 },
-       { 7,4,5 },
-
-       { 7,8,44 },
-       { 7,6,17 },
-       { 9,9,1408 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,8,30 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-       { 7,6,12 },
-       { 7,5,9 },
-       { 9,6,1664 },
-       { 7,4,6 },
-       { 7,8,34 },
-       { 9,5,128 },
-       { 7,8,50 },
-       { 7,6,14 },
-
-       { 7,8,62 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,8,48 },
-       { 7,4,3 },
-       { 7,8,60 },
-       { 7,4,5 },
-       { 7,8,42 },
-       { 7,6,16 },
-       { 9,9,1152 },
-       { 7,4,6 },
-
-       { 7,8,32 },
-       { 7,5,8 },
-       { 7,8,58 },
-       { 9,5,64 },
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-       { 7,7,22 },
-       { 7,4,3 },
-       { 7,5,11 },
-       { 7,4,5 },
-
-       { 7,7,26 },
-       { 7,5,9 },
-       { 9,8,640 },
-       { 7,4,6 },
-       { 7,8,38 },
-       { 9,5,128 },
-       { 7,7,25 },
-       { 7,6,15 },
-       { 9,8,384 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
-
-       { 7,6,13 },
-       { 7,4,3 },
-       { 7,7,18 },
-       { 7,4,5 },
-       { 7,7,21 },
-       { 7,6,17 },
-       { 9,7,256 },
-       { 7,4,6 },
-       { 7,6,1 },
-       { 7,5,8 },
-       { 9,6,192 },
-       { 9,5,64 },
-
-       { 7,5,10 },
-       { 7,4,4 },
-       { 7,4,2 },
-       { 7,4,7 },
+12,11,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1472,7,4,5,7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,960,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,11,1792,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,
+7,8,44,7,6,17,9,9,1344,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,
+7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,
+7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,
+7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+11,11,1856,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,
+7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,
+7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1728,7,4,5,7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,
+7,8,42,7,6,16,9,9,1152,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,
+9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,
+7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1472,7,4,5,
+7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,
+7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,960,7,4,6,
+7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,11,12,2112,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,
+7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,7,8,44,7,6,17,9,9,1344,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,
+7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,
+7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,12,2368,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1728,7,4,5,
+7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1152,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,
+7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1472,7,4,5,7,8,43,7,6,17,9,9,1216,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,
+7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,960,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,704,7,4,6,
+7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+11,12,1984,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,832,7,4,6,
+7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,
+7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1600,7,4,5,7,8,44,7,6,17,9,9,1344,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,
+7,8,42,7,6,16,9,9,1088,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,
+9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,
+7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1536,7,4,5,
+7,8,43,7,6,17,9,9,1280,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,
+7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,1024,7,4,6,
+7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,9,768,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,11,11,1920,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,40,7,6,16,9,9,896,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,
+7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1728,7,4,5,7,8,44,7,6,17,9,9,1408,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,
+7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1152,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,
+7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1472,7,4,5,7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,960,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,12,2240,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,
+7,8,44,7,6,17,9,9,1344,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,
+7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,
+7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,
+7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+11,12,2496,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,
+7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,
+7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1728,7,4,5,7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,
+7,8,42,7,6,16,9,9,1152,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,
+9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,12,11,0,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,
+7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1472,7,4,5,
+7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,
+7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,960,7,4,6,
+7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,11,11,1792,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,
+7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,7,8,44,7,6,17,9,9,1344,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,
+7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,
+7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,11,1856,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1728,7,4,5,
+7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1152,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,
+7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1472,7,4,5,7,8,43,7,6,17,9,9,1216,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,
+7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,960,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,704,7,4,6,
+7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+11,12,2176,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,832,7,4,6,
+7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,
+7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1600,7,4,5,7,8,44,7,6,17,9,9,1344,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,
+7,8,42,7,6,16,9,9,1088,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,
+9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,
+7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1536,7,4,5,
+7,8,43,7,6,17,9,9,1280,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,
+7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,1024,7,4,6,
+7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,9,768,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,11,12,2432,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,40,7,6,16,9,9,896,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,
+7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1728,7,4,5,7,8,44,7,6,17,9,9,1408,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,
+7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1152,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,
+7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1472,7,4,5,7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,960,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,12,2048,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,
+7,8,44,7,6,17,9,9,1344,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,
+7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,
+7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,
+7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+11,11,1920,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,
+7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,
+7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1728,7,4,5,7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,
+7,8,42,7,6,16,9,9,1152,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,
+9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,0,0,0,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,7,7,19,7,5,8,7,8,55,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,7,8,53,7,5,9,9,8,448,7,4,6,
+7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1472,7,4,5,
+7,8,43,7,6,17,9,9,1216,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,33,9,5,128,7,8,49,7,6,14,
+7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,7,8,41,7,6,16,9,9,960,7,4,6,
+7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,9,704,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,9,8,320,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,11,12,2304,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,
+7,8,40,7,6,16,9,9,832,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,7,8,36,9,5,128,7,8,52,7,6,15,
+7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1600,7,4,5,7,8,44,7,6,17,9,9,1344,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,30,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,7,8,62,7,4,4,7,4,2,7,4,7,
+7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1088,7,4,6,7,8,32,7,5,8,7,8,58,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,8,640,7,4,6,
+7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,
+7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+0,0,0,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,
+7,7,28,7,4,4,7,4,2,7,4,7,7,7,23,7,4,3,7,7,27,7,4,5,7,8,39,7,6,16,9,8,576,7,4,6,
+7,7,19,7,5,8,7,8,55,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,8,45,7,4,3,7,5,11,7,4,5,
+7,8,53,7,5,9,9,8,448,7,4,6,7,8,35,9,5,128,7,8,51,7,6,15,7,8,63,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,9,9,1536,7,4,5,7,8,43,7,6,17,9,9,1280,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,29,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,
+7,8,33,9,5,128,7,8,49,7,6,14,7,8,61,7,4,4,7,4,2,7,4,7,7,8,47,7,4,3,7,8,59,7,4,5,
+7,8,41,7,6,16,9,9,1024,7,4,6,7,8,31,7,5,8,7,8,57,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,7,22,7,4,3,7,5,11,7,4,5,7,7,26,7,5,9,9,9,768,7,4,6,7,8,37,9,5,128,7,7,25,7,6,15,
+9,8,320,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,
+7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,11,12,2560,7,4,3,7,5,11,7,4,5,
+7,6,12,7,5,9,9,6,1664,7,4,6,7,7,20,9,5,128,7,7,24,7,6,14,7,7,28,7,4,4,7,4,2,7,4,7,
+7,7,23,7,4,3,7,7,27,7,4,5,7,8,40,7,6,16,9,9,896,7,4,6,7,7,19,7,5,8,7,8,56,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7,7,8,46,7,4,3,7,5,11,7,4,5,7,8,54,7,5,9,9,8,512,7,4,6,
+7,8,36,9,5,128,7,8,52,7,6,15,7,8,0,7,4,4,7,4,2,7,4,7,7,6,13,7,4,3,9,9,1728,7,4,5,
+7,8,44,7,6,17,9,9,1408,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,
+7,8,30,7,4,3,7,5,11,7,4,5,7,6,12,7,5,9,9,6,1664,7,4,6,7,8,34,9,5,128,7,8,50,7,6,14,
+7,8,62,7,4,4,7,4,2,7,4,7,7,8,48,7,4,3,7,8,60,7,4,5,7,8,42,7,6,16,9,9,1152,7,4,6,
+7,8,32,7,5,8,7,8,58,9,5,64,7,5,10,7,4,4,7,4,2,7,4,7,7,7,22,7,4,3,7,5,11,7,4,5,
+7,7,26,7,5,9,9,8,640,7,4,6,7,8,38,9,5,128,7,7,25,7,6,15,9,8,384,7,4,4,7,4,2,7,4,7,
+7,6,13,7,4,3,7,7,18,7,4,5,7,7,21,7,6,17,9,7,256,7,4,6,7,6,1,7,5,8,9,6,192,9,5,64,
+7,5,10,7,4,4,7,4,2,7,4,7
 };
  const TIFFFaxTabEnt TIFFFaxBlackTable[8192] = {
 };
  const TIFFFaxTabEnt TIFFFaxBlackTable[8192] = {
-       { 12,11,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1792 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,23 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,20 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,25 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,128 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,56 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,30 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,11,1856 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,57 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,21 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,54 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,52 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,48 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2112 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,44 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,36 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,384 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,28 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,60 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,40 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2368 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,1984 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,50 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,34 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1664 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,26 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,1408 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,32 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1920 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,61 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,42 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1024 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,768 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,62 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2240 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,46 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,38 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,512 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,19 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,24 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,22 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2496 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 12,11,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1792 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,23 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,20 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,25 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,12,192 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1280 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,31 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1856 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,58 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,21 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,896 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,640 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,49 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2176 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,45 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,37 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,448 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,29 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,1536 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,41 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2432 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2048 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,51 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,35 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,12,320 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,27 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,59 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,33 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,11,1920 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,256 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,43 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1152 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,55 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,63 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2304 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,47 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,39 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,53 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,19 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,24 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,22 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2560 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 12,11,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,11,1792 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,23 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,20 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,25 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,128 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,56 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,30 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1856 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,57 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,21 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,54 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,52 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,48 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2112 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,44 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,36 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,12,384 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,28 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,60 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,40 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2368 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,1984 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,50 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,34 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1728 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,26 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1472 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,32 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1920 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,61 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,42 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,1088 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,832 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,62 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2240 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,46 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,38 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,576 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,19 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,24 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,22 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2496 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 12,11,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1792 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,23 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,20 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,25 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,192 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1344 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,31 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,11,1856 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,58 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,11,21 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,960 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,13,704 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,49 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2176 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,45 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,37 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,448 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,29 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1600 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,41 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2432 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,18 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,17 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2048 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,51 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,35 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,12,320 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,27 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,59 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,33 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,11,1920 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 10,12,256 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,43 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,13,1216 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,9,15 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,55 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,63 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 11,12,2304 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,47 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,12,39 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,12,53 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 0,0,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,13 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,19 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,24 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,11,22 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 11,12,2560 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,10 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,10,16 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,10,0 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 10,10,64 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,6,9 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,11 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,8,14 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,6,8 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-       { 8,7,12 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,6 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
-
-       { 8,5,7 },
-       { 8,2,3 },
-       { 8,3,1 },
-       { 8,2,2 },
-       { 8,4,5 },
-       { 8,2,3 },
-       { 8,3,4 },
-       { 8,2,2 },
+12,11,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,11,1792,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,23,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,20,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,25,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,12,128,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,56,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,30,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,11,1856,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,57,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,21,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,54,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,52,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,48,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,2112,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,44,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,36,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,12,384,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,28,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,60,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,40,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2368,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,1984,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,50,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,34,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,1664,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,26,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,1408,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,32,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,11,1920,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,61,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,42,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,1024,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,768,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,62,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2240,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,46,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,38,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,512,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,19,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,24,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,22,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2496,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,12,11,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,18,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,17,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,11,1792,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,23,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,20,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,25,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,12,192,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,1280,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,31,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,11,1856,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,58,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,21,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,896,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,640,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,49,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2176,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,45,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,37,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,12,448,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,29,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,1536,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,41,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,2432,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,16,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,10,64,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2048,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,51,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,35,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,12,320,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,27,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,59,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,33,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,11,1920,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,12,256,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,43,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,1152,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,55,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,63,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,2304,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,47,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,39,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,53,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,19,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,24,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,22,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2560,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,12,11,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,11,1792,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,23,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,20,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,25,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,12,128,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,56,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,30,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,11,1856,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,57,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,21,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,54,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,52,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,48,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2112,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,44,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,36,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,12,384,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,28,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,60,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,40,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2368,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,18,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,17,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,1984,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,50,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,34,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,1728,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,26,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,1472,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,32,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,11,1920,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,61,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,42,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,1088,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,832,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,62,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2240,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,46,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,38,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,576,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,19,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,24,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,22,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,2496,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,16,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,10,64,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+12,11,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,11,1792,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,23,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,20,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,25,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,12,192,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,1344,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,31,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,11,1856,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,58,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,11,21,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,960,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,13,704,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,49,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,12,2176,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,45,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,37,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,12,448,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,29,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,13,1600,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,41,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2432,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,18,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,10,17,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2048,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,51,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,35,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,12,320,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,27,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,59,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,33,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,11,11,1920,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+10,12,256,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,43,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,10,13,1216,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,13,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,9,15,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,55,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,63,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,11,12,2304,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,12,47,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,12,39,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,12,53,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,8,14,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,0,0,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,13,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,19,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,11,24,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,7,11,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,11,22,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+11,12,2560,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,9,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,10,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,10,16,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,10,0,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,10,10,64,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,6,9,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,8,7,11,8,2,3,8,3,1,8,2,2,
+8,4,6,8,2,3,8,3,4,8,2,2,8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2,
+8,8,14,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,8,6,8,8,2,3,8,3,1,8,2,2,
+8,4,5,8,2,3,8,3,4,8,2,2,8,7,12,8,2,3,8,3,1,8,2,2,8,4,6,8,2,3,8,3,4,8,2,2,
+8,5,7,8,2,3,8,3,1,8,2,2,8,4,5,8,2,3,8,3,4,8,2,2
 };
 };
index 375bcbedb44849f0b3481cdadd8d1967362ee199..6746e1e2e26519b8f1cf61e9cf4f8ba43e9ea526 100644 (file)
@@ -45,6 +45,12 @@ TIFFFlush(TIFF* tif)
 
 /*
  * Flush buffered data to the file.
 
 /*
  * Flush buffered data to the file.
+ *
+ * Frank Warmerdam'2000: I modified this to return 1 if TIFF_BEENWRITING
+ * is not set, so that TIFFFlush() will proceed to write out the directory.
+ * The documentation says returning 1 is an error indicator, but not having
+ * been writing isn't exactly a an error.  Hopefully this doesn't cause
+ * problems for other people. 
  */
 int
 TIFFFlushData(TIFF* tif)
  */
 int
 TIFFFlushData(TIFF* tif)
@@ -58,3 +64,4 @@ TIFFFlushData(TIFF* tif)
        }
        return (TIFFFlushData1(tif));
 }
        }
        return (TIFFFlushData1(tif));
 }
+
index 810885e8511c9f09a7a17dba495f037a220e6007..b9a0903767bb110ff075fc3a2d84112a5f387935 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
 #include <assert.h>
 #include <stdio.h>
 
 #include <assert.h>
 #include <stdio.h>
 
-static int LINKAGEMODE gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
-static int LINKAGEMODE gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
-static int LINKAGEMODE gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32);
-static int LINKAGEMODE gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
-static int LINKAGEMODE pickTileContigCase(TIFFRGBAImage*);
-static int LINKAGEMODE pickTileSeparateCase(TIFFRGBAImage*);
+static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
+static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
+static int gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32);
+static int gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
+static int pickTileContigCase(TIFFRGBAImage*);
+static int pickTileSeparateCase(TIFFRGBAImage*);
 
 static const char photoTag[] = "PhotometricInterpretation";
 
 
 static const char photoTag[] = "PhotometricInterpretation";
 
+/* 
+ * Helper constants used in Orientation tag handling
+ */
+#define FLIP_VERTICALLY 0x01
+#define FLIP_HORIZONTALLY 0x02
+
+/*
+ * Color conversion constants. We will define display types here.
+ */
+
+TIFFDisplay display_sRGB = {
+       {                       /* XYZ -> luminance matrix */
+               {  3.2410F, -1.5374F, -0.4986F },
+               {  -0.9692F, 1.8760F, 0.0416F },
+               {  0.0556F, -0.2040F, 1.0570F }
+       },      
+       100.0F, 100.0F, 100.0F, /* Light o/p for reference white */
+       255, 255, 255,          /* Pixel values for ref. white */
+       1.0F, 1.0F, 1.0F,       /* Residual light o/p for black pixel */
+       2.4F, 2.4F, 2.4F,       /* Gamma values for the three guns */
+};
+
 /*
  * Check the image to see if TIFFReadRGBAImage can deal with it.
  * 1/0 is returned according to whether or not the image can
 /*
  * Check the image to see if TIFFReadRGBAImage can deal with it.
  * 1/0 is returned according to whether or not the image can
@@ -55,6 +77,10 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
     uint16 photometric;
     int colorchannels;
 
     uint16 photometric;
     int colorchannels;
 
+    if (!tif->tif_decodestatus) {
+       sprintf(emsg, "Sorry, requested compression method is not configured");
+       return (0);
+    }
     switch (td->td_bitspersample) {
     case 1: case 2: case 4:
     case 8: case 16:
     switch (td->td_bitspersample) {
     case 1: case 2: case 4:
     case 8: case 16:
@@ -82,13 +108,22 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
     case PHOTOMETRIC_MINISWHITE:
     case PHOTOMETRIC_MINISBLACK:
     case PHOTOMETRIC_PALETTE:
     case PHOTOMETRIC_MINISWHITE:
     case PHOTOMETRIC_MINISBLACK:
     case PHOTOMETRIC_PALETTE:
-       if (td->td_planarconfig == PLANARCONFIG_CONTIG && td->td_samplesperpixel != 1) {
+       if (td->td_planarconfig == PLANARCONFIG_CONTIG 
+            && td->td_samplesperpixel != 1
+            && td->td_bitspersample < 8 ) {
            sprintf(emsg,
            sprintf(emsg,
-               "Sorry, can not handle contiguous data with %s=%d, and %s=%d",
-               photoTag, photometric,
-               "Samples/pixel", td->td_samplesperpixel);
+                    "Sorry, can not handle contiguous data with %s=%d, "
+                    "and %s=%d and Bits/Sample=%d",
+                    photoTag, photometric,
+                    "Samples/pixel", td->td_samplesperpixel,
+                    td->td_bitspersample);
            return (0);
        }
            return (0);
        }
+        /*
+        ** We should likely validate that any extra samples are either
+        ** to be ignored, or are alpha, and if alpha we should try to use
+        ** them.  But for now we won't bother with this. 
+        */
        break;
     case PHOTOMETRIC_YCBCR:
        if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
        break;
     case PHOTOMETRIC_YCBCR:
        if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
@@ -97,27 +132,25 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
            return (0);
        }
        break;
            return (0);
        }
        break;
-    case PHOTOMETRIC_RGB:
+    case PHOTOMETRIC_RGB: 
        if (colorchannels < 3) {
            sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
                "Color channels", colorchannels);
            return (0);
        }
        break;
        if (colorchannels < 3) {
            sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
                "Color channels", colorchannels);
            return (0);
        }
        break;
-#ifdef CMYK_SUPPORT
     case PHOTOMETRIC_SEPARATED:
        if (td->td_inkset != INKSET_CMYK) {
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "InkSet", td->td_inkset);
            return (0);
        }
     case PHOTOMETRIC_SEPARATED:
        if (td->td_inkset != INKSET_CMYK) {
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "InkSet", td->td_inkset);
            return (0);
        }
-       if (td->td_samplesperpixel != 4) {
+       if (td->td_samplesperpixel < 4) {
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "Samples/pixel", td->td_samplesperpixel);
            return (0);
        }
        break;
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "Samples/pixel", td->td_samplesperpixel);
            return (0);
        }
        break;
-#endif
     case PHOTOMETRIC_LOGL:
        if (td->td_compression != COMPRESSION_SGILOG) {
            sprintf(emsg, "Sorry, LogL data must have %s=%d",
     case PHOTOMETRIC_LOGL:
        if (td->td_compression != COMPRESSION_SGILOG) {
            sprintf(emsg, "Sorry, LogL data must have %s=%d",
@@ -138,6 +171,8 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
            return (0);
        }
        break;
            return (0);
        }
        break;
+    case PHOTOMETRIC_CIELAB:
+       break;
     default:
        sprintf(emsg, "Sorry, can not handle image with %s=%d",
            photoTag, photometric);
     default:
        sprintf(emsg, "Sorry, can not handle image with %s=%d",
            photoTag, photometric);
@@ -149,20 +184,22 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
 void
 TIFFRGBAImageEnd(TIFFRGBAImage* img)
 {
 void
 TIFFRGBAImageEnd(TIFFRGBAImage* img)
 {
-    if (img->Map)
-       _TIFFfree(img->Map), img->Map = NULL;
-    if (img->BWmap)
-       _TIFFfree(img->BWmap), img->BWmap = NULL;
-    if (img->PALmap)
-       _TIFFfree(img->PALmap), img->PALmap = NULL;
-    if (img->ycbcr)
-       _TIFFfree(img->ycbcr), img->ycbcr = NULL;
-
-    if( img->redcmap ) {
-        _TIFFfree( img->redcmap );
-        _TIFFfree( img->greencmap );
-        _TIFFfree( img->bluecmap );
-    }
+       if (img->Map)
+               _TIFFfree(img->Map), img->Map = NULL;
+       if (img->BWmap)
+               _TIFFfree(img->BWmap), img->BWmap = NULL;
+       if (img->PALmap)
+               _TIFFfree(img->PALmap), img->PALmap = NULL;
+       if (img->ycbcr)
+               _TIFFfree(img->ycbcr), img->ycbcr = NULL;
+       if (img->cielab)
+               _TIFFfree(img->cielab), img->cielab = NULL;
+
+       if( img->redcmap ) {
+               _TIFFfree( img->redcmap );
+               _TIFFfree( img->greencmap );
+               _TIFFfree( img->bluecmap );
+       }
 }
 
 static int
 }
 
 static int
@@ -193,7 +230,8 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
     img->redcmap = NULL;
     img->greencmap = NULL;
     img->bluecmap = NULL;
     img->redcmap = NULL;
     img->greencmap = NULL;
     img->bluecmap = NULL;
-
+    img->req_orientation = ORIENTATION_BOTLEFT;            /* It is the default */
+    
     img->tif = tif;
     img->stoponerr = stop;
     TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
     img->tif = tif;
     img->stoponerr = stop;
     TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
@@ -202,7 +240,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
     case 8: case 16:
        break;
     default:
     case 8: case 16:
        break;
     default:
-       sprintf(emsg, "Sorry, can not image with %d-bit samples",
+       sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
            img->bitspersample);
        return (0);
     }
            img->bitspersample);
        return (0);
     }
@@ -211,12 +249,32 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
     TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
        &extrasamples, &sampleinfo);
     if (extrasamples == 1)
     TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
        &extrasamples, &sampleinfo);
     if (extrasamples == 1)
+    {
        switch (sampleinfo[0]) {
        switch (sampleinfo[0]) {
+       case EXTRASAMPLE_UNSPECIFIED:   /* Workaround for some images without */
+               if (img->samplesperpixel == 4)  /* correct info about alpha channel */
+                       img->alpha = EXTRASAMPLE_ASSOCALPHA;
+               break;
        case EXTRASAMPLE_ASSOCALPHA:    /* data is pre-multiplied */
        case EXTRASAMPLE_UNASSALPHA:    /* data is not pre-multiplied */
        case EXTRASAMPLE_ASSOCALPHA:    /* data is pre-multiplied */
        case EXTRASAMPLE_UNASSALPHA:    /* data is not pre-multiplied */
-           img->alpha = sampleinfo[0];
-           break;
+               img->alpha = sampleinfo[0];
+               break;
        }
        }
+    }
+
+#if DEFAULT_EXTRASAMPLE_AS_ALPHA == 1
+    if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
+        img->photometric = PHOTOMETRIC_MINISWHITE;
+
+    if( extrasamples == 0 
+        && img->samplesperpixel == 4 
+        && img->photometric == PHOTOMETRIC_RGB )
+    {
+        img->alpha = EXTRASAMPLE_ASSOCALPHA;
+        extrasamples = 1;
+    }
+#endif
+
     colorchannels = img->samplesperpixel - extrasamples;
     TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress);
     TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
     colorchannels = img->samplesperpixel - extrasamples;
     TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress);
     TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
@@ -257,15 +315,19 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
         memcpy( img->redcmap, red_orig, n_color * 2 );
         memcpy( img->greencmap, green_orig, n_color * 2 );
         memcpy( img->bluecmap, blue_orig, n_color * 2 );
         memcpy( img->redcmap, red_orig, n_color * 2 );
         memcpy( img->greencmap, green_orig, n_color * 2 );
         memcpy( img->bluecmap, blue_orig, n_color * 2 );
-
+        
        /* fall thru... */
     case PHOTOMETRIC_MINISWHITE:
     case PHOTOMETRIC_MINISBLACK:
        /* fall thru... */
     case PHOTOMETRIC_MINISWHITE:
     case PHOTOMETRIC_MINISBLACK:
-       if (planarconfig == PLANARCONFIG_CONTIG && img->samplesperpixel != 1) {
+       if (planarconfig == PLANARCONFIG_CONTIG 
+            && img->samplesperpixel != 1
+            && img->bitspersample < 8 ) {
            sprintf(emsg,
            sprintf(emsg,
-               "Sorry, can not handle contiguous data with %s=%d, and %s=%d",
-               photoTag, img->photometric,
-               "Samples/pixel", img->samplesperpixel);
+                    "Sorry, can not handle contiguous data with %s=%d, "
+                    "and %s=%d and Bits/Sample=%d",
+                    photoTag, img->photometric,
+                    "Samples/pixel", img->samplesperpixel,
+                    img->bitspersample);
            return (0);
        }
        break;
            return (0);
        }
        break;
@@ -276,14 +338,22 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
            return (0);
        }
        /* It would probably be nice to have a reality check here. */
            return (0);
        }
        /* It would probably be nice to have a reality check here. */
-       if (compress == COMPRESSION_JPEG && planarconfig == PLANARCONFIG_CONTIG) {
+       if (planarconfig == PLANARCONFIG_CONTIG)
            /* can rely on libjpeg to convert to RGB */
            /* XXX should restore current state on exit */
            /* can rely on libjpeg to convert to RGB */
            /* XXX should restore current state on exit */
-           TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
-           img->photometric = PHOTOMETRIC_RGB;
-       }
+           switch (compress) {
+               case COMPRESSION_OJPEG:
+               case COMPRESSION_JPEG:
+                   TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
+                   img->photometric = PHOTOMETRIC_RGB;
+                    break;
+
+                default:
+                    /* do nothing */;
+                    break;
+           }
        break;
        break;
-    case PHOTOMETRIC_RGB:
+    case PHOTOMETRIC_RGB: 
        if (colorchannels < 3) {
            sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
                "Color channels", colorchannels);
        if (colorchannels < 3) {
            sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
                "Color channels", colorchannels);
@@ -298,7 +368,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
                "InkSet", inkset);
            return (0);
        }
                "InkSet", inkset);
            return (0);
        }
-       if (img->samplesperpixel != 4) {
+       if (img->samplesperpixel < 4) {
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "Samples/pixel", img->samplesperpixel);
            return (0);
            sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
                "Samples/pixel", img->samplesperpixel);
            return (0);
@@ -330,6 +400,8 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
        img->photometric = PHOTOMETRIC_RGB;             /* little white lie */
        img->bitspersample = 8;
        break;
        img->photometric = PHOTOMETRIC_RGB;             /* little white lie */
        img->bitspersample = 8;
        break;
+    case PHOTOMETRIC_CIELAB:
+       break;
     default:
        sprintf(emsg, "Sorry, can not handle image with %s=%d",
            photoTag, img->photometric);
     default:
        sprintf(emsg, "Sorry, can not handle image with %s=%d",
            photoTag, img->photometric);
@@ -339,6 +411,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
     img->BWmap = NULL;
     img->PALmap = NULL;
     img->ycbcr = NULL;
     img->BWmap = NULL;
     img->PALmap = NULL;
     img->ycbcr = NULL;
+    img->cielab = NULL;
     TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
     TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
     TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
     TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
     TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
     TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
@@ -346,12 +419,11 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
        !(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
     if (img->isContig) {
        img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
        !(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
     if (img->isContig) {
        img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
-       (void) pickTileContigCase(img);
+       return pickTileContigCase(img);
     } else {
        img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
     } else {
        img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
-       (void) pickTileSeparateCase(img);
+       return pickTileSeparateCase(img);
     }
     }
-    return (1);
 }
 
 int
 }
 
 int
@@ -370,17 +442,21 @@ TIFFRGBAImageGet(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 }
 
 /*
 }
 
 /*
- * Read the specified image into an ABGR-format raster.
+ * Read the specified image into an ABGR-format rastertaking in account
+ * specified orientation.
  */
 int
  */
 int
-TIFFReadRGBAImage(TIFF* tif,
-    uint32 rwidth, uint32 rheight, uint32* raster, int stop)
+TIFFReadRGBAImageOriented(TIFF* tif,
+                         uint32 rwidth, uint32 rheight, uint32* raster,
+                         int orientation, int stop)
 {
     char emsg[1024];
     TIFFRGBAImage img;
     int ok;
 
 {
     char emsg[1024];
     TIFFRGBAImage img;
     int ok;
 
-    if (TIFFRGBAImageBegin(&img, tif, stop, emsg)) {
+    if (TIFFRGBAImageOK(tif, emsg) &&
+       TIFFRGBAImageBegin(&img, tif, stop, emsg)) {
+       img.req_orientation = orientation;
        /* XXX verify rwidth and rheight against width and height */
        ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth,
            rwidth, img.height);
        /* XXX verify rwidth and rheight against width and height */
        ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth,
            rwidth, img.height);
@@ -392,34 +468,77 @@ TIFFReadRGBAImage(TIFF* tif,
     return (ok);
 }
 
     return (ok);
 }
 
-static uint32
-setorientation(TIFFRGBAImage* img, uint32 h)
+/*
+ * Read the specified image into an ABGR-format raster. Use bottom left
+ * origin for raster by default.
+ */
+int
+TIFFReadRGBAImage(TIFF* tif,
+                 uint32 rwidth, uint32 rheight, uint32* raster, int stop)
 {
 {
-    TIFF* tif = img->tif;
-    uint32 y;
-
-    switch (img->orientation) {
-    case ORIENTATION_BOTRIGHT:
-    case ORIENTATION_RIGHTBOT: /* XXX */
-    case ORIENTATION_LEFTBOT:  /* XXX */
-       TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
-       img->orientation = ORIENTATION_BOTLEFT;
-       /* fall thru... */
-    case ORIENTATION_BOTLEFT:
-       y = 0;
-       break;
-    case ORIENTATION_TOPRIGHT:
-    case ORIENTATION_RIGHTTOP: /* XXX */
-    case ORIENTATION_LEFTTOP:  /* XXX */
-    default:
-       TIFFWarning(TIFFFileName(tif), "using top-left orientation");
-       img->orientation = ORIENTATION_TOPLEFT;
-       /* fall thru... */
-    case ORIENTATION_TOPLEFT:
-       y = h-1;
-       break;
-    }
-    return (y);
+       return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster,
+                                        ORIENTATION_BOTLEFT, stop);
+}
+
+static int 
+setorientation(TIFFRGBAImage* img)
+{
+       switch (img->orientation) {
+               case ORIENTATION_TOPLEFT:
+               case ORIENTATION_LEFTTOP:
+                       if (img->req_orientation == ORIENTATION_TOPRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTTOP)
+                               return FLIP_HORIZONTALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTBOT)
+                               return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTBOT)
+                               return FLIP_VERTICALLY;
+                       else
+                               return 0;
+               case ORIENTATION_TOPRIGHT:
+               case ORIENTATION_RIGHTTOP:
+                       if (img->req_orientation == ORIENTATION_TOPLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTTOP)
+                               return FLIP_HORIZONTALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTBOT)
+                               return FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTBOT)
+                               return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
+                       else
+                               return 0;
+               case ORIENTATION_BOTRIGHT:
+               case ORIENTATION_RIGHTBOT:
+                       if (img->req_orientation == ORIENTATION_TOPLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTTOP)
+                               return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTTOP)
+                               return FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTBOT)
+                               return FLIP_HORIZONTALLY;
+                       else
+                               return 0;
+               case ORIENTATION_BOTLEFT:
+               case ORIENTATION_LEFTBOT:
+                       if (img->req_orientation == ORIENTATION_TOPLEFT ||
+                           img->req_orientation == ORIENTATION_LEFTTOP)
+                               return FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTTOP)
+                               return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
+                       else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
+                           img->req_orientation == ORIENTATION_RIGHTBOT)
+                               return FLIP_HORIZONTALLY;
+                       else
+                               return 0;
+               default:        /* NOTREACHED */
+                       return 0;
+       }
 }
 
 /*
 }
 
 /*
@@ -433,47 +552,86 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 {
     TIFF* tif = img->tif;
     tileContigRoutine put = img->put.contig;
 {
     TIFF* tif = img->tif;
     tileContigRoutine put = img->put.contig;
-    uint16 orientation;
-    uint32 col, row, y;
+    uint32 col, row, y, rowstoread;
+    uint32 pos;
     uint32 tw, th;
     u_char* buf;
     int32 fromskew, toskew;
     uint32 nrow;
     uint32 tw, th;
     u_char* buf;
     int32 fromskew, toskew;
     uint32 nrow;
+    int ret = 1, flip;
 
     buf = (u_char*) _TIFFmalloc(TIFFTileSize(tif));
     if (buf == 0) {
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
 
     buf = (u_char*) _TIFFmalloc(TIFFTileSize(tif));
     if (buf == 0) {
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
+    _TIFFmemset(buf, 0, TIFFTileSize(tif));
     TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
     TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
     TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
     TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
-    y = setorientation(img, h);
-    orientation = img->orientation;
-    toskew = -(int32) (orientation == ORIENTATION_TOPLEFT ? tw+w : tw-w);
-    for (row = 0; row < h; row += th) {
-       nrow = (row + th > h ? h - row : th);
-       for (col = 0; col < w; col += tw) {
-           if (TIFFReadTile(tif, buf, col+img->col_offset,
+
+    flip = setorientation(img);
+    if (flip & FLIP_VERTICALLY) {
+           y = h - 1;
+           toskew = -(int32)(tw + w);
+    }
+    else {
+           y = 0;
+           toskew = -(int32)(tw - w);
+    }
+     
+    for (row = 0; row < h; row += nrow)
+    {
+        rowstoread = th - (row + img->row_offset) % th;
+       nrow = (row + rowstoread > h ? h - row : rowstoread);
+       for (col = 0; col < w; col += tw) 
+        {
+            if (TIFFReadTile(tif, buf, col+img->col_offset,
                              row+img->row_offset, 0, 0) < 0 && img->stoponerr)
                              row+img->row_offset, 0, 0) < 0 && img->stoponerr)
-               break;
-           if (col + tw > w) {
-               /*
-                * Tile is clipped horizontally.  Calculate
-                * visible portion and skewing factors.
-                */
-               uint32 npix = w - col;
-               fromskew = tw - npix;
-               (*put)(img, raster+y*w+col, col, y,
-                   npix, nrow, fromskew, toskew + fromskew, buf);
-           } else {
-               (*put)(img, raster+y*w+col, col, y, tw, nrow, 0, toskew, buf);
-           }
-       }
-       y += (orientation == ORIENTATION_TOPLEFT ?
-           -(int32) nrow : (int32) nrow);
+            {
+                ret = 0;
+                break;
+            }
+           
+            pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif);
+
+           if (col + tw > w) 
+            {
+                /*
+                 * Tile is clipped horizontally.  Calculate
+                 * visible portion and skewing factors.
+                 */
+                uint32 npix = w - col;
+                fromskew = tw - npix;
+                (*put)(img, raster+y*w+col, col, y,
+                       npix, nrow, fromskew, toskew + fromskew, buf + pos);
+            }
+            else 
+            {
+                (*put)(img, raster+y*w+col, col, y, tw, nrow, 0, toskew, buf + pos);
+            }
+        }
+
+        y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow);
     }
     _TIFFfree(buf);
     }
     _TIFFfree(buf);
-    return (1);
+
+    if (flip & FLIP_HORIZONTALLY) {
+           uint32 line;
+
+           for (line = 0; line < h; line++) {
+                   uint32 *left = raster + (line * w);
+                   uint32 *right = left + w - 1;
+                   
+                   while ( left < right ) {
+                           uint32 temp = *left;
+                           *left = *right;
+                           *right = temp;
+                           left++, right--;
+                   }
+           }
+    }
+
+    return (ret);
 }
 
 /*
 }
 
 /*
@@ -487,8 +645,8 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 {
     TIFF* tif = img->tif;
     tileSeparateRoutine put = img->put.separate;
 {
     TIFF* tif = img->tif;
     tileSeparateRoutine put = img->put.separate;
-    uint16 orientation;
-    uint32 col, row, y;
+    uint32 col, row, y, rowstoread;
+    uint32 pos;
     uint32 tw, th;
     u_char* buf;
     u_char* r;
     uint32 tw, th;
     u_char* buf;
     u_char* r;
@@ -499,6 +657,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
     int32 fromskew, toskew;
     int alpha = img->alpha;
     uint32 nrow;
     int32 fromskew, toskew;
     int alpha = img->alpha;
     uint32 nrow;
+    int ret = 1, flip;
 
     tilesize = TIFFTileSize(tif);
     buf = (u_char*) _TIFFmalloc(4*tilesize);
 
     tilesize = TIFFTileSize(tif);
     buf = (u_char*) _TIFFmalloc(4*tilesize);
@@ -506,6 +665,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
+    _TIFFmemset(buf, 0, 4*tilesize);
     r = buf;
     g = r + tilesize;
     b = g + tilesize;
     r = buf;
     g = r + tilesize;
     b = g + tilesize;
@@ -514,43 +674,88 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
        memset(a, 0xff, tilesize);
     TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
     TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
        memset(a, 0xff, tilesize);
     TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);
     TIFFGetField(tif, TIFFTAG_TILELENGTH, &th);
-    y = setorientation(img, h);
-    orientation = img->orientation;
-    toskew = -(int32) (orientation == ORIENTATION_TOPLEFT ? tw+w : tw-w);
-    for (row = 0; row < h; row += th) {
-       nrow = (row + th > h ? h - row : th);
-       for (col = 0; col < w; col += tw) {
-           if (TIFFReadTile(tif, r, col+img->col_offset,
+
+    flip = setorientation(img);
+    if (flip & FLIP_VERTICALLY) {
+           y = h - 1;
+           toskew = -(int32)(tw + w);
+    }
+    else {
+           y = 0;
+           toskew = -(int32)(tw - w);
+    }
+
+    for (row = 0; row < h; row += nrow) 
+    {
+        rowstoread = th - (row + img->row_offset) % th;
+       nrow = (row + rowstoread > h ? h - row : rowstoread);
+        for (col = 0; col < w; col += tw) 
+        {
+            if (TIFFReadTile(tif, r, col+img->col_offset,
                              row+img->row_offset,0,0) < 0 && img->stoponerr)
                              row+img->row_offset,0,0) < 0 && img->stoponerr)
-               break;
-           if (TIFFReadTile(tif, g, col+img->col_offset,
+            {
+                ret = 0;
+                break;
+            }
+            if (TIFFReadTile(tif, g, col+img->col_offset,
                              row+img->row_offset,0,1) < 0 && img->stoponerr)
                              row+img->row_offset,0,1) < 0 && img->stoponerr)
-               break;
-           if (TIFFReadTile(tif, b, col+img->col_offset,
+            {
+                ret = 0;
+                break;
+            }
+            if (TIFFReadTile(tif, b, col+img->col_offset,
                              row+img->row_offset,0,2) < 0 && img->stoponerr)
                              row+img->row_offset,0,2) < 0 && img->stoponerr)
-               break;
-           if (alpha && TIFFReadTile(tif,a,col+img->col_offset,
-                               row+img->row_offset,0,3) < 0 && img->stoponerr)
-               break;
-           if (col + tw > w) {
-               /*
-                * Tile is clipped horizontally.  Calculate
-                * visible portion and skewing factors.
-                */
-               uint32 npix = w - col;
-               fromskew = tw - npix;
-               (*put)(img, raster+y*w+col, col, y,
-                   npix, nrow, fromskew, toskew + fromskew, r, g, b, a);
-           } else {
-               (*put)(img, raster+y*w+col, col, y,
-                   tw, nrow, 0, toskew, r, g, b, a);
+            {
+                ret = 0;
+                break;
+            }
+            if (alpha && TIFFReadTile(tif,a,col+img->col_offset,
+                                      row+img->row_offset,0,3) < 0 && img->stoponerr)
+            {
+                ret = 0;
+                break;
+            }
+
+            pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif);
+
+            if (col + tw > w) 
+            {
+                /*
+                 * Tile is clipped horizontally.  Calculate
+                 * visible portion and skewing factors.
+                 */
+                uint32 npix = w - col;
+                fromskew = tw - npix;
+                (*put)(img, raster+y*w+col, col, y,
+                       npix, nrow, fromskew, toskew + fromskew, 
+                       r + pos, g + pos, b + pos, a + pos);
+            } else {
+                (*put)(img, raster+y*w+col, col, y,
+                       tw, nrow, 0, toskew, r + pos, g + pos, b + pos, a + pos);
+            }
+        }
+
+        y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow);
+    }
+
+    if (flip & FLIP_HORIZONTALLY) {
+           uint32 line;
+
+           for (line = 0; line < h; line++) {
+                   uint32 *left = raster + (line * w);
+                   uint32 *right = left + w - 1;
+                   
+                   while ( left < right ) {
+                           uint32 temp = *left;
+                           *left = *right;
+                           *right = temp;
+                           left++, right--;
+                   }
            }
            }
-       }
-       y += (orientation == ORIENTATION_TOPLEFT ?
-           -(int32) nrow : (int32) nrow);
     }
     }
+
     _TIFFfree(buf);
     _TIFFfree(buf);
-    return (1);
+    return (ret);
 }
 
 /*
 }
 
 /*
@@ -564,38 +769,71 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 {
     TIFF* tif = img->tif;
     tileContigRoutine put = img->put.contig;
 {
     TIFF* tif = img->tif;
     tileContigRoutine put = img->put.contig;
-    uint16 orientation;
-    uint32 row, y, nrow;
+    uint32 row, y, nrow, rowstoread;
+    uint32 pos;
     u_char* buf;
     uint32 rowsperstrip;
     uint32 imagewidth = img->width;
     tsize_t scanline;
     int32 fromskew, toskew;
     u_char* buf;
     uint32 rowsperstrip;
     uint32 imagewidth = img->width;
     tsize_t scanline;
     int32 fromskew, toskew;
+    int ret = 1, flip;
 
     buf = (u_char*) _TIFFmalloc(TIFFStripSize(tif));
     if (buf == 0) {
        TIFFError(TIFFFileName(tif), "No space for strip buffer");
        return (0);
     }
 
     buf = (u_char*) _TIFFmalloc(TIFFStripSize(tif));
     if (buf == 0) {
        TIFFError(TIFFFileName(tif), "No space for strip buffer");
        return (0);
     }
-    y = setorientation(img, h);
-    orientation = img->orientation;
-    toskew = -(int32) (orientation == ORIENTATION_TOPLEFT ? w+w : w-w);
+    _TIFFmemset(buf, 0, TIFFStripSize(tif));
+
+    flip = setorientation(img);
+    if (flip & FLIP_VERTICALLY) {
+           y = h - 1;
+           toskew = -(int32)(w + w);
+    } else {
+           y = 0;
+           toskew = -(int32)(w - w);
+    }
+
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     scanline = TIFFScanlineSize(tif);
     fromskew = (w < imagewidth ? imagewidth - w : 0);
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     scanline = TIFFScanlineSize(tif);
     fromskew = (w < imagewidth ? imagewidth - w : 0);
-    for (row = 0; row < h; row += rowsperstrip) {
-       nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
-       if (TIFFReadEncodedStrip(tif,
+    for (row = 0; row < h; row += nrow) 
+    {
+        rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
+        nrow = (row + rowstoread > h ? h - row : rowstoread);
+        if (TIFFReadEncodedStrip(tif,
                                  TIFFComputeStrip(tif,row+img->row_offset, 0),
                                  TIFFComputeStrip(tif,row+img->row_offset, 0),
-                                 buf, nrow*scanline) < 0
+                                 buf, 
+                                 ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0
             && img->stoponerr)
             && img->stoponerr)
-               break;
-       (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf);
-       y += (orientation == ORIENTATION_TOPLEFT ?
-           -(int32) nrow : (int32) nrow);
+        {
+            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);
     }
     }
+
+    if (flip & FLIP_HORIZONTALLY) {
+           uint32 line;
+
+           for (line = 0; line < h; line++) {
+                   uint32 *left = raster + (line * w);
+                   uint32 *right = left + w - 1;
+                   
+                   while ( left < right ) {
+                           uint32 temp = *left;
+                           *left = *right;
+                           *right = temp;
+                           left++, right--;
+                   }
+           }
+    }
+
     _TIFFfree(buf);
     _TIFFfree(buf);
-    return (1);
+    return (ret);
 }
 
 /*
 }
 
 /*
@@ -609,16 +847,17 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 {
     TIFF* tif = img->tif;
     tileSeparateRoutine put = img->put.separate;
 {
     TIFF* tif = img->tif;
     tileSeparateRoutine put = img->put.separate;
-    uint16 orientation;
     u_char *buf;
     u_char *r, *g, *b, *a;
     u_char *buf;
     u_char *r, *g, *b, *a;
-    uint32 row, y, nrow;
+    uint32 row, y, nrow, rowstoread;
+    uint32 pos;
     tsize_t scanline;
     uint32 rowsperstrip, offset_row;
     uint32 imagewidth = img->width;
     tsize_t stripsize;
     int32 fromskew, toskew;
     int alpha = img->alpha;
     tsize_t scanline;
     uint32 rowsperstrip, offset_row;
     uint32 imagewidth = img->width;
     tsize_t stripsize;
     int32 fromskew, toskew;
     int alpha = img->alpha;
+    int        ret = 1, flip;
 
     stripsize = TIFFStripSize(tif);
     r = buf = (u_char *)_TIFFmalloc(4*stripsize);
 
     stripsize = TIFFStripSize(tif);
     r = buf = (u_char *)_TIFFmalloc(4*stripsize);
@@ -626,39 +865,85 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
        TIFFError(TIFFFileName(tif), "No space for tile buffer");
        return (0);
     }
+    _TIFFmemset(buf, 0, 4*stripsize);
     g = r + stripsize;
     b = g + stripsize;
     a = b + stripsize;
     if (!alpha)
        memset(a, 0xff, stripsize);
     g = r + stripsize;
     b = g + stripsize;
     a = b + stripsize;
     if (!alpha)
        memset(a, 0xff, stripsize);
-    y = setorientation(img, h);
-    orientation = img->orientation;
-    toskew = -(int32) (orientation == ORIENTATION_TOPLEFT ? w+w : w-w);
+
+    flip = setorientation(img);
+    if (flip & FLIP_VERTICALLY) {
+           y = h - 1;
+           toskew = -(int32)(w + w);
+    }
+    else {
+           y = 0;
+           toskew = -(int32)(w - w);
+    }
+
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     scanline = TIFFScanlineSize(tif);
     fromskew = (w < imagewidth ? imagewidth - w : 0);
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     scanline = TIFFScanlineSize(tif);
     fromskew = (w < imagewidth ? imagewidth - w : 0);
-    for (row = 0; row < h; row += rowsperstrip) {
-       nrow = (row + rowsperstrip > h ? h - row : rowsperstrip);
+    for (row = 0; row < h; row += nrow) 
+    {
+        rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;            
+        nrow = (row + rowstoread > h ? h - row : rowstoread);
         offset_row = row + img->row_offset;
         offset_row = row + img->row_offset;
-       if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
-           r, nrow*scanline) < 0 && img->stoponerr)
-           break;
-       if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1),
-           g, nrow*scanline) < 0 && img->stoponerr)
-           break;
-       if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2),
-           b, nrow*scanline) < 0 && img->stoponerr)
-           break;
-       if (alpha &&
-           (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 3),
-           a, nrow*scanline) < 0 && img->stoponerr))
-           break;
-       (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, r, g, b, a);
-       y += (orientation == ORIENTATION_TOPLEFT ?
-           -(int32) nrow : (int32) nrow);
+       if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
+                                 r, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+            && img->stoponerr)
+        {
+            ret = 0;
+            break;
+        }
+        if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1),
+                                 g, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+            && img->stoponerr)
+        {
+            ret = 0;
+            break;
+        }
+        if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2),
+                                 b, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+            && img->stoponerr)
+        {
+            ret = 0;
+            break;
+        }
+        if (alpha &&
+            (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 3),
+                                  a, ((row + img->row_offset)%rowsperstrip + nrow) * 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, r + pos, g + pos, 
+               b + pos, a + pos);
+        y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow);
+    }
+
+    if (flip & FLIP_HORIZONTALLY) {
+           uint32 line;
+
+           for (line = 0; line < h; line++) {
+                   uint32 *left = raster + (line * w);
+                   uint32 *right = left + w - 1;
+                   
+                   while ( left < right ) {
+                           uint32 temp = *left;
+                           *left = *right;
+                           *right = temp;
+                           left++, right--;
+                   }
+           }
     }
     }
+
     _TIFFfree(buf);
     _TIFFfree(buf);
-    return (1);
+    return (ret);
 }
 
 /*
 }
 
 /*
@@ -716,7 +1001,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
        op2;                            \
     }                                  \
 }
        op2;                            \
     }                                  \
 }
-
+    
 #define        SKEW(r,g,b,skew)        { r += skew; g += skew; b += skew; }
 #define        SKEW4(r,g,b,a,skew)     { r += skew; g += skew; b += skew; a+= skew; }
 
 #define        SKEW(r,g,b,skew)        { r += skew; g += skew; b += skew; }
 #define        SKEW4(r,g,b,a,skew)     { r += skew; g += skew; b += skew; a+= skew; }
 
@@ -732,7 +1017,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
        ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|((uint32)W2B(a)<<24))
 
 #define        DECLAREContigPutFunc(name) \
        ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|((uint32)W2B(a)<<24))
 
 #define        DECLAREContigPutFunc(name) \
-static void LINKAGEMODE name(\
+static void name(\
     TIFFRGBAImage* img, \
     uint32* cp, \
     uint32 x, uint32 y, \
     TIFFRGBAImage* img, \
     uint32* cp, \
     uint32 x, uint32 y, \
@@ -747,10 +1032,15 @@ static void LINKAGEMODE name(\
 DECLAREContigPutFunc(put8bitcmaptile)
 {
     uint32** PALmap = img->PALmap;
 DECLAREContigPutFunc(put8bitcmaptile)
 {
     uint32** PALmap = img->PALmap;
+    int samplesperpixel = img->samplesperpixel;
 
 
-    (void) x; (void) y;
+    (void) y;
     while (h-- > 0) {
     while (h-- > 0) {
-       UNROLL8(w, NOP, *cp++ = PALmap[*pp++][0]);
+       for (x = w; x-- > 0;)
+        {
+           *cp++ = PALmap[*pp][0];
+            pp += samplesperpixel;
+        }
        cp += toskew;
        pp += fromskew;
     }
        cp += toskew;
        pp += fromskew;
     }
@@ -812,12 +1102,41 @@ DECLAREContigPutFunc(put1bitcmaptile)
  */
 DECLAREContigPutFunc(putgreytile)
 {
  */
 DECLAREContigPutFunc(putgreytile)
 {
+    int samplesperpixel = img->samplesperpixel;
     uint32** BWmap = img->BWmap;
 
     (void) y;
     while (h-- > 0) {
        for (x = w; x-- > 0;)
     uint32** BWmap = img->BWmap;
 
     (void) y;
     while (h-- > 0) {
        for (x = w; x-- > 0;)
-           *cp++ = BWmap[*pp++][0];
+        {
+           *cp++ = BWmap[*pp][0];
+            pp += samplesperpixel;
+        }
+       cp += toskew;
+       pp += fromskew;
+    }
+}
+
+/*
+ * 16-bit greyscale => colormap/RGB
+ */
+DECLAREContigPutFunc(put16bitbwtile)
+{
+    int samplesperpixel = img->samplesperpixel;
+    uint32** BWmap = img->BWmap;
+
+    (void) y;
+    while (h-- > 0) {
+        uint16 *wp = (uint16 *) pp;
+
+       for (x = w; x-- > 0;)
+        {
+            /* use high order byte of 16bit value */
+
+           *cp++ = BWmap[*wp >> 8][0];
+            pp += 2 * samplesperpixel;
+            wp += samplesperpixel;
+        }
        cp += toskew;
        pp += fromskew;
     }
        cp += toskew;
        pp += fromskew;
     }
@@ -1019,7 +1338,7 @@ DECLAREContigPutFunc(putRGBUAcontig16bittile)
         * we divide by (0xffff * 0xfff) / 0xff == 0x10eff.
         */
        for (x = w; x-- > 0;) {
         * we divide by (0xffff * 0xfff) / 0xff == 0x10eff.
         */
        for (x = w; x-- > 0;) {
-           a = wp[3] >> 4;
+           a = wp[3] >> 4; 
            r = (wp[0] * a) / 0x10eff;
            g = (wp[1] * a) / 0x10eff;
            b = (wp[2] * a) / 0x10eff;
            r = (wp[0] * a) / 0x10eff;
            g = (wp[1] * a) / 0x10eff;
            b = (wp[2] * a) / 0x10eff;
@@ -1084,7 +1403,7 @@ DECLAREContigPutFunc(putRGBcontig8bitCMYKMaptile)
 }
 
 #define        DECLARESepPutFunc(name) \
 }
 
 #define        DECLARESepPutFunc(name) \
-static void LINKAGEMODE name(\
+static void name(\
     TIFFRGBAImage* img,\
     uint32* cp,\
     uint32 x, uint32 y, \
     TIFFRGBAImage* img,\
     uint32* cp,\
     uint32 x, uint32 y, \
@@ -1214,7 +1533,7 @@ DECLARESepPutFunc(putRGBUAseparate16bittile)
         * we divide by (0xffff * 0xfff) / 0xff == 0x10eff.
         */
        for (x = w; x-- > 0;) {
         * we divide by (0xffff * 0xfff) / 0xff == 0x10eff.
         */
        for (x = w; x-- > 0;) {
-           a = *wa++ >> 4;
+           a = *wa++ >> 4; 
            r = (*wr++ * a) / 0x10eff;
            g = (*wg++ * a) / 0x10eff;
            b = (*wb++ * a) / 0x10eff;
            r = (*wr++ * a) / 0x10eff;
            g = (*wg++ * a) / 0x10eff;
            b = (*wb++ * a) / 0x10eff;
@@ -1226,44 +1545,89 @@ DECLARESepPutFunc(putRGBUAseparate16bittile)
 }
 
 /*
 }
 
 /*
- * YCbCr -> RGB conversion and packing routines.  The colorspace
- * conversion algorithm comes from the IJG v5a code; see below
- * for more information on how it works.
+ * 8-bit packed CIE L*a*b 1976 samples => RGB
+ */
+DECLAREContigPutFunc(putcontig8bitCIELab)
+{
+       float X, Y, Z;
+       uint32 r, g, b;
+       (void) y;
+       fromskew *= 3;
+       while (h-- > 0) {
+               for (x = w; x-- > 0;) {
+                       TIFFCIELabToXYZ(img->cielab,
+                                       (u_char)pp[0],
+                                       (signed char)pp[1],
+                                       (signed char)pp[2],
+                                       &X, &Y, &Z);
+                       TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
+                       *cp++ = PACK(r, g, b);
+                       pp += 3;
+               }
+               cp += toskew;
+               pp += fromskew;
+       }
+}
+
+/*
+ * YCbCr -> RGB conversion and packing routines.
  */
 
  */
 
-#define        YCbCrtoRGB(dst, yc) {                                           \
-    int Y = (yc);                                                      \
-    dst = PACK(                                                                \
-       clamptab[Y+Crrtab[Cr]],                                         \
-       clamptab[Y + (int)((Cbgtab[Cb]+Crgtab[Cr])>>16)],               \
-       clamptab[Y+Cbbtab[Cb]]);                                        \
+#define        YCbCrtoRGB(dst, Y) {                                            \
+       uint32 r, g, b;                                                 \
+       TIFFYCbCrtoRGB(img->ycbcr, (Y), Cb, Cr, &r, &g, &b);            \
+       dst = PACK(r, g, b);                                            \
 }
 }
-#define        YCbCrSetup                                                      \
-    TIFFYCbCrToRGB* ycbcr = img->ycbcr;                                        \
-    int* Crrtab = ycbcr->Cr_r_tab;                                     \
-    int* Cbbtab = ycbcr->Cb_b_tab;                                     \
-    int32* Crgtab = ycbcr->Cr_g_tab;                                   \
-    int32* Cbgtab = ycbcr->Cb_g_tab;                                   \
-    TIFFRGBValue* clamptab = ycbcr->clamptab
 
 /*
 
 /*
- * 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB
+ * 8-bit packed YCbCr samples => RGB 
+ * This function is generic for different sampling sizes, 
+ * and can handle blocks sizes that aren't multiples of the
+ * sampling size.  However, it is substantially less optimized
+ * than the specific sampling cases.  It is used as a fallback
+ * for difficult blocks.
  */
  */
-DECLAREContigPutFunc(putcontig8bitYCbCr44tile)
+#ifdef notdef
+static void putcontig8bitYCbCrGenericTile( 
+    TIFFRGBAImage* img, 
+    uint32* cp, 
+    uint32 x, uint32 y, 
+    uint32 w, uint32 h, 
+    int32 fromskew, int32 toskew, 
+    u_char* pp,
+    int h_group, 
+    int v_group )
+
 {
 {
-    YCbCrSetup;
     uint32* cp1 = cp+w+toskew;
     uint32* cp2 = cp1+w+toskew;
     uint32* cp3 = cp2+w+toskew;
     int32 incr = 3*w+4*toskew;
     uint32* cp1 = cp+w+toskew;
     uint32* cp2 = cp1+w+toskew;
     uint32* cp3 = cp2+w+toskew;
     int32 incr = 3*w+4*toskew;
+    int32   Cb, Cr;
+    int     group_size = v_group * h_group + 2;
 
     (void) y;
 
     (void) y;
-    /* XXX adjust fromskew */
+    fromskew = (fromskew * group_size) / h_group;
+
+    for( yy = 0; yy < h; yy++ )
+    {
+        u_char *pp_line;
+        int     y_line_group = yy / v_group;
+        int     y_remainder = yy - y_line_group * v_group;
+
+        pp_line = pp + v_line_group * 
+
+        
+        for( xx = 0; xx < w; xx++ )
+        {
+            Cb = pp
+        }
+    }
     for (; h >= 4; h -= 4) {
        x = w>>2;
        do {
     for (; h >= 4; h -= 4) {
        x = w>>2;
        do {
-           int Cb = pp[16];
-           int Cr = pp[17];
+           Cb = pp[16];
+           Cr = pp[17];
 
            YCbCrtoRGB(cp [0], pp[ 0]);
            YCbCrtoRGB(cp [1], pp[ 1]);
 
            YCbCrtoRGB(cp [0], pp[ 0]);
            YCbCrtoRGB(cp [1], pp[ 1]);
@@ -1289,38 +1653,180 @@ DECLAREContigPutFunc(putcontig8bitYCbCr44tile)
        pp += fromskew;
     }
 }
        pp += fromskew;
     }
 }
+#endif
+
+/*
+ * 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB
+ */
+DECLAREContigPutFunc(putcontig8bitYCbCr44tile)
+{
+    uint32* cp1 = cp+w+toskew;
+    uint32* cp2 = cp1+w+toskew;
+    uint32* cp3 = cp2+w+toskew;
+    int32 incr = 3*w+4*toskew;
+
+    (void) y;
+    /* adjust fromskew */
+    fromskew = (fromskew * 18) / 4;
+    if ((h & 3) == 0 && (w & 3) == 0) {                                        
+        for (; h >= 4; h -= 4) {
+            x = w>>2;
+            do {
+                int32 Cb = pp[16];
+                int32 Cr = pp[17];
+
+                YCbCrtoRGB(cp [0], pp[ 0]);
+                YCbCrtoRGB(cp [1], pp[ 1]);
+                YCbCrtoRGB(cp [2], pp[ 2]);
+                YCbCrtoRGB(cp [3], pp[ 3]);
+                YCbCrtoRGB(cp1[0], pp[ 4]);
+                YCbCrtoRGB(cp1[1], pp[ 5]);
+                YCbCrtoRGB(cp1[2], pp[ 6]);
+                YCbCrtoRGB(cp1[3], pp[ 7]);
+                YCbCrtoRGB(cp2[0], pp[ 8]);
+                YCbCrtoRGB(cp2[1], pp[ 9]);
+                YCbCrtoRGB(cp2[2], pp[10]);
+                YCbCrtoRGB(cp2[3], pp[11]);
+                YCbCrtoRGB(cp3[0], pp[12]);
+                YCbCrtoRGB(cp3[1], pp[13]);
+                YCbCrtoRGB(cp3[2], pp[14]);
+                YCbCrtoRGB(cp3[3], pp[15]);
+
+                cp += 4, cp1 += 4, cp2 += 4, cp3 += 4;
+                pp += 18;
+            } while (--x);
+            cp += incr, cp1 += incr, cp2 += incr, cp3 += incr;
+            pp += fromskew;
+        }
+    } else {
+        while (h > 0) {
+            for (x = w; x > 0;) {
+                int32 Cb = pp[16];
+                int32 Cr = pp[17];
+                switch (x) {
+                default:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp3[3], pp[15]); /* FALLTHROUGH */
+                    case 3:  YCbCrtoRGB(cp2[3], pp[11]); /* FALLTHROUGH */
+                    case 2:  YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 3:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp3[2], pp[14]); /* FALLTHROUGH */
+                    case 3:  YCbCrtoRGB(cp2[2], pp[10]); /* FALLTHROUGH */
+                    case 2:  YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 2:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp3[1], pp[13]); /* FALLTHROUGH */
+                    case 3:  YCbCrtoRGB(cp2[1], pp[ 9]); /* FALLTHROUGH */
+                    case 2:  YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 1:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp3[0], pp[12]); /* FALLTHROUGH */
+                    case 3:  YCbCrtoRGB(cp2[0], pp[ 8]); /* FALLTHROUGH */
+                    case 2:  YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                }
+                if (x < 4) {
+                    cp += x; cp1 += x; cp2 += x; cp3 += x;
+                    x = 0;
+                }
+                else {
+                    cp += 4; cp1 += 4; cp2 += 4; cp3 += 4;
+                    x -= 4;
+                }
+                pp += 18;
+            }
+            if (h <= 4)
+                break;
+            h -= 4;
+            cp += incr, cp1 += incr, cp2 += incr, cp3 += incr;
+            pp += fromskew;
+        }
+    }
+}
 
 /*
  * 8-bit packed YCbCr samples w/ 4,2 subsampling => RGB
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr42tile)
 {
 
 /*
  * 8-bit packed YCbCr samples w/ 4,2 subsampling => RGB
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr42tile)
 {
-    YCbCrSetup;
     uint32* cp1 = cp+w+toskew;
     int32 incr = 2*toskew+w;
 
     (void) y;
     uint32* cp1 = cp+w+toskew;
     int32 incr = 2*toskew+w;
 
     (void) y;
-    /* XXX adjust fromskew */
-    for (; h >= 2; h -= 2) {
-       x = w>>2;
-       do {
-           int Cb = pp[8];
-           int Cr = pp[9];
-
-           YCbCrtoRGB(cp [0], pp[0]);
-           YCbCrtoRGB(cp [1], pp[1]);
-           YCbCrtoRGB(cp [2], pp[2]);
-           YCbCrtoRGB(cp [3], pp[3]);
-           YCbCrtoRGB(cp1[0], pp[4]);
-           YCbCrtoRGB(cp1[1], pp[5]);
-           YCbCrtoRGB(cp1[2], pp[6]);
-           YCbCrtoRGB(cp1[3], pp[7]);
-
-           cp += 4, cp1 += 4;
-           pp += 10;
-       } while (--x);
-       cp += incr, cp1 += incr;
-       pp += fromskew;
+    fromskew = (fromskew * 10) / 4;
+    if ((h & 3) == 0 && (w & 1) == 0) {
+        for (; h >= 2; h -= 2) {
+            x = w>>2;
+            do {
+                int32 Cb = pp[8];
+                int32 Cr = pp[9];
+                
+                YCbCrtoRGB(cp [0], pp[0]);
+                YCbCrtoRGB(cp [1], pp[1]);
+                YCbCrtoRGB(cp [2], pp[2]);
+                YCbCrtoRGB(cp [3], pp[3]);
+                YCbCrtoRGB(cp1[0], pp[4]);
+                YCbCrtoRGB(cp1[1], pp[5]);
+                YCbCrtoRGB(cp1[2], pp[6]);
+                YCbCrtoRGB(cp1[3], pp[7]);
+                
+                cp += 4, cp1 += 4;
+                pp += 10;
+            } while (--x);
+            cp += incr, cp1 += incr;
+            pp += fromskew;
+        }
+    } else {
+        while (h > 0) {
+            for (x = w; x > 0;) {
+                int32 Cb = pp[8];
+                int32 Cr = pp[9];
+                switch (x) {
+                default:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 3:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 2:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 1:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                }
+                if (x < 4) {
+                    cp += x; cp1 += x;
+                    x = 0;
+                }
+                else {
+                    cp += 4; cp1 += 4;
+                    x -= 4;
+                }
+                pp += 10;
+            }
+            if (h <= 2)
+                break;
+            h -= 2;
+            cp += incr, cp1 += incr;
+            pp += fromskew;
+        }
     }
 }
 
     }
 }
 
@@ -1329,15 +1835,13 @@ DECLAREContigPutFunc(putcontig8bitYCbCr42tile)
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
 {
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
 {
-    YCbCrSetup;
-
     (void) y;
     /* XXX adjust fromskew */
     do {
        x = w>>2;
        do {
     (void) y;
     /* XXX adjust fromskew */
     do {
        x = w>>2;
        do {
-           int Cb = pp[4];
-           int Cr = pp[5];
+           int32 Cb = pp[4];
+           int32 Cr = pp[5];
 
            YCbCrtoRGB(cp [0], pp[0]);
            YCbCrtoRGB(cp [1], pp[1]);
 
            YCbCrtoRGB(cp [0], pp[0]);
            YCbCrtoRGB(cp [1], pp[1]);
@@ -1347,9 +1851,27 @@ DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
            cp += 4;
            pp += 6;
        } while (--x);
            cp += 4;
            pp += 6;
        } while (--x);
+
+        if( (w&3) != 0 )
+        {
+           int32 Cb = pp[4];
+           int32 Cr = pp[5];
+
+            switch( (w&3) ) {
+              case 3: YCbCrtoRGB(cp [2], pp[2]);
+              case 2: YCbCrtoRGB(cp [1], pp[1]);
+              case 1: YCbCrtoRGB(cp [0], pp[0]);
+              case 0: break;
+            }
+
+            cp += (w&3);
+            pp += 6;
+        }
+
        cp += toskew;
        pp += fromskew;
     } while (--h);
        cp += toskew;
        pp += fromskew;
     } while (--h);
+
 }
 
 /*
 }
 
 /*
@@ -1357,28 +1879,62 @@ DECLAREContigPutFunc(putcontig8bitYCbCr41tile)
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr22tile)
 {
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr22tile)
 {
-    YCbCrSetup;
     uint32* cp1 = cp+w+toskew;
     int32 incr = 2*toskew+w;
 
     (void) y;
     uint32* cp1 = cp+w+toskew;
     int32 incr = 2*toskew+w;
 
     (void) y;
-    /* XXX adjust fromskew */
-    for (; h >= 2; h -= 2) {
-       x = w>>1;
-       do {
-           int Cb = pp[4];
-           int Cr = pp[5];
-
-           YCbCrtoRGB(cp [0], pp[0]);
-           YCbCrtoRGB(cp [1], pp[1]);
-           YCbCrtoRGB(cp1[0], pp[2]);
-           YCbCrtoRGB(cp1[1], pp[3]);
-
-           cp += 2, cp1 += 2;
-           pp += 6;
-       } while (--x);
-       cp += incr, cp1 += incr;
-       pp += fromskew;
+    fromskew = (fromskew * 6) / 2;
+    if ((h & 1) == 0 && (w & 1) == 0) {
+        for (; h >= 2; h -= 2) {
+            x = w>>1;
+            do {
+                int32 Cb = pp[4];
+                int32 Cr = pp[5];
+
+                YCbCrtoRGB(cp [0], pp[0]);
+                YCbCrtoRGB(cp [1], pp[1]);
+                YCbCrtoRGB(cp1[0], pp[2]);
+                YCbCrtoRGB(cp1[1], pp[3]);
+
+                cp += 2, cp1 += 2;
+                pp += 6;
+            } while (--x);
+            cp += incr, cp1 += incr;
+            pp += fromskew;
+        }
+    } else {
+        while (h > 0) {
+            for (x = w; x > 0;) {
+                int32 Cb = pp[4];
+                int32 Cr = pp[5];
+                switch (x) {
+                default:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[1], pp[ 3]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                case 1:
+                    switch (h) {
+                    default: YCbCrtoRGB(cp1[0], pp[ 2]); /* FALLTHROUGH */
+                    case 1:  YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */
+                    }                                    /* FALLTHROUGH */
+                }
+                if (x < 2) {
+                    cp += x; cp1 += x;
+                    x = 0;
+                }
+                else {
+                    cp += 2; cp1 += 2;
+                    x -= 2;
+                }
+                pp += 6;
+            }
+            if (h <= 2)
+                break;
+            h -= 2;
+            cp += incr, cp1 += incr;
+            pp += fromskew;
+        }
     }
 }
 
     }
 }
 
@@ -1387,22 +1943,32 @@ DECLAREContigPutFunc(putcontig8bitYCbCr22tile)
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr21tile)
 {
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr21tile)
 {
-    YCbCrSetup;
-
     (void) y;
     (void) y;
-    /* XXX adjust fromskew */
+    fromskew = (fromskew * 4) / 2;
     do {
        x = w>>1;
        do {
     do {
        x = w>>1;
        do {
-           int Cb = pp[2];
-           int Cr = pp[3];
+           int32 Cb = pp[2];
+           int32 Cr = pp[3];
 
 
-           YCbCrtoRGB(cp[0], pp[0]);
+           YCbCrtoRGB(cp[0], pp[0]); 
            YCbCrtoRGB(cp[1], pp[1]);
 
            cp += 2;
            pp += 4;
        } while (--x);
            YCbCrtoRGB(cp[1], pp[1]);
 
            cp += 2;
            pp += 4;
        } while (--x);
+
+        if( (w&1) != 0 )
+        {
+           int32 Cb = pp[2];
+           int32 Cr = pp[3];
+            
+            YCbCrtoRGB(cp [0], pp[0]);
+
+           cp += 1;
+           pp += 4;
+        }
+
        cp += toskew;
        pp += fromskew;
     } while (--h);
        cp += toskew;
        pp += fromskew;
     } while (--h);
@@ -1413,15 +1979,13 @@ DECLAREContigPutFunc(putcontig8bitYCbCr21tile)
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr11tile)
 {
  */
 DECLAREContigPutFunc(putcontig8bitYCbCr11tile)
 {
-    YCbCrSetup;
-
     (void) y;
     (void) y;
-    /* XXX adjust fromskew */
+    fromskew *= 3;
     do {
     do {
-       x = w>>1;
+        x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */ 
        do {
        do {
-           int Cb = pp[1];
-           int Cr = pp[2];
+           int32 Cb = pp[1];
+           int32 Cr = pp[2];
 
            YCbCrtoRGB(*cp++, pp[0]);
 
 
            YCbCrtoRGB(*cp++, pp[0]);
 
@@ -1431,125 +1995,87 @@ DECLAREContigPutFunc(putcontig8bitYCbCr11tile)
        pp += fromskew;
     } while (--h);
 }
        pp += fromskew;
     } while (--h);
 }
-#undef YCbCrSetup
 #undef YCbCrtoRGB
 
 #undef YCbCrtoRGB
 
-#define        LumaRed                 coeffs[0]
-#define        LumaGreen               coeffs[1]
-#define        LumaBlue                coeffs[2]
-#define        SHIFT                   16
-#define        FIX(x)                  ((int32)((x) * (1L<<SHIFT) + 0.5))
-#define        ONE_HALF                ((int32)(1<<(SHIFT-1)))
-
-/*
- * Initialize the YCbCr->RGB conversion tables.  The conversion
- * is done according to the 6.0 spec:
- *
- *    R = Y + Cr*(2 - 2*LumaRed)
- *    B = Y + Cb*(2 - 2*LumaBlue)
- *    G =   Y
- *        - LumaBlue*Cb*(2-2*LumaBlue)/LumaGreen
- *        - LumaRed*Cr*(2-2*LumaRed)/LumaGreen
- *
- * To avoid floating point arithmetic the fractional constants that
- * come out of the equations are represented as fixed point values
- * in the range 0...2^16.  We also eliminate multiplications by
- * pre-calculating possible values indexed by Cb and Cr (this code
- * assumes conversion is being done for 8-bit samples).
- */
-static void
-TIFFYCbCrToRGBInit(TIFFYCbCrToRGB* ycbcr, TIFF* tif)
+static tileContigRoutine
+initYCbCrConversion(TIFFRGBAImage* img)
 {
 {
-    TIFFRGBValue* clamptab;
-    float* coeffs;
-    int i;
+       static char module[] = "initCIELabConversion";
 
 
-    clamptab = (TIFFRGBValue*)(
-       (tidata_t) ycbcr+TIFFroundup(sizeof (TIFFYCbCrToRGB), sizeof (long)));
-    _TIFFmemset(clamptab, 0, 256);             /* v < 0 => 0 */
-    ycbcr->clamptab = (clamptab += 256);
-    for (i = 0; i < 256; i++)
-       clamptab[i] = i;
-    _TIFFmemset(clamptab+256, 255, 2*256);     /* v > 255 => 255 */
-    TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &coeffs);
-    _TIFFmemcpy(ycbcr->coeffs, coeffs, 3*sizeof (float));
-    { float f1 = 2-2*LumaRed;          int32 D1 = FIX(f1);
-      float f2 = LumaRed*f1/LumaGreen; int32 D2 = -FIX(f2);
-      float f3 = 2-2*LumaBlue;         int32 D3 = FIX(f3);
-      float f4 = LumaBlue*f3/LumaGreen;        int32 D4 = -FIX(f4);
-      int x;
-
-      ycbcr->Cr_r_tab = (int*) (clamptab + 3*256);
-      ycbcr->Cb_b_tab = ycbcr->Cr_r_tab + 256;
-      ycbcr->Cr_g_tab = (int32*) (ycbcr->Cb_b_tab + 256);
-      ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256;
-      /*
-       * i is the actual input pixel value in the range 0..255
-       * Cb and Cr values are in the range -128..127 (actually
-       * they are in a range defined by the ReferenceBlackWhite
-       * tag) so there is some range shifting to do here when
-       * constructing tables indexed by the raw pixel data.
-       *
-       * XXX handle ReferenceBlackWhite correctly to calculate
-       *     Cb/Cr values to use in constructing the tables.
-       */
-      for (i = 0, x = -128; i < 256; i++, x++) {
-         ycbcr->Cr_r_tab[i] = (int)((D1*x + ONE_HALF)>>SHIFT);
-         ycbcr->Cb_b_tab[i] = (int)((D3*x + ONE_HALF)>>SHIFT);
-         ycbcr->Cr_g_tab[i] = D2*x;
-         ycbcr->Cb_g_tab[i] = D4*x + ONE_HALF;
-      }
-    }
+       float *luma, *refBlackWhite;
+       uint16 hs, vs;
+
+       if (img->ycbcr == NULL) {
+           img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc(
+                   TIFFroundup(sizeof (TIFFYCbCrToRGB), sizeof (long))
+                   + 4*256*sizeof (TIFFRGBValue)
+                   + 2*256*sizeof (int)
+                   + 3*256*sizeof (int32)
+           );
+           if (img->ycbcr == NULL) {
+                   TIFFError(module,
+                             "No space for YCbCr->RGB conversion state");
+                   return (NULL);
+           }
+       }
+
+       TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma);
+       TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE,
+                             &refBlackWhite);
+       if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0)
+               return NULL;
+
+       /*
+        * The 6.0 spec says that subsampling must be
+        * one of 1, 2, or 4, and that vertical subsampling
+        * must always be <= horizontal subsampling; so
+        * there are only a few possibilities and we just
+        * enumerate the cases.
+        */
+       TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs);
+       switch ((hs<<4)|vs) {
+               case 0x44: return (putcontig8bitYCbCr44tile);
+               case 0x42: return (putcontig8bitYCbCr42tile);
+               case 0x41: return (putcontig8bitYCbCr41tile);
+               case 0x22: return (putcontig8bitYCbCr22tile);
+               case 0x21: return (putcontig8bitYCbCr21tile);
+               case 0x11: return (putcontig8bitYCbCr11tile);
+       }
+
+       return (NULL);
 }
 }
-#undef SHIFT
-#undef ONE_HALF
-#undef FIX
-#undef LumaBlue
-#undef LumaGreen
-#undef LumaRed
 
 static tileContigRoutine
 
 static tileContigRoutine
-initYCbCrConversion(TIFFRGBAImage* img)
+initCIELabConversion(TIFFRGBAImage* img)
 {
 {
-    uint16 hs, vs;
-
-    if (img->ycbcr == NULL) {
-       img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc(
-             TIFFroundup(sizeof (TIFFYCbCrToRGB), sizeof (long))
-           + 4*256*sizeof (TIFFRGBValue)
-           + 2*256*sizeof (int)
-           + 2*256*sizeof (int32)
-       );
-       if (img->ycbcr == NULL) {
-           TIFFError(TIFFFileName(img->tif),
-               "No space for YCbCr->RGB conversion state");
-           return (NULL);
+       static char module[] = "initCIELabConversion";
+
+       float   *whitePoint;
+       float   refWhite[3];
+
+       if (!img->cielab) {
+               img->cielab = (TIFFCIELabToRGB *)
+                       _TIFFmalloc(sizeof(TIFFCIELabToRGB));
+               if (!img->cielab) {
+                       TIFFError(module,
+                           "No space for CIE L*a*b*->RGB conversion state.");
+                       return NULL;
+               }
        }
        }
-       TIFFYCbCrToRGBInit(img->ycbcr, img->tif);
-    } else {
-       float* coeffs;
 
 
-       TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &coeffs);
-       if (_TIFFmemcmp(coeffs, img->ycbcr->coeffs, 3*sizeof (float)) != 0)
-           TIFFYCbCrToRGBInit(img->ycbcr, img->tif);
-    }
-    /*
-     * The 6.0 spec says that subsampling must be
-     * one of 1, 2, or 4, and that vertical subsampling
-     * must always be <= horizontal subsampling; so
-     * there are only a few possibilities and we just
-     * enumerate the cases.
-     */
-    TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs);
-    switch ((hs<<4)|vs) {
-    case 0x44: return (&putcontig8bitYCbCr44tile);
-    case 0x42: return (&putcontig8bitYCbCr42tile);
-    case 0x41: return (&putcontig8bitYCbCr41tile);
-    case 0x22: return (&putcontig8bitYCbCr22tile);
-    case 0x21: return (&putcontig8bitYCbCr21tile);
-    case 0x11: return (&putcontig8bitYCbCr11tile);
-    }
-    return (NULL);
+       TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &whitePoint);
+       refWhite[1] = 100.0F;
+       refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
+       refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1])
+                     / whitePoint[1] * refWhite[1];
+       if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, refWhite) < 0) {
+               TIFFError(module,
+                   "Failed to initialize CIE L*a*b*->RGB conversion state.");
+               _TIFFfree(img->cielab);
+               return NULL;
+       }
+
+       return putcontig8bitCIELab;
 }
 
 /*
 }
 
 /*
@@ -1568,6 +2094,9 @@ makebwmap(TIFFRGBAImage* img)
     int i;
     uint32* p;
 
     int i;
     uint32* p;
 
+    if( nsamples == 0 )
+        nsamples = 1;
+
     img->BWmap = (uint32**) _TIFFmalloc(
        256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));
     if (img->BWmap == NULL) {
     img->BWmap = (uint32**) _TIFFmalloc(
        256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));
     if (img->BWmap == NULL) {
@@ -1601,6 +2130,7 @@ makebwmap(TIFFRGBAImage* img)
            GREY(i&0xf);
            break;
        case 8:
            GREY(i&0xf);
            break;
        case 8:
+        case 16:
            GREY(i);
            break;
        }
            GREY(i);
            break;
        }
@@ -1613,13 +2143,18 @@ makebwmap(TIFFRGBAImage* img)
  * Construct a mapping table to convert from the range
  * of the data samples to [0,255] --for display.  This
  * process also handles inverting B&W images when needed.
  * Construct a mapping table to convert from the range
  * of the data samples to [0,255] --for display.  This
  * process also handles inverting B&W images when needed.
- */
+ */ 
 static int
 setupMap(TIFFRGBAImage* img)
 {
     int32 x, range;
 
     range = (int32)((1L<<img->bitspersample)-1);
 static int
 setupMap(TIFFRGBAImage* img)
 {
     int32 x, range;
 
     range = (int32)((1L<<img->bitspersample)-1);
+    
+    /* treat 16 bit the same as eight bit */
+    if( img->bitspersample == 16 )
+        range = (int32) 255;
+
     img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue));
     if (img->Map == NULL) {
        TIFFError(TIFFFileName(img->tif),
     img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue));
     if (img->Map == NULL) {
        TIFFError(TIFFFileName(img->tif),
@@ -1628,12 +2163,12 @@ setupMap(TIFFRGBAImage* img)
     }
     if (img->photometric == PHOTOMETRIC_MINISWHITE) {
        for (x = 0; x <= range; x++)
     }
     if (img->photometric == PHOTOMETRIC_MINISWHITE) {
        for (x = 0; x <= range; x++)
-           img->Map[x] = ((range - x) * 255) / range;
+           img->Map[x] = (TIFFRGBValue) (((range - x) * 255) / range);
     } else {
        for (x = 0; x <= range; x++)
     } else {
        for (x = 0; x <= range; x++)
-           img->Map[x] = (x * 255) / range;
+           img->Map[x] = (TIFFRGBValue) ((x * 255) / range);
     }
     }
-    if (img->bitspersample <= 8 &&
+    if (img->bitspersample <= 16 &&
        (img->photometric == PHOTOMETRIC_MINISBLACK ||
         img->photometric == PHOTOMETRIC_MINISWHITE)) {
        /*
        (img->photometric == PHOTOMETRIC_MINISBLACK ||
         img->photometric == PHOTOMETRIC_MINISWHITE)) {
        /*
@@ -1707,7 +2242,7 @@ makecmap(TIFFRGBAImage* img)
     for (i = 0; i < 256; i++) {
        TIFFRGBValue c;
        img->PALmap[i] = p;
     for (i = 0; i < 256; i++) {
        TIFFRGBValue c;
        img->PALmap[i] = p;
-#define        CMAP(x) c = x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);
+#define        CMAP(x) c = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);
        switch (bitspersample) {
        case 1:
            CMAP(i>>7);
        switch (bitspersample) {
        case 1:
            CMAP(i>>7);
@@ -1738,7 +2273,7 @@ makecmap(TIFFRGBAImage* img)
     return (1);
 }
 
     return (1);
 }
 
-/*
+/* 
  * Construct any mapping table used
  * by the associated put routine.
  */
  * Construct any mapping table used
  * by the associated put routine.
  */
@@ -1830,16 +2365,21 @@ pickTileContigCase(TIFFRGBAImage* img)
        case PHOTOMETRIC_MINISWHITE:
        case PHOTOMETRIC_MINISBLACK:
            switch (img->bitspersample) {
        case PHOTOMETRIC_MINISWHITE:
        case PHOTOMETRIC_MINISBLACK:
            switch (img->bitspersample) {
-           case 8:     put = putgreytile; break;
-           case 4: put = put4bitbwtile; break;
-           case 2: put = put2bitbwtile; break;
-           case 1: put = put1bitbwtile; break;
+            case 16: put = put16bitbwtile; break;
+           case 8:  put = putgreytile; break;
+           case 4:  put = put4bitbwtile; break;
+           case 2:  put = put2bitbwtile; break;
+           case 1:  put = put1bitbwtile; break;
            }
            break;
        case PHOTOMETRIC_YCBCR:
            if (img->bitspersample == 8)
                put = initYCbCrConversion(img);
            break;
            }
            break;
        case PHOTOMETRIC_YCBCR:
            if (img->bitspersample == 8)
                put = initYCbCrConversion(img);
            break;
+       case PHOTOMETRIC_CIELAB:
+           if (img->bitspersample == 8)
+               put = initCIELabConversion(img);
+           break;
        }
     }
     return ((img->put.contig = put) != 0);
        }
     }
     return ((img->put.contig = put) != 0);
@@ -1910,7 +2450,7 @@ TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster )
                   "Can't use TIFFReadRGBAStrip() with tiled file.");
        return (0);
     }
                   "Can't use TIFFReadRGBAStrip() with tiled file.");
        return (0);
     }
-
+    
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     if( (row % rowsperstrip) != 0 )
     {
     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
     if( (row % rowsperstrip) != 0 )
     {
@@ -1919,7 +2459,7 @@ TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster )
        return (0);
     }
 
        return (0);
     }
 
-    if (TIFFRGBAImageBegin(&img, tif, 0, emsg)) {
+    if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, 0, emsg)) {
 
         img.row_offset = row;
         img.col_offset = 0;
 
         img.row_offset = row;
         img.col_offset = 0;
@@ -1928,15 +2468,15 @@ TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster )
             rows_to_read = img.height - row;
         else
             rows_to_read = rowsperstrip;
             rows_to_read = img.height - row;
         else
             rows_to_read = rowsperstrip;
-
+        
        ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read );
        ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read );
-
+        
        TIFFRGBAImageEnd(&img);
     } else {
        TIFFError(TIFFFileName(tif), emsg);
        ok = 0;
     }
        TIFFRGBAImageEnd(&img);
     } else {
        TIFFError(TIFFFileName(tif), emsg);
        ok = 0;
     }
-
+    
     return (ok);
 }
 
     return (ok);
 }
 
@@ -1955,20 +2495,20 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster)
     int        ok;
     uint32     tile_xsize, tile_ysize;
     uint32     read_xsize, read_ysize;
     int        ok;
     uint32     tile_xsize, tile_ysize;
     uint32     read_xsize, read_ysize;
-    int                i_row;
+    uint32     i_row;
 
     /*
      * Verify that our request is legal - on a tile file, and on a
      * tile boundary.
      */
 
     /*
      * Verify that our request is legal - on a tile file, and on a
      * tile boundary.
      */
-
+    
     if( !TIFFIsTiled( tif ) )
     {
         TIFFError(TIFFFileName(tif),
                   "Can't use TIFFReadRGBATile() with stripped file.");
        return (0);
     }
     if( !TIFFIsTiled( tif ) )
     {
         TIFFError(TIFFFileName(tif),
                   "Can't use TIFFReadRGBATile() with stripped file.");
        return (0);
     }
-
+    
     TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize);
     TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize);
     if( (col % tile_xsize) != 0 || (row % tile_ysize) != 0 )
     TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize);
     TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize);
     if( (col % tile_xsize) != 0 || (row % tile_ysize) != 0 )
@@ -1982,10 +2522,11 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster)
     /*
      * Setup the RGBA reader.
      */
     /*
      * Setup the RGBA reader.
      */
-
-    if ( !TIFFRGBAImageBegin(&img, tif, 0, emsg)) {
-       TIFFError(TIFFFileName(tif), emsg);
-        return( 0 );
+    
+    if (!TIFFRGBAImageOK(tif, emsg) 
+       || !TIFFRGBAImageBegin(&img, tif, 0, emsg)) {
+           TIFFError(TIFFFileName(tif), emsg);
+           return( 0 );
     }
 
     /*
     }
 
     /*
@@ -1999,7 +2540,7 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster)
         read_ysize = img.height - row;
     else
         read_ysize = tile_ysize;
         read_ysize = img.height - row;
     else
         read_ysize = tile_ysize;
-
+    
     if( col + tile_xsize > img.width )
         read_xsize = img.width - col;
     else
     if( col + tile_xsize > img.width )
         read_xsize = img.width - col;
     else
@@ -2008,12 +2549,12 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster)
     /*
      * Read the chunk of imagery.
      */
     /*
      * Read the chunk of imagery.
      */
-
+    
     img.row_offset = row;
     img.col_offset = col;
 
     ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize );
     img.row_offset = row;
     img.col_offset = col;
 
     ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize );
-
+        
     TIFFRGBAImageEnd(&img);
 
     /*
     TIFFRGBAImageEnd(&img);
 
     /*
@@ -2021,23 +2562,21 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster)
      * shifting the data around as if a full tile of data is being returned.
      *
      * This is all the more complicated because the image is organized in
      * shifting the data around as if a full tile of data is being returned.
      *
      * This is all the more complicated because the image is organized in
-     * bottom to top format.
+     * bottom to top format. 
      */
 
     if( read_xsize == tile_xsize && read_ysize == tile_ysize )
         return( ok );
 
      */
 
     if( read_xsize == tile_xsize && read_ysize == tile_ysize )
         return( ok );
 
-    for( i_row = 0; i_row < read_ysize; i_row++ )
-    {
-        _TIFFmemcpy( raster + (tile_ysize - i_row - 1) * tile_xsize,
-                     raster + (read_ysize - i_row - 1) * read_xsize,
-                     read_xsize * sizeof(uint32) );
+    for( i_row = 0; i_row < read_ysize; i_row++ ) {
+        memmove( raster + (tile_ysize - i_row - 1) * tile_xsize,
+                 raster + (read_ysize - i_row - 1) * read_xsize,
+                 read_xsize * sizeof(uint32) );
         _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize+read_xsize,
                      0, sizeof(uint32) * (tile_xsize - read_xsize) );
     }
 
         _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize+read_xsize,
                      0, sizeof(uint32) * (tile_xsize - read_xsize) );
     }
 
-    for( i_row = read_ysize; i_row < tile_ysize; i_row++ )
-    {
+    for( i_row = read_ysize; i_row < tile_ysize; i_row++ ) {
         _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize,
                      0, sizeof(uint32) * tile_xsize );
     }
         _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize,
                      0, sizeof(uint32) * tile_xsize );
     }
index 76433f704bac29d6cd8d65be1a7be4e3b275938d..529afa71171b4d7943afcf6d3f7320d0ca393a2f 100644 (file)
 #include <assert.h>
 #include <stdio.h>
 #include <setjmp.h>
 #include <assert.h>
 #include <stdio.h>
 #include <setjmp.h>
+
+int TIFFFillStrip(TIFF*, tstrip_t);
+int TIFFFillTile(TIFF*, ttile_t);
+
+/* We undefine FAR to avoid conflict with JPEG definition */
+
+#ifdef FAR
+#undef FAR
+#endif
+
+/*
+   The windows RPCNDR.H file defines boolean, but defines it with the
+   wrong size.  So we declare HAVE_BOOLEAN so that the jpeg include file
+   won't try to typedef boolean, but #define it to override the rpcndr.h
+   definition.
+
+   http://bugzilla.remotesensing.org/show_bug.cgi?id=188
+*/
+#if defined(__RPCNDR_H__)
+#define HAVE_BOOLEAN
+#define boolean unsigned int
+#endif
+
 #include "jpeglib.h"
 #include "jerror.h"
 
 #include "jpeglib.h"
 #include "jerror.h"
 
@@ -75,6 +98,8 @@ typedef       struct {
                struct jpeg_decompress_struct d;
                struct jpeg_common_struct comm;
        } cinfo;                        /* NB: must be first */
                struct jpeg_decompress_struct d;
                struct jpeg_common_struct comm;
        } cinfo;                        /* NB: must be first */
+        int             cinfo_initialized;
+
        jpeg_error_mgr  err;            /* libjpeg error manager */
        JMP_BUF         exit_jmpbuf;    /* for catching libjpeg failures */
        /*
        jpeg_error_mgr  err;            /* libjpeg error manager */
        JMP_BUF         exit_jmpbuf;    /* for catching libjpeg failures */
        /*
@@ -104,6 +129,8 @@ typedef     struct {
        int             jpegquality;    /* Compression quality level */
        int             jpegcolormode;  /* Auto RGB<=>YCbCr convert? */
        int             jpegtablesmode; /* What to put in JPEGTables */
        int             jpegquality;    /* Compression quality level */
        int             jpegcolormode;  /* Auto RGB<=>YCbCr convert? */
        int             jpegtablesmode; /* What to put in JPEGTables */
+
+        int             ycbcrsampling_fetched;
 } JPEGState;
 
 #define        JState(tif)     ((JPEGState*)(tif)->tif_data)
 } JPEGState;
 
 #define        JState(tif)     ((JPEGState*)(tif)->tif_data)
@@ -112,6 +139,7 @@ static      int JPEGDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGDecodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGEncode(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGEncodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGDecodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGEncode(TIFF*, tidata_t, tsize_t, tsample_t);
 static int JPEGEncodeRaw(TIFF*, tidata_t, tsize_t, tsample_t);
+static  int JPEGInitializeLibJPEG( TIFF * tif );
 
 #define        FIELD_JPEGTABLES        (FIELD_CODEC+0)
 
 
 #define        FIELD_JPEGTABLES        (FIELD_CODEC+0)
 
@@ -549,10 +577,6 @@ alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info,
                sp->ds_buffer[ci] = buf;
        }
        sp->samplesperclump = samples_per_clump;
                sp->ds_buffer[ci] = buf;
        }
        sp->samplesperclump = samples_per_clump;
-       /* Cb,Cr both have sampling factors 1 */
-       /* so downsampled width of Cb is # of clumps per line */
-       sp->bytesperline = sizeof(JSAMPLE) * samples_per_clump *
-               comp_info[1].downsampled_width;
        return (1);
 }
 
        return (1);
 }
 
@@ -567,6 +591,8 @@ JPEGSetupDecode(TIFF* tif)
        JPEGState* sp = JState(tif);
        TIFFDirectory *td = &tif->tif_dir;
 
        JPEGState* sp = JState(tif);
        TIFFDirectory *td = &tif->tif_dir;
 
+        JPEGInitializeLibJPEG( tif );
+
        assert(sp != NULL);
        assert(sp->cinfo.comm.is_decompressor);
 
        assert(sp != NULL);
        assert(sp->cinfo.comm.is_decompressor);
 
@@ -628,13 +654,13 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
        /*
         * Check image parameters and set decompression parameters.
         */
        /*
         * Check image parameters and set decompression parameters.
         */
+       segment_width = td->td_imagewidth;
+       segment_height = td->td_imagelength - tif->tif_row;
        if (isTiled(tif)) {
        if (isTiled(tif)) {
-               segment_width = td->td_tilewidth;
-               segment_height = td->td_tilelength;
+                segment_width = td->td_tilewidth;
+                segment_height = td->td_tilelength;
                sp->bytesperline = TIFFTileRowSize(tif);
        } else {
                sp->bytesperline = TIFFTileRowSize(tif);
        } else {
-               segment_width = td->td_imagewidth;
-               segment_height = td->td_imagelength - tif->tif_row;
                if (segment_height > td->td_rowsperstrip)
                        segment_height = td->td_rowsperstrip;
                sp->bytesperline = TIFFScanlineSize(tif);
                if (segment_height > td->td_rowsperstrip)
                        segment_height = td->td_rowsperstrip;
                sp->bytesperline = TIFFScanlineSize(tif);
@@ -649,8 +675,12 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
        }
        if (sp->cinfo.d.image_width != segment_width ||
            sp->cinfo.d.image_height != segment_height) {
        }
        if (sp->cinfo.d.image_width != segment_width ||
            sp->cinfo.d.image_height != segment_height) {
-               TIFFError(module, "Improper JPEG strip/tile size");
-               return (0);
+               TIFFWarning(module, 
+                 "Improper JPEG strip/tile size, expected %dx%d, got %dx%d",
+                          segment_width, 
+                          segment_height,
+                          sp->cinfo.d.image_width, 
+                          sp->cinfo.d.image_height);
        }
        if (sp->cinfo.d.num_components !=
            (td->td_planarconfig == PLANARCONFIG_CONTIG ?
        }
        if (sp->cinfo.d.num_components !=
            (td->td_planarconfig == PLANARCONFIG_CONTIG ?
@@ -666,8 +696,22 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
                /* Component 0 should have expected sampling factors */
                if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling ||
                    sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) {
                /* Component 0 should have expected sampling factors */
                if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling ||
                    sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) {
-                       TIFFError(module, "Improper JPEG sampling factors");
-                       return (0);
+                       TIFFWarning(module, 
+                                    "Improper JPEG sampling factors %d,%d\n"
+                                    "Apparently should be %d,%d, "
+                                    "decompressor will try reading with "
+                                    "sampling %d,%d",
+                                    sp->cinfo.d.comp_info[0].h_samp_factor,
+                                    sp->cinfo.d.comp_info[0].v_samp_factor,
+                                    sp->h_sampling, 
+                                    sp->v_sampling,
+                                    sp->cinfo.d.comp_info[0].h_samp_factor,
+                                    sp->cinfo.d.comp_info[0].v_samp_factor );
+
+                        sp->h_sampling = (uint16)
+                            sp->cinfo.d.comp_info[0].h_samp_factor;
+                        sp->v_sampling = (uint16)
+                            sp->cinfo.d.comp_info[0].v_samp_factor;
                }
                /* Rest should have sampling factors 1,1 */
                for (ci = 1; ci < sp->cinfo.d.num_components; ci++) {
                }
                /* Rest should have sampling factors 1,1 */
                for (ci = 1; ci < sp->cinfo.d.num_components; ci++) {
@@ -689,11 +733,11 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
        if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
            sp->photometric == PHOTOMETRIC_YCBCR &&
            sp->jpegcolormode == JPEGCOLORMODE_RGB) {
        if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
            sp->photometric == PHOTOMETRIC_YCBCR &&
            sp->jpegcolormode == JPEGCOLORMODE_RGB) {
-               /* Convert YCbCr to RGB */
+       /* Convert YCbCr to RGB */
                sp->cinfo.d.jpeg_color_space = JCS_YCbCr;
                sp->cinfo.d.out_color_space = JCS_RGB;
        } else {
                sp->cinfo.d.jpeg_color_space = JCS_YCbCr;
                sp->cinfo.d.out_color_space = JCS_RGB;
        } else {
-               /* Suppress colorspace handling */
+                       /* Suppress colorspace handling */
                sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN;
                sp->cinfo.d.out_color_space = JCS_UNKNOWN;
                if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
                sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN;
                sp->cinfo.d.out_color_space = JCS_UNKNOWN;
                if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
@@ -731,112 +775,112 @@ JPEGPreDecode(TIFF* tif, tsample_t s)
  * Decode a chunk of pixels.
  * "Standard" case: returned data is not downsampled.
  */
  * Decode a chunk of pixels.
  * "Standard" case: returned data is not downsampled.
  */
-static int
+/*ARGSUSED*/ static int
 JPEGDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
 JPEGDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
-       JPEGState *sp = JState(tif);
-       tsize_t nrows;
-       JSAMPROW bufptr[1];
-
-       (void) s;
-       assert(sp != NULL);
-       /* data is expected to be read in multiples of a scanline */
-       nrows = cc / sp->bytesperline;
-       if (cc % sp->bytesperline)
-               TIFFWarning(tif->tif_name, "fractional scanline not read");
-
-       while (nrows-- > 0) {
-               bufptr[0] = (JSAMPROW) buf;
-               if (TIFFjpeg_read_scanlines(sp, bufptr, 1) != 1)
-                       return (0);
-               if (nrows > 0)
-                       tif->tif_row++;
-               buf += sp->bytesperline;
-       }
-       /* Close down the decompressor if we've finished the strip or tile. */
-       if (sp->cinfo.d.output_scanline == sp->cinfo.d.output_height) {
-               if (TIFFjpeg_finish_decompress(sp) != TRUE)
-                       return (0);
-       }
-       return (1);
+    JPEGState *sp = JState(tif);
+    tsize_t nrows;
+
+    nrows = cc / sp->bytesperline;
+    if (cc % sp->bytesperline)
+        TIFFWarning(tif->tif_name, "fractional scanline not read");
+
+    if( nrows > (int) sp->cinfo.d.image_height )
+        nrows = sp->cinfo.d.image_height;
+
+    /* data is expected to be read in multiples of a scanline */
+    if (nrows)
+    {
+        do {
+            JSAMPROW bufptr = (JSAMPROW)buf;
+
+            if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1)
+                return (0);
+            ++tif->tif_row;
+            buf += sp->bytesperline;
+            cc -= sp->bytesperline;
+        } while (--nrows > 0);
+    }
+    /* Close down the decompressor if we've finished the strip or tile. */
+    return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
+        || TIFFjpeg_finish_decompress(sp);
 }
 
 /*
  * Decode a chunk of pixels.
  * Returned data is downsampled per sampling factors.
  */
 }
 
 /*
  * Decode a chunk of pixels.
  * Returned data is downsampled per sampling factors.
  */
-static int
+/*ARGSUSED*/ static int
 JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        JPEGState *sp = JState(tif);
 JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        JPEGState *sp = JState(tif);
-       JSAMPLE* inptr;
-       JSAMPLE* outptr;
        tsize_t nrows;
        tsize_t nrows;
-       JDIMENSION clumps_per_line, nclump;
-       int clumpoffset, ci, xpos, ypos;
-       jpeg_component_info* compptr;
-       int samples_per_clump = sp->samplesperclump;
 
 
-       (void) s;
-       assert(sp != NULL);
        /* data is expected to be read in multiples of a scanline */
        /* data is expected to be read in multiples of a scanline */
-       nrows = cc / sp->bytesperline;
-       if (cc % sp->bytesperline)
-               TIFFWarning(tif->tif_name, "fractional scanline not read");
+       if ( (nrows = sp->cinfo.d.image_height) ) {
+               /* Cb,Cr both have sampling factors 1, so this is correct */
+               JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
+               int samples_per_clump = sp->samplesperclump;
+       
+               do {
+                       jpeg_component_info *compptr;
+                       int ci, clumpoffset;
 
 
-       /* Cb,Cr both have sampling factors 1, so this is correct */
-       clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
+                       /* Reload downsampled-data buffer if needed */
+                       if (sp->scancount >= DCTSIZE) {
+                               int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
 
 
-       while (nrows-- > 0) {
-               /* Reload downsampled-data buffer if needed */
-               if (sp->scancount >= DCTSIZE) {
-                       int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
-                       if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n)
-                               return (0);
-                       sp->scancount = 0;
-                       /* Close down the decompressor if done. */
-                       if (sp->cinfo.d.output_scanline >=
-                           sp->cinfo.d.output_height) {
-                               if (TIFFjpeg_finish_decompress(sp) != TRUE)
+                               if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n)
+                                       != n)
                                        return (0);
                                        return (0);
+                               sp->scancount = 0;
                        }
                        }
-               }
-               /*
-                * Fastest way to unseparate the data is to make one pass
-                * over the scanline for each row of each component.
-                */
-               clumpoffset = 0;                /* first sample in clump */
-               for (ci = 0, compptr = sp->cinfo.d.comp_info;
-                    ci < sp->cinfo.d.num_components;
-                    ci++, compptr++) {
-                   int hsamp = compptr->h_samp_factor;
-                   int vsamp = compptr->v_samp_factor;
-                   for (ypos = 0; ypos < vsamp; ypos++) {
-                       inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
-                       outptr = ((JSAMPLE*) buf) + clumpoffset;
-                       if (hsamp == 1) {
-                           /* fast path for at least Cb and Cr */
-                           for (nclump = clumps_per_line; nclump-- > 0; ) {
-                               outptr[0] = *inptr++;
-                               outptr += samples_per_clump;
-                           }
-                       } else {
-                           /* general case */
-                           for (nclump = clumps_per_line; nclump-- > 0; ) {
-                               for (xpos = 0; xpos < hsamp; xpos++)
-                                   outptr[xpos] = *inptr++;
-                               outptr += samples_per_clump;
+                       /*
+                        * Fastest way to unseparate data is to make one pass
+                        * over the scanline for each row of each component.
+                        */
+                       clumpoffset = 0;        /* first sample in clump */
+                       for (ci = 0, compptr = sp->cinfo.d.comp_info;
+                            ci < sp->cinfo.d.num_components;
+                            ci++, compptr++) {
+                           int hsamp = compptr->h_samp_factor;
+                           int vsamp = compptr->v_samp_factor;
+                           int ypos;
+
+                           for (ypos = 0; ypos < vsamp; ypos++) {
+                               JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
+                               JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
+                               JDIMENSION nclump;
+
+                               if (hsamp == 1) {
+                                   /* fast path for at least Cb and Cr */
+                                   for (nclump = clumps_per_line; nclump-- > 0; ) {
+                                       outptr[0] = *inptr++;
+                                       outptr += samples_per_clump;
+                                   }
+                               } else {
+                                       int xpos;
+
+                                   /* general case */
+                                   for (nclump = clumps_per_line; nclump-- > 0; ) {
+                                       for (xpos = 0; xpos < hsamp; xpos++)
+                                           outptr[xpos] = *inptr++;
+                                       outptr += samples_per_clump;
+                                   }
+                               }
+                               clumpoffset += hsamp;
                            }
                        }
                            }
                        }
-                       clumpoffset += hsamp;
-                   }
-               }
-               sp->scancount++;
-               if (nrows > 0)
-                       tif->tif_row++;
-               buf += sp->bytesperline;
+                       ++sp->scancount;
+                       ++tif->tif_row;
+                       buf += sp->bytesperline;
+                       cc -= sp->bytesperline;
+               } while (--nrows > 0);
        }
        }
-       return (1);
+
+        /* Close down the decompressor if done. */
+        return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
+                   || TIFFjpeg_finish_decompress(sp);
 }
 
 
 }
 
 
@@ -869,6 +913,8 @@ prepare_JPEGTables(TIFF* tif)
 {
        JPEGState* sp = JState(tif);
 
 {
        JPEGState* sp = JState(tif);
 
+        JPEGInitializeLibJPEG( tif );
+
        /* Initialize quant tables for current quality setting */
        if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
                return (0);
        /* Initialize quant tables for current quality setting */
        if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
                return (0);
@@ -903,6 +949,8 @@ JPEGSetupEncode(TIFF* tif)
        TIFFDirectory *td = &tif->tif_dir;
        static const char module[] = "JPEGSetupEncode";
 
        TIFFDirectory *td = &tif->tif_dir;
        static const char module[] = "JPEGSetupEncode";
 
+        JPEGInitializeLibJPEG( tif );
+
        assert(sp != NULL);
        assert(!sp->cinfo.comm.is_decompressor);
 
        assert(sp != NULL);
        assert(!sp->cinfo.comm.is_decompressor);
 
@@ -926,7 +974,6 @@ JPEGSetupEncode(TIFF* tif)
                 * default value is inappropriate for YCbCr.  Fill in the
                 * proper value if application didn't set it.
                 */
                 * default value is inappropriate for YCbCr.  Fill in the
                 * proper value if application didn't set it.
                 */
-#ifdef COLORIMETRY_SUPPORT
                if (!TIFFFieldSet(tif, FIELD_REFBLACKWHITE)) {
                        float refbw[6];
                        long top = 1L << td->td_bitspersample;
                if (!TIFFFieldSet(tif, FIELD_REFBLACKWHITE)) {
                        float refbw[6];
                        long top = 1L << td->td_bitspersample;
@@ -938,7 +985,6 @@ JPEGSetupEncode(TIFF* tif)
                        refbw[5] = refbw[1];
                        TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refbw);
                }
                        refbw[5] = refbw[1];
                        TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refbw);
                }
-#endif
                break;
        case PHOTOMETRIC_PALETTE:               /* disallowed by Tech Note */
        case PHOTOMETRIC_MASK:
                break;
        case PHOTOMETRIC_PALETTE:               /* disallowed by Tech Note */
        case PHOTOMETRIC_MASK:
@@ -1279,7 +1325,8 @@ JPEGCleanup(TIFF* tif)
 {
        if (tif->tif_data) {
                JPEGState *sp = JState(tif);
 {
        if (tif->tif_data) {
                JPEGState *sp = JState(tif);
-               TIFFjpeg_destroy(sp);           /* release libjpeg resources */
+                if( sp->cinfo_initialized )
+                    TIFFjpeg_destroy(sp);      /* release libjpeg resources */
                if (sp->jpegtables)             /* tag value */
                        _TIFFfree(sp->jpegtables);
                _TIFFfree(tif->tif_data);       /* release local state */
                if (sp->jpegtables)             /* tag value */
                        _TIFFfree(sp->jpegtables);
                _TIFFfree(tif->tif_data);       /* release local state */
@@ -1336,6 +1383,10 @@ JPEGVSetField(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_JPEGTABLESMODE:
                sp->jpegtablesmode = va_arg(ap, int);
                return (1);                     /* pseudo tag */
        case TIFFTAG_JPEGTABLESMODE:
                sp->jpegtablesmode = va_arg(ap, int);
                return (1);                     /* pseudo tag */
+       case TIFFTAG_YCBCRSUBSAMPLING:
+                /* mark the fact that we have a real ycbcrsubsampling! */
+               sp->ycbcrsampling_fetched = 1;
+               return (*sp->vsetparent)(tif, tag, ap);
        default:
                return (*sp->vsetparent)(tif, tag, ap);
        }
        default:
                return (*sp->vsetparent)(tif, tag, ap);
        }
@@ -1343,6 +1394,73 @@ JPEGVSetField(TIFF* tif, ttag_t tag, va_list ap)
        return (1);
 }
 
        return (1);
 }
 
+/*
+ * Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in
+ * the TIFF tags, but still use non-default (2,2) values within the jpeg
+ * data stream itself.  In order for TIFF applications to work properly
+ * - for instance to get the strip buffer size right - it is imperative
+ * that the subsampling be available before we start reading the image
+ * data normally.  This function will attempt to load the first strip in
+ * order to get the sampling values from the jpeg data stream.  Various
+ * hacks are various places are done to ensure this function gets called
+ * before the td_ycbcrsubsampling values are used from the directory structure,
+ * including calling TIFFGetField() for the YCBCRSUBSAMPLING field from 
+ * TIFFStripSize(), and the printing code in tif_print.c. 
+ *
+ * Note that JPEGPreDeocode() will produce a fairly loud warning when the
+ * discovered sampling does not match the default sampling (2,2) or whatever
+ * was actually in the tiff tags. 
+ *
+ * Problems:
+ *  o This code will cause one whole strip/tile of compressed data to be
+ *    loaded just to get the tags right, even if the imagery is never read.
+ *    It would be more efficient to just load a bit of the header, and
+ *    initialize things from that. 
+ *
+ * See the bug in bugzilla for details:
+ *
+ * http://bugzilla.remotesensing.org/show_bug.cgi?id=168
+ *
+ * Frank Warmerdam, July 2002
+ */
+
+static void 
+JPEGFixupTestSubsampling( TIFF * tif )
+{
+#if CHECK_JPEG_YCBCR_SUBSAMPLING == 1
+    JPEGState *sp = JState(tif);
+    TIFFDirectory *td = &tif->tif_dir;
+
+    JPEGInitializeLibJPEG( tif );
+
+    /*
+     * Some JPEG-in-TIFF files don't provide the ycbcrsampling tags, 
+     * and use a sampling schema other than the default 2,2.  To handle
+     * this we actually have to scan the header of a strip or tile of
+     * jpeg data to get the sampling.  
+     */
+    if( !sp->cinfo.comm.is_decompressor 
+        || sp->ycbcrsampling_fetched  
+        || td->td_photometric != PHOTOMETRIC_YCBCR )
+        return;
+
+    sp->ycbcrsampling_fetched = 1;
+    if( TIFFIsTiled( tif ) )
+    {
+        if( !TIFFFillTile( tif, 0 ) )
+            return;
+    }
+    else
+    {
+        if( !TIFFFillStrip( tif, 0 ) )
+            return;
+    }
+
+    TIFFSetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
+                  (uint16) sp->h_sampling, (uint16) sp->v_sampling );
+#endif /* CHECK_JPEG_YCBCR_SUBSAMPLING == 1 */
+}
+
 static int
 JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
 {
 static int
 JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
 {
@@ -1364,6 +1482,10 @@ JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
        case TIFFTAG_JPEGTABLESMODE:
                *va_arg(ap, int*) = sp->jpegtablesmode;
                break;
        case TIFFTAG_JPEGTABLESMODE:
                *va_arg(ap, int*) = sp->jpegtablesmode;
                break;
+       case TIFFTAG_YCBCRSUBSAMPLING:
+                JPEGFixupTestSubsampling( tif );
+               return (*sp->vgetparent)(tif, tag, ap);
+               break;
        default:
                return (*sp->vgetparent)(tif, tag, ap);
        }
        default:
                return (*sp->vgetparent)(tif, tag, ap);
        }
@@ -1404,6 +1526,72 @@ JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th)
        *th = TIFFroundup(*th, td->td_ycbcrsubsampling[1] * DCTSIZE);
 }
 
        *th = TIFFroundup(*th, td->td_ycbcrsubsampling[1] * DCTSIZE);
 }
 
+/*
+ * The JPEG library initialized used to be done in TIFFInitJPEG(), but
+ * now that we allow a TIFF file to be opened in update mode it is necessary
+ * to have some way of deciding whether compression or decompression is
+ * desired other than looking at tif->tif_mode.  We accomplish this by 
+ * examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry.
+ * If so, we assume decompression is desired. 
+ *
+ * This is tricky, because TIFFInitJPEG() is called while the directory is
+ * being read, and generally speaking the BYTECOUNTS tag won't have been read
+ * at that point.  So we try to defer jpeg library initialization till we
+ * do have that tag ... basically any access that might require the compressor
+ * or decompressor that occurs after the reading of the directory. 
+ *
+ * In an ideal world compressors or decompressors would be setup
+ * at the point where a single tile or strip was accessed (for read or write)
+ * so that stuff like update of missing tiles, or replacement of tiles could
+ * be done. However, we aren't trying to crack that nut just yet ...
+ *
+ * NFW, Feb 3rd, 2003.
+ */
+
+static int JPEGInitializeLibJPEG( TIFF * tif )
+{
+    JPEGState* sp = JState(tif);
+    uint32 *byte_counts = NULL;
+    int     data_is_empty = TRUE;
+
+    if( sp->cinfo_initialized )
+        return 1;
+
+    /*
+     * Do we have tile data already?  Make sure we initialize the
+     * the state in decompressor mode if we have tile data, even if we
+     * are not in read-only file access mode. 
+     */
+    if( TIFFIsTiled( tif ) 
+        && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &byte_counts ) 
+        && byte_counts != NULL )
+    {
+        data_is_empty = byte_counts[0] == 0;
+    }
+    if( !TIFFIsTiled( tif ) 
+        && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &byte_counts) 
+        && byte_counts != NULL )
+    {
+        data_is_empty = byte_counts[0] == 0;
+    }
+
+    /*
+     * Initialize libjpeg.
+     */
+    if (tif->tif_mode == O_RDONLY || !data_is_empty ) {
+        if (!TIFFjpeg_create_decompress(sp))
+            return (0);
+
+    } else {
+        if (!TIFFjpeg_create_compress(sp))
+            return (0);
+    }
+
+    sp->cinfo_initialized = TRUE;
+
+    return 1;
+}
+
 int
 TIFFInitJPEG(TIFF* tif, int scheme)
 {
 int
 TIFFInitJPEG(TIFF* tif, int scheme)
 {
@@ -1415,10 +1603,13 @@ TIFFInitJPEG(TIFF* tif, int scheme)
         * Allocate state block so tag methods have storage to record values.
         */
        tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (JPEGState));
         * Allocate state block so tag methods have storage to record values.
         */
        tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (JPEGState));
+
        if (tif->tif_data == NULL) {
                TIFFError("TIFFInitJPEG", "No space for JPEG state block");
                return (0);
        }
        if (tif->tif_data == NULL) {
                TIFFError("TIFFInitJPEG", "No space for JPEG state block");
                return (0);
        }
+        memset( tif->tif_data, 0, sizeof(JPEGState));
+
        sp = JState(tif);
        sp->tif = tif;                          /* back link */
 
        sp = JState(tif);
        sp->tif = tif;                          /* back link */
 
@@ -1427,11 +1618,11 @@ TIFFInitJPEG(TIFF* tif, int scheme)
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo));
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = JPEGVGetField;     /* hook for codec tags */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = JPEGVSetField;     /* hook for codec tags */
-       tif->tif_printdir = JPEGPrintDir;       /* hook for codec tags */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield = JPEGVGetField;  /* hook for codec tags */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield = JPEGVSetField;  /* hook for codec tags */
+       tif->tif_tagmethods.printdir = JPEGPrintDir;    /* hook for codec tags */
 
        /* Default values for codec-specific fields */
        sp->jpegtables = NULL;
 
        /* Default values for codec-specific fields */
        sp->jpegtables = NULL;
@@ -1440,6 +1631,8 @@ TIFFInitJPEG(TIFF* tif, int scheme)
        sp->jpegcolormode = JPEGCOLORMODE_RAW;
        sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF;
 
        sp->jpegcolormode = JPEGCOLORMODE_RAW;
        sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF;
 
+        sp->ycbcrsampling_fetched = 0;
+
        /*
         * Install codec methods.
         */
        /*
         * Install codec methods.
         */
@@ -1461,16 +1654,13 @@ TIFFInitJPEG(TIFF* tif, int scheme)
        tif->tif_deftilesize = JPEGDefaultTileSize;
        tif->tif_flags |= TIFF_NOBITREV;        /* no bit reversal, please */
 
        tif->tif_deftilesize = JPEGDefaultTileSize;
        tif->tif_flags |= TIFF_NOBITREV;        /* no bit reversal, please */
 
-       /*
-        * Initialize libjpeg.
-        */
-       if (tif->tif_mode == O_RDONLY) {
-               if (!TIFFjpeg_create_decompress(sp))
-                       return (0);
-       } else {
-               if (!TIFFjpeg_create_compress(sp))
-                       return (0);
-       }
+        sp->cinfo_initialized = FALSE;
+
+        /*
+         * Mark the TIFFTAG_YCBCRSAMPLES as present even if it is not
+         * see: JPEGFixupTestSubsampling().
+         */
+        TIFFSetFieldBit( tif, FIELD_YCBCRSUBSAMPLING );
 
        return (1);
 }
 
        return (1);
 }
index 5adaa54e0fe6ef795d80282d324c2d521e9b726f..4c3d06e44932a793d2bb454dd29d9bc8c2b3447c 100644 (file)
@@ -2,23 +2,23 @@
  * Copyright (c) 1997 Greg Ward Larson
  * Copyright (c) 1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1997 Greg Ward Larson
  * Copyright (c) 1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any
  * advertising or publicity relating to the software without the specific,
  * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any
  * advertising or publicity relating to the software without the specific,
  * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE
  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE
  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -34,7 +34,7 @@
  * LogLuv image support uses the TIFF library to store 16 or 10-bit
  * log luminance values with 8 bits each of u and v or a 14-bit index.
  *
  * LogLuv image support uses the TIFF library to store 16 or 10-bit
  * log luminance values with 8 bits each of u and v or a 14-bit index.
  *
- * The codec can take as input and produce as output 32-bit IEEE float values
+ * The codec can take as input and produce as output 32-bit IEEE float values 
  * as well as 16-bit integer values.  A 16-bit luminance is interpreted
  * as a sign bit followed by a 15-bit integer that is converted
  * to and from a linear magnitude using the transformation:
  * as well as 16-bit integer values.  A 16-bit luminance is interpreted
  * as a sign bit followed by a 15-bit integer that is converted
  * to and from a linear magnitude using the transformation:
  * of conversion to and from LogLuv, though the application is still
  * responsible for interpreting the TIFFTAG_STONITS calibration factor.
  *
  * of conversion to and from LogLuv, though the application is still
  * responsible for interpreting the TIFFTAG_STONITS calibration factor.
  *
- * The information is compressed into one of two basic encodings, depending on
- * the setting of the compression tag, which is one of COMPRESSION_SGILOG
+ * By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white
+ * point of (x,y)=(1/3,1/3).  However, most color systems assume some other
+ * white point, such as D65, and an absolute color conversion to XYZ then
+ * to another color space with a different white point may introduce an
+ * unwanted color cast to the image.  It is often desirable, therefore, to
+ * perform a white point conversion that maps the input white to [1 1 1]
+ * in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT
+ * tag value.  A decoder that demands absolute color calibration may use
+ * this white point tag to get back the original colors, but usually it
+ * will be ignored and the new white point will be used instead that
+ * matches the output color space.
+ *
+ * Pixel information is compressed into one of two basic encodings, depending
+ * on the setting of the compression tag, which is one of COMPRESSION_SGILOG
  * or COMPRESSION_SGILOG24.  For COMPRESSION_SGILOG, greyscale data is
  * stored as:
  *
  * or COMPRESSION_SGILOG24.  For COMPRESSION_SGILOG, greyscale data is
  * stored as:
  *
  * scheme by separating the logL, u and v bytes for each row and applying
  * a PackBits type of compression.  Since the 24-bit encoding is not
  * adaptive, the 32-bit color format takes less space in many cases.
  * scheme by separating the logL, u and v bytes for each row and applying
  * a PackBits type of compression.  Since the 24-bit encoding is not
  * adaptive, the 32-bit color format takes less space in many cases.
+ *
+ * Further control is provided over the conversion from higher-resolution
+ * formats to final encoded values through the pseudo tag
+ * TIFFTAG_SGILOGENCODE:
+ *  SGILOGENCODE_NODITHER     = do not dither encoded values
+ *  SGILOGENCODE_RANDITHER    = apply random dithering during encoding
+ *
+ * The default value of this tag is SGILOGENCODE_NODITHER for
+ * COMPRESSION_SGILOG to maximize run-length encoding and
+ * SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn
+ * quantization errors into noise.
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
@@ -135,10 +158,11 @@ typedef   struct logLuvState LogLuvState;
 
 struct logLuvState {
        int                     user_datafmt;   /* user data format */
 
 struct logLuvState {
        int                     user_datafmt;   /* user data format */
+       int                     encode_meth;    /* encoding method */
        int                     pixel_size;     /* bytes per pixel */
 
        tidata_t*               tbuf;           /* translation buffer */
        int                     pixel_size;     /* bytes per pixel */
 
        tidata_t*               tbuf;           /* translation buffer */
-       short                   tbuflen;        /* buffer length */
+       int                     tbuflen;        /* buffer length */
        void (*tfunc)(LogLuvState*, tidata_t, int);
 
        TIFFVSetMethod          vgetparent;     /* super-class method */
        void (*tfunc)(LogLuvState*, tidata_t, int);
 
        TIFFVSetMethod          vgetparent;     /* super-class method */
@@ -156,7 +180,7 @@ struct logLuvState {
 /*
  * Decode a string of 16-bit gray pixels.
  */
 /*
  * Decode a string of 16-bit gray pixels.
  */
-static int LINKAGEMODE
+static int
 LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp = DecoderState(tif);
 LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp = DecoderState(tif);
@@ -186,13 +210,13 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
                for (i = 0; i < npixels && cc > 0; )
                        if (*bp >= 128) {               /* run */
                                rc = *bp++ + (2-128);
                for (i = 0; i < npixels && cc > 0; )
                        if (*bp >= 128) {               /* run */
                                rc = *bp++ + (2-128);
-                               b = (int16)*bp++ << shft;
+                               b = (int16)(*bp++ << shft);
                                cc -= 2;
                                cc -= 2;
-                               while (rc--)
+                               while (rc-- && i < npixels)
                                        tp[i++] |= b;
                        } else {                        /* non-run */
                                rc = *bp++;             /* nul is noop */
                                        tp[i++] |= b;
                        } else {                        /* non-run */
                                rc = *bp++;             /* nul is noop */
-                               while (--cc && rc--)
+                               while (--cc && rc-- && i < npixels)
                                        tp[i++] |= (int16)*bp++ << shft;
                        }
                if (i != npixels) {
                                        tp[i++] |= (int16)*bp++ << shft;
                        }
                if (i != npixels) {
@@ -213,7 +237,7 @@ LogL16Decode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 /*
  * Decode a string of 24-bit pixels.
  */
 /*
  * Decode a string of 24-bit pixels.
  */
-static int LINKAGEMODE
+static int
 LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp = DecoderState(tif);
 LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp = DecoderState(tif);
@@ -232,7 +256,6 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
                assert(sp->tbuflen >= npixels);
                tp = (uint32 *) sp->tbuf;
        }
                assert(sp->tbuflen >= npixels);
                tp = (uint32 *) sp->tbuf;
        }
-       _TIFFmemset((tdata_t) tp, 0, npixels*sizeof (tp[0]));
                                        /* copy to array of uint32 */
        bp = (u_char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
                                        /* copy to array of uint32 */
        bp = (u_char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
@@ -256,7 +279,7 @@ LogLuvDecode24(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 /*
  * Decode a string of 32-bit pixels.
  */
 /*
  * Decode a string of 32-bit pixels.
  */
-static int LINKAGEMODE
+static int
 LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp;
 LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        LogLuvState* sp;
@@ -289,11 +312,11 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
                                rc = *bp++ + (2-128);
                                b = (uint32)*bp++ << shft;
                                cc -= 2;
                                rc = *bp++ + (2-128);
                                b = (uint32)*bp++ << shft;
                                cc -= 2;
-                               while (rc--)
+                               while (rc-- && i < npixels)
                                        tp[i++] |= b;
                        } else {                        /* non-run */
                                rc = *bp++;             /* nul is noop */
                                        tp[i++] |= b;
                        } else {                        /* non-run */
                                rc = *bp++;             /* nul is noop */
-                               while (--cc && rc--)
+                               while (--cc && rc-- && i < npixels)
                                        tp[i++] |= (uint32)*bp++ << shft;
                        }
                if (i != npixels) {
                                        tp[i++] |= (uint32)*bp++ << shft;
                        }
                if (i != npixels) {
@@ -316,7 +339,7 @@ LogLuvDecode32(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
  * maintain synchrony with the encode algorithm, which
  * is row by row.
  */
  * maintain synchrony with the encode algorithm, which
  * is row by row.
  */
-static int LINKAGEMODE
+static int
 LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFScanlineSize(tif);
 LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFScanlineSize(tif);
@@ -332,7 +355,7 @@ LogLuvDecodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
  * maintain synchrony with the encode algorithm, which
  * is row by row.
  */
  * maintain synchrony with the encode algorithm, which
  * is row by row.
  */
-static int LINKAGEMODE
+static int
 LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFTileRowSize(tif);
 LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFTileRowSize(tif);
@@ -346,7 +369,7 @@ LogLuvDecodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 /*
  * Encode a row of 16-bit pixels.
  */
 /*
  * Encode a row of 16-bit pixels.
  */
-static int LINKAGEMODE
+static int
 LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
 LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
@@ -382,7 +405,7 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                        }
                        mask = 0xff << shft;            /* find next run */
                        for (beg = i; beg < npixels; beg += rc) {
                        }
                        mask = 0xff << shft;            /* find next run */
                        for (beg = i; beg < npixels; beg += rc) {
-                               b = tp[beg] & mask;
+                               b = (int16) (tp[beg] & mask);
                                rc = 1;
                                while (rc < 127+2 && beg+rc < npixels &&
                                                (tp[beg+rc] & mask) == b)
                                rc = 1;
                                while (rc < 127+2 && beg+rc < npixels &&
                                                (tp[beg+rc] & mask) == b)
@@ -391,36 +414,36 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                                        break;          /* long enough */
                        }
                        if (beg-i > 1 && beg-i < MINRUN) {
                                        break;          /* long enough */
                        }
                        if (beg-i > 1 && beg-i < MINRUN) {
-                               b = tp[i] & mask;       /* check short run */
+                               b = (int16) (tp[i] & mask);/*check short run */
                                j = i+1;
                                while ((tp[j++] & mask) == b)
                                j = i+1;
                                while ((tp[j++] & mask) == b)
-                                       if (j == beg) {
-                                               *op++ = 128-2+j-i;
-                                               *op++ = b >> shft;
-                                               occ -= 2;
-                                               i = beg;
-                                               break;
-                                       }
+                                    if (j == beg) {
+                                        *op++ = (tidataval_t)(128-2+j-i);
+                                        *op++ = (tidataval_t) (b >> shft);
+                                        occ -= 2;
+                                        i = beg;
+                                        break;
+                                    }
                        }
                        while (i < beg) {               /* write out non-run */
                                if ((j = beg-i) > 127) j = 127;
                                if (occ < j+3) {
                        }
                        while (i < beg) {               /* write out non-run */
                                if ((j = beg-i) > 127) j = 127;
                                if (occ < j+3) {
-                                       tif->tif_rawcp = op;
-                                       tif->tif_rawcc = tif->tif_rawdatasize - occ;
-                                       if (!TIFFFlushData1(tif))
-                                               return (-1);
-                                       op = tif->tif_rawcp;
-                                       occ = tif->tif_rawdatasize - tif->tif_rawcc;
+                                    tif->tif_rawcp = op;
+                                    tif->tif_rawcc = tif->tif_rawdatasize - occ;
+                                    if (!TIFFFlushData1(tif))
+                                        return (-1);
+                                    op = tif->tif_rawcp;
+                                    occ = tif->tif_rawdatasize - tif->tif_rawcc;
                                }
                                }
-                               *op++ = j; occ--;
+                               *op++ = (tidataval_t) j; occ--;
                                while (j--) {
                                while (j--) {
-                                       *op++ = tp[i++] >> shft & 0xff;
+                                       *op++ = (tidataval_t) (tp[i++] >> shft & 0xff);
                                        occ--;
                                }
                        }
                        if (rc >= MINRUN) {             /* write out run */
                                        occ--;
                                }
                        }
                        if (rc >= MINRUN) {             /* write out run */
-                               *op++ = 128-2+rc;
-                               *op++ = tp[beg] >> shft & 0xff;
+                               *op++ = (tidataval_t) (128-2+rc);
+                               *op++ = (tidataval_t) (tp[beg] >> shft & 0xff);
                                occ -= 2;
                        } else
                                rc = 0;
                                occ -= 2;
                        } else
                                rc = 0;
@@ -434,7 +457,7 @@ LogL16Encode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 /*
  * Encode a row of 24-bit pixels.
  */
 /*
  * Encode a row of 24-bit pixels.
  */
-static int LINKAGEMODE
+static int
 LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
 LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
@@ -465,9 +488,9 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                        op = tif->tif_rawcp;
                        occ = tif->tif_rawdatasize - tif->tif_rawcc;
                }
                        op = tif->tif_rawcp;
                        occ = tif->tif_rawdatasize - tif->tif_rawcc;
                }
-               *op++ = *tp >> 16;
-               *op++ = *tp >> 8 & 0xff;
-               *op++ = *tp++ & 0xff;
+               *op++ = (tidataval_t)(*tp >> 16);
+               *op++ = (tidataval_t)(*tp >> 8 & 0xff);
+               *op++ = (tidataval_t)(*tp++ & 0xff);
                occ -= 3;
        }
        tif->tif_rawcp = op;
                occ -= 3;
        }
        tif->tif_rawcp = op;
@@ -479,7 +502,7 @@ LogLuvEncode24(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 /*
  * Encode a row of 32-bit pixels.
  */
 /*
  * Encode a row of 32-bit pixels.
  */
-static int LINKAGEMODE
+static int
 LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
 LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        LogLuvState* sp = EncoderState(tif);
@@ -529,8 +552,8 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                                j = i+1;
                                while ((tp[j++] & mask) == b)
                                        if (j == beg) {
                                j = i+1;
                                while ((tp[j++] & mask) == b)
                                        if (j == beg) {
-                                               *op++ = 128-2+j-i;
-                                               *op++ = b >> shft;
+                                               *op++ = (tidataval_t)(128-2+j-i);
+                                               *op++ = (tidataval_t)(b >> shft);
                                                occ -= 2;
                                                i = beg;
                                                break;
                                                occ -= 2;
                                                i = beg;
                                                break;
@@ -546,15 +569,15 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
                                        op = tif->tif_rawcp;
                                        occ = tif->tif_rawdatasize - tif->tif_rawcc;
                                }
                                        op = tif->tif_rawcp;
                                        occ = tif->tif_rawdatasize - tif->tif_rawcc;
                                }
-                               *op++ = j; occ--;
+                               *op++ = (tidataval_t) j; occ--;
                                while (j--) {
                                while (j--) {
-                                       *op++ = tp[i++] >> shft & 0xff;
+                                       *op++ = (tidataval_t)(tp[i++] >> shft & 0xff);
                                        occ--;
                                }
                        }
                        if (rc >= MINRUN) {             /* write out run */
                                        occ--;
                                }
                        }
                        if (rc >= MINRUN) {             /* write out run */
-                               *op++ = 128-2+rc;
-                               *op++ = tp[beg] >> shft & 0xff;
+                               *op++ = (tidataval_t) (128-2+rc);
+                               *op++ = (tidataval_t)(tp[beg] >> shft & 0xff);
                                occ -= 2;
                        } else
                                rc = 0;
                                occ -= 2;
                        } else
                                rc = 0;
@@ -569,7 +592,7 @@ LogLuvEncode32(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
  * Encode a strip of pixels.  We break it into rows to
  * avoid encoding runs across row boundaries.
  */
  * Encode a strip of pixels.  We break it into rows to
  * avoid encoding runs across row boundaries.
  */
-static int LINKAGEMODE
+static int
 LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFScanlineSize(tif);
 LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFScanlineSize(tif);
@@ -584,7 +607,7 @@ LogLuvEncodeStrip(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
  * Encode a tile of pixels.  We break it into rows to
  * avoid encoding runs across row boundaries.
  */
  * Encode a tile of pixels.  We break it into rows to
  * avoid encoding runs across row boundaries.
  */
-static int LINKAGEMODE
+static int
 LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFTileRowSize(tif);
 LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
        tsize_t rowlen = TIFFTileRowSize(tif);
@@ -598,49 +621,57 @@ LogLuvEncodeTile(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 /*
  * Encode/Decode functions for converting to and from user formats.
  */
 /*
  * Encode/Decode functions for converting to and from user formats.
  */
-#include "uvcode.h"
 
 
-#define U_NEU  0.210526316
-#define V_NEU  0.473684211
+#include "uvcode.h"
 
 
-#ifdef M_LN2
-#define        LOGOF2          M_LN2
-#else
-#define LOGOF2         0.69314718055994530942
+#ifndef UVSCALE
+#define U_NEU          0.210526316
+#define V_NEU          0.473684211
+#define UVSCALE                410.
 #endif
 #endif
-#ifndef log2
-#define log2(x)                ((1./LOGOF2)*log(x))
+
+#ifndef        M_LN2
+#define M_LN2          0.69314718055994530942
 #endif
 #endif
-#ifndef exp2
-#define exp2(x)                exp(LOGOF2*(x))
+#ifndef M_PI
+#define M_PI           3.14159265358979323846
 #endif
 #endif
-#define UVSCALE                410.
+#define log2(x)                ((1./M_LN2)*log(x))
+#define exp2(x)                exp(M_LN2*(x))
+
+#define itrunc(x,m)    ((m)==SGILOGENCODE_NODITHER ? \
+                               (int)(x) : \
+                               (int)((x) + rand()*(1./RAND_MAX) - .5))
 
 
-static double
-pix16toY(int p16)
+#if !LOGLUV_PUBLIC
+static
+#endif
+double
+LogL16toY(int p16)             /* compute luminance from 16-bit LogL */
 {
        int     Le = p16 & 0x7fff;
        double  Y;
 
        if (!Le)
                return (0.);
 {
        int     Le = p16 & 0x7fff;
        double  Y;
 
        if (!Le)
                return (0.);
-       Y = exp(LOGOF2/256.*(Le+.5) - LOGOF2*64.);
-       if (p16 & 0x8000)
-               return (-Y);
-       return (Y);
+       Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.);
+       return (!(p16 & 0x8000) ? Y : -Y);
 }
 
 }
 
-static int
-pix16fromY(double Y)
+#if !LOGLUV_PUBLIC
+static
+#endif
+int
+LogL16fromY(double Y, int em)  /* get 16-bit LogL from Y */
 {
 {
-       if (Y >= 1.84467e19)
+       if (Y >= 1.8371976e19)
                return (0x7fff);
                return (0x7fff);
-       if (Y <= -1.84467e19)
+       if (Y <= -1.8371976e19)
                return (0xffff);
                return (0xffff);
-       if (Y > 5.43571e-20)
-               return (int)(256.*(log2(Y) + 64.));
-       if (Y < -5.43571e-20)
-               return (~0x7fff | (int)(256.*(log2(-Y) + 64.)));
+       if (Y > 5.4136769e-20)
+               return itrunc(256.*(log2(Y) + 64.), em);
+       if (Y < -5.4136769e-20)
+               return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em));
        return (0);
 }
 
        return (0);
 }
 
@@ -651,7 +682,7 @@ L16toY(LogLuvState* sp, tidata_t op, int n)
        float* yp = (float*) op;
 
        while (n-- > 0)
        float* yp = (float*) op;
 
        while (n-- > 0)
-               *yp++ = pix16toY(*l16++);
+               *yp++ = (float)LogL16toY(*l16++);
 }
 
 static void
 }
 
 static void
@@ -661,8 +692,8 @@ L16toGry(LogLuvState* sp, tidata_t op, int n)
        uint8* gp = (uint8*) op;
 
        while (n-- > 0) {
        uint8* gp = (uint8*) op;
 
        while (n-- > 0) {
-               double Y = pix16toY(*l16++);
-               *gp++ = (Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y));
+               double Y = LogL16toY(*l16++);
+               *gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y)));
        }
 }
 
        }
 }
 
@@ -673,10 +704,13 @@ L16fromY(LogLuvState* sp, tidata_t op, int n)
        float* yp = (float*) op;
 
        while (n-- > 0)
        float* yp = (float*) op;
 
        while (n-- > 0)
-               *l16++ = pix16fromY(*yp++);
+               *l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth));
 }
 
 }
 
-static void
+#if !LOGLUV_PUBLIC
+static
+#endif
+void
 XYZtoRGB24(float xyz[3], uint8 rgb[3])
 {
        double  r, g, b;
 XYZtoRGB24(float xyz[3], uint8 rgb[3])
 {
        double  r, g, b;
@@ -686,68 +720,161 @@ XYZtoRGB24(float xyz[3], uint8 rgb[3])
        b =  0.061*xyz[0] + -0.224*xyz[1] +  1.163*xyz[2];
                                        /* assume 2.0 gamma for speed */
        /* could use integer sqrt approx., but this is probably faster */
        b =  0.061*xyz[0] + -0.224*xyz[1] +  1.163*xyz[2];
                                        /* assume 2.0 gamma for speed */
        /* could use integer sqrt approx., but this is probably faster */
-       rgb[0] = (r <= 0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r));
-       rgb[1] = (g <= 0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g));
-       rgb[2] = (b <= 0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b));
+       rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r)));
+       rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g)));
+       rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b)));
+}
+
+#if !LOGLUV_PUBLIC
+static
+#endif
+double
+LogL10toY(int p10)             /* compute luminance from 10-bit LogL */
+{
+       if (p10 == 0)
+               return (0.);
+       return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.));
 }
 
 }
 
+#if !LOGLUV_PUBLIC
+static
+#endif
+int
+LogL10fromY(double Y, int em)  /* get 10-bit LogL from Y */
+{
+       if (Y >= 15.742)
+               return (0x3ff);
+       else if (Y <= .00024283)
+               return (0);
+       else
+               return itrunc(64.*(log2(Y) + 12.), em);
+}
+
+#define NANGLES                100
+#define uv2ang(u, v)   ( (NANGLES*.499999999/M_PI) \
+                               * atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES )
+
 static int
 static int
-uv_encode(double u, double v)          /* encode (u',v') coordinates */
+oog_encode(double u, double v)         /* encode out-of-gamut chroma */
+{
+       static int      oog_table[NANGLES];
+       static int      initialized = 0;
+       register int    i;
+       
+       if (!initialized) {             /* set up perimeter table */
+               double  eps[NANGLES], ua, va, ang, epsa;
+               int     ui, vi, ustep;
+               for (i = NANGLES; i--; )
+                       eps[i] = 2.;
+               for (vi = UV_NVS; vi--; ) {
+                       va = UV_VSTART + (vi+.5)*UV_SQSIZ;
+                       ustep = uv_row[vi].nus-1;
+                       if (vi == UV_NVS-1 || vi == 0 || ustep <= 0)
+                               ustep = 1;
+                       for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) {
+                               ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
+                               ang = uv2ang(ua, va);
+                                i = (int) ang;
+                               epsa = fabs(ang - (i+.5));
+                               if (epsa < eps[i]) {
+                                       oog_table[i] = uv_row[vi].ncum + ui;
+                                       eps[i] = epsa;
+                               }
+                       }
+               }
+               for (i = NANGLES; i--; )        /* fill any holes */
+                       if (eps[i] > 1.5) {
+                               int     i1, i2;
+                               for (i1 = 1; i1 < NANGLES/2; i1++)
+                                       if (eps[(i+i1)%NANGLES] < 1.5)
+                                               break;
+                               for (i2 = 1; i2 < NANGLES/2; i2++)
+                                       if (eps[(i+NANGLES-i2)%NANGLES] < 1.5)
+                                               break;
+                               if (i1 < i2)
+                                       oog_table[i] =
+                                               oog_table[(i+i1)%NANGLES];
+                               else
+                                       oog_table[i] =
+                                               oog_table[(i+NANGLES-i2)%NANGLES];
+                       }
+               initialized = 1;
+       }
+       i = (int) uv2ang(u, v);         /* look up hue angle */
+       return (oog_table[i]);
+}
+
+#undef uv2ang
+#undef NANGLES
+
+#if !LOGLUV_PUBLIC
+static
+#endif
+int
+uv_encode(double u, double v, int em)  /* encode (u',v') coordinates */
 {
        register int    vi, ui;
 
        if (v < UV_VSTART)
 {
        register int    vi, ui;
 
        if (v < UV_VSTART)
-               return(-1);
-       vi = (v - UV_VSTART)*(1./UV_SQSIZ);
+               return oog_encode(u, v);
+       vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
        if (vi >= UV_NVS)
        if (vi >= UV_NVS)
-               return(-1);
+               return oog_encode(u, v);
        if (u < uv_row[vi].ustart)
        if (u < uv_row[vi].ustart)
-               return(-1);
-       ui = (u - uv_row[vi].ustart)*(1./UV_SQSIZ);
+               return oog_encode(u, v);
+       ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
        if (ui >= uv_row[vi].nus)
        if (ui >= uv_row[vi].nus)
-               return(-1);
-       return(uv_row[vi].ncum + ui);
+               return oog_encode(u, v);
+
+       return (uv_row[vi].ncum + ui);
 }
 
 }
 
-static int
+#if !LOGLUV_PUBLIC
+static
+#endif
+int
 uv_decode(double *up, double *vp, int c)       /* decode (u',v') index */
 {
        int     upper, lower;
        register int    ui, vi;
 
        if (c < 0 || c >= UV_NDIVS)
 uv_decode(double *up, double *vp, int c)       /* decode (u',v') index */
 {
        int     upper, lower;
        register int    ui, vi;
 
        if (c < 0 || c >= UV_NDIVS)
-               return(-1);
-       lower = 0;                      /* binary search */
+               return (-1);
+       lower = 0;                              /* binary search */
        upper = UV_NVS;
        upper = UV_NVS;
-       do {
+       while (upper - lower > 1) {
                vi = (lower + upper) >> 1;
                ui = c - uv_row[vi].ncum;
                if (ui > 0)
                        lower = vi;
                else if (ui < 0)
                        upper = vi;
                vi = (lower + upper) >> 1;
                ui = c - uv_row[vi].ncum;
                if (ui > 0)
                        lower = vi;
                else if (ui < 0)
                        upper = vi;
-               else
+               else {
+                       lower = vi;
                        break;
                        break;
-       } while (upper - lower > 1);
+               }
+       }
        vi = lower;
        ui = c - uv_row[vi].ncum;
        *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
        *vp = UV_VSTART + (vi+.5)*UV_SQSIZ;
        vi = lower;
        ui = c - uv_row[vi].ncum;
        *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ;
        *vp = UV_VSTART + (vi+.5)*UV_SQSIZ;
-       return(0);
+       return (0);
 }
 
 }
 
-static void
-pix24toXYZ(uint32 p, float XYZ[3])
+#if !LOGLUV_PUBLIC
+static
+#endif
+void
+LogLuv24toXYZ(uint32 p, float XYZ[3])
 {
 {
-       int     Le, Ce;
+       int     Ce;
        double  L, u, v, s, x, y;
                                        /* decode luminance */
        double  L, u, v, s, x, y;
                                        /* decode luminance */
-       Le = p >> 14 & 0x3ff;
-       if (Le == 0) {
+       L = LogL10toY(p>>14 & 0x3ff);
+       if (L <= 0.) {
                XYZ[0] = XYZ[1] = XYZ[2] = 0.;
                return;
        }
                XYZ[0] = XYZ[1] = XYZ[2] = 0.;
                return;
        }
-       L = exp(LOGOF2/64.*(Le+.5) - LOGOF2*12.);
                                        /* decode color */
        Ce = p & 0x3fff;
        if (uv_decode(&u, &v, Ce) < 0) {
                                        /* decode color */
        Ce = p & 0x3fff;
        if (uv_decode(&u, &v, Ce) < 0) {
@@ -757,36 +884,33 @@ pix24toXYZ(uint32 p, float XYZ[3])
        x = 9.*u * s;
        y = 4.*v * s;
                                        /* convert to XYZ */
        x = 9.*u * s;
        y = 4.*v * s;
                                        /* convert to XYZ */
-       XYZ[0] = x/y * L;
-       XYZ[1] = L;
-       XYZ[2] = (1.-x-y)/y * L;
+       XYZ[0] = (float)(x/y * L);
+       XYZ[1] = (float)L;
+       XYZ[2] = (float)((1.-x-y)/y * L);
 }
 
 }
 
-static uint32
-pix24fromXYZ(float XYZ[3])
+#if !LOGLUV_PUBLIC
+static
+#endif
+uint32
+LogLuv24fromXYZ(float XYZ[3], int em)
 {
        int     Le, Ce;
 {
        int     Le, Ce;
-       double  L, u, v, s;
+       double  u, v, s;
                                        /* encode luminance */
                                        /* encode luminance */
-       L = XYZ[1];
-       if (L >= 16.)
-               Le = 0x3ff;
-       else if (L <= 1./4096.)
-               Le = 0;
-       else
-               Le = 64.*(log2(L) + 12.);
+       Le = LogL10fromY(XYZ[1], em);
                                        /* encode color */
        s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
                                        /* encode color */
        s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
-       if (s == 0.) {
+       if (!Le || s <= 0.) {
                u = U_NEU;
                v = V_NEU;
        } else {
                u = 4.*XYZ[0] / s;
                v = 9.*XYZ[1] / s;
        }
                u = U_NEU;
                v = V_NEU;
        } else {
                u = 4.*XYZ[0] / s;
                v = 9.*XYZ[1] / s;
        }
-       Ce = uv_encode(u, v);
-       if (Ce < 0)
-               Ce = uv_encode(U_NEU, V_NEU);
+       Ce = uv_encode(u, v, em);
+       if (Ce < 0)                     /* never happens */
+               Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
                                        /* combine encodings */
        return (Le << 14 | Ce);
 }
                                        /* combine encodings */
        return (Le << 14 | Ce);
 }
@@ -798,7 +922,7 @@ Luv24toXYZ(LogLuvState* sp, tidata_t op, int n)
        float* xyz = (float*) op;
 
        while (n-- > 0) {
        float* xyz = (float*) op;
 
        while (n-- > 0) {
-               pix24toXYZ(*luv, xyz);
+               LogLuv24toXYZ(*luv, xyz);
                xyz += 3;
                luv++;
        }
                xyz += 3;
                luv++;
        }
@@ -813,13 +937,13 @@ Luv24toLuv48(LogLuvState* sp, tidata_t op, int n)
        while (n-- > 0) {
                double u, v;
 
        while (n-- > 0) {
                double u, v;
 
-               *luv3++ = (*luv >> 12 & 0xffd) + 13314;
+               *luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314);
                if (uv_decode(&u, &v, *luv&0x3fff) < 0) {
                        u = U_NEU;
                        v = V_NEU;
                }
                if (uv_decode(&u, &v, *luv&0x3fff) < 0) {
                        u = U_NEU;
                        v = V_NEU;
                }
-               *luv3++ = u * (1L<<15);
-               *luv3++ = v * (1L<<15);
+               *luv3++ = (int16)(u * (1L<<15));
+               *luv3++ = (int16)(v * (1L<<15));
                luv++;
        }
 }
                luv++;
        }
 }
@@ -833,7 +957,7 @@ Luv24toRGB(LogLuvState* sp, tidata_t op, int n)
        while (n-- > 0) {
                float xyz[3];
 
        while (n-- > 0) {
                float xyz[3];
 
-               pix24toXYZ(*luv++, xyz);
+               LogLuv24toXYZ(*luv++, xyz);
                XYZtoRGB24(xyz, rgb);
                rgb += 3;
        }
                XYZtoRGB24(xyz, rgb);
                rgb += 3;
        }
@@ -846,7 +970,7 @@ Luv24fromXYZ(LogLuvState* sp, tidata_t op, int n)
        float* xyz = (float*) op;
 
        while (n-- > 0) {
        float* xyz = (float*) op;
 
        while (n-- > 0) {
-               *luv++ = pix24fromXYZ(xyz);
+               *luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth);
                xyz += 3;
        }
 }
                xyz += 3;
        }
 }
@@ -864,23 +988,30 @@ Luv24fromLuv48(LogLuvState* sp, tidata_t op, int n)
                        Le = 0;
                else if (luv3[0] >= (1<<12)+3314)
                        Le = (1<<10) - 1;
                        Le = 0;
                else if (luv3[0] >= (1<<12)+3314)
                        Le = (1<<10) - 1;
-               else
+               else if (sp->encode_meth == SGILOGENCODE_NODITHER)
                        Le = (luv3[0]-3314) >> 2;
                        Le = (luv3[0]-3314) >> 2;
-               Ce = uv_encode((luv[1]+.5)/(1<<15), (luv[2]+.5)/(1<<15));
-               if (Ce < 0)
-                       Ce = uv_encode(U_NEU, V_NEU);
+               else
+                       Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
+
+               Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15),
+                                       sp->encode_meth);
+               if (Ce < 0)     /* never happens */
+                       Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
                *luv++ = (uint32)Le << 14 | Ce;
                luv3 += 3;
        }
 }
 
                *luv++ = (uint32)Le << 14 | Ce;
                luv3 += 3;
        }
 }
 
-static void
-pix32toXYZ(uint32 p, float XYZ[3])
+#if !LOGLUV_PUBLIC
+static
+#endif
+void
+LogLuv32toXYZ(uint32 p, float XYZ[3])
 {
        double  L, u, v, s, x, y;
                                        /* decode luminance */
 {
        double  L, u, v, s, x, y;
                                        /* decode luminance */
-       L = pix16toY((int)p >> 16);
-       if (L == 0.) {
+       L = LogL16toY((int)p >> 16);
+       if (L <= 0.) {
                XYZ[0] = XYZ[1] = XYZ[2] = 0.;
                return;
        }
                XYZ[0] = XYZ[1] = XYZ[2] = 0.;
                return;
        }
@@ -891,21 +1022,24 @@ pix32toXYZ(uint32 p, float XYZ[3])
        x = 9.*u * s;
        y = 4.*v * s;
                                        /* convert to XYZ */
        x = 9.*u * s;
        y = 4.*v * s;
                                        /* convert to XYZ */
-       XYZ[0] = x/y * L;
-       XYZ[1] = L;
-       XYZ[2] = (1.-x-y)/y * L;
+       XYZ[0] = (float)(x/y * L);
+       XYZ[1] = (float)L;
+       XYZ[2] = (float)((1.-x-y)/y * L);
 }
 
 }
 
-static uint32
-pix32fromXYZ(float XYZ[3])
+#if !LOGLUV_PUBLIC
+static
+#endif
+uint32
+LogLuv32fromXYZ(float XYZ[3], int em)
 {
        unsigned int    Le, ue, ve;
        double  u, v, s;
                                        /* encode luminance */
 {
        unsigned int    Le, ue, ve;
        double  u, v, s;
                                        /* encode luminance */
-       Le = (unsigned int)pix16fromY(XYZ[1]);
+       Le = (unsigned int)LogL16fromY(XYZ[1], em);
                                        /* encode color */
        s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
                                        /* encode color */
        s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2];
-       if (s == 0.) {
+       if (!Le || s <= 0.) {
                u = U_NEU;
                v = V_NEU;
        } else {
                u = U_NEU;
                v = V_NEU;
        } else {
@@ -913,10 +1047,10 @@ pix32fromXYZ(float XYZ[3])
                v = 9.*XYZ[1] / s;
        }
        if (u <= 0.) ue = 0;
                v = 9.*XYZ[1] / s;
        }
        if (u <= 0.) ue = 0;
-       else ue = UVSCALE * u;
+       else ue = itrunc(UVSCALE*u, em);
        if (ue > 255) ue = 255;
        if (v <= 0.) ve = 0;
        if (ue > 255) ue = 255;
        if (v <= 0.) ve = 0;
-       else ve = UVSCALE * v;
+       else ve = itrunc(UVSCALE*v, em);
        if (ve > 255) ve = 255;
                                        /* combine encodings */
        return (Le << 16 | ue << 8 | ve);
        if (ve > 255) ve = 255;
                                        /* combine encodings */
        return (Le << 16 | ue << 8 | ve);
@@ -929,7 +1063,7 @@ Luv32toXYZ(LogLuvState* sp, tidata_t op, int n)
        float* xyz = (float*) op;
 
        while (n-- > 0) {
        float* xyz = (float*) op;
 
        while (n-- > 0) {
-               pix32toXYZ(*luv++, xyz);
+               LogLuv32toXYZ(*luv++, xyz);
                xyz += 3;
        }
 }
                xyz += 3;
        }
 }
@@ -943,11 +1077,11 @@ Luv32toLuv48(LogLuvState* sp, tidata_t op, int n)
        while (n-- > 0) {
                double u, v;
 
        while (n-- > 0) {
                double u, v;
 
-               *luv3++ = *luv >> 16;
+               *luv3++ = (int16)(*luv >> 16);
                u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5);
                v = 1./UVSCALE * ((*luv & 0xff) + .5);
                u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5);
                v = 1./UVSCALE * ((*luv & 0xff) + .5);
-               *luv3++ = u * (1L<<15);
-               *luv3++ = v * (1L<<15);
+               *luv3++ = (int16)(u * (1L<<15));
+               *luv3++ = (int16)(v * (1L<<15));
                luv++;
        }
 }
                luv++;
        }
 }
@@ -961,7 +1095,7 @@ Luv32toRGB(LogLuvState* sp, tidata_t op, int n)
        while (n-- > 0) {
                float xyz[3];
 
        while (n-- > 0) {
                float xyz[3];
 
-               pix32toXYZ(*luv++, xyz);
+               LogLuv32toXYZ(*luv++, xyz);
                XYZtoRGB24(xyz, rgb);
                rgb += 3;
        }
                XYZtoRGB24(xyz, rgb);
                rgb += 3;
        }
@@ -974,7 +1108,7 @@ Luv32fromXYZ(LogLuvState* sp, tidata_t op, int n)
        float* xyz = (float*) op;
 
        while (n-- > 0) {
        float* xyz = (float*) op;
 
        while (n-- > 0) {
-               *luv++ = pix32fromXYZ(xyz);
+               *luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth);
                xyz += 3;
        }
 }
                xyz += 3;
        }
 }
@@ -985,10 +1119,19 @@ Luv32fromLuv48(LogLuvState* sp, tidata_t op, int n)
        uint32* luv = (uint32*) sp->tbuf;
        int16* luv3 = (int16*) op;
 
        uint32* luv = (uint32*) sp->tbuf;
        int16* luv3 = (int16*) op;
 
+       if (sp->encode_meth == SGILOGENCODE_NODITHER) {
+               while (n-- > 0) {
+                       *luv++ = (uint32)luv3[0] << 16 |
+                               (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
+                               (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
+                       luv3 += 3;
+               }
+               return;
+       }
        while (n-- > 0) {
                *luv++ = (uint32)luv3[0] << 16 |
        while (n-- > 0) {
                *luv++ = (uint32)luv3[0] << 16 |
-                       (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) |
-                       (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff);
+       (itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
+               (itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
                luv3 += 3;
        }
 }
                luv3 += 3;
        }
 }
@@ -1018,6 +1161,17 @@ LogL16GuessDataFmt(TIFFDirectory *td)
        return (SGILOGDATAFMT_UNKNOWN);
 }
 
        return (SGILOGDATAFMT_UNKNOWN);
 }
 
+static uint32
+multiply(size_t m1, size_t m2)
+{
+       uint32  bytes = m1 * m2;
+
+       if (m1 && bytes / m1 != m2)
+               bytes = 0;
+
+       return bytes;
+}
+
 static int
 LogL16InitState(TIFF* tif)
 {
 static int
 LogL16InitState(TIFF* tif)
 {
@@ -1046,9 +1200,9 @@ LogL16InitState(TIFF* tif)
                    "No support for converting user data format to LogL");
                return (0);
        }
                    "No support for converting user data format to LogL");
                return (0);
        }
-       sp->tbuflen = td->td_imagewidth * td->td_rowsperstrip;
-       sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16));
-       if (sp->tbuf == NULL) {
+       sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
+       if (multiply(sp->tbuflen, sizeof (int16)) == 0 ||
+           (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) {
                TIFFError(module, "%s: No space for SGILog translation buffer",
                    tif->tif_name);
                return (0);
                TIFFError(module, "%s: No space for SGILog translation buffer",
                    tif->tif_name);
                return (0);
@@ -1144,9 +1298,9 @@ LogLuvInitState(TIFF* tif)
                    "No support for converting user data format to LogLuv");
                return (0);
        }
                    "No support for converting user data format to LogLuv");
                return (0);
        }
-       sp->tbuflen = td->td_imagewidth * td->td_rowsperstrip;
-       sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32));
-       if (sp->tbuf == NULL) {
+       sp->tbuflen = multiply(td->td_imagewidth, td->td_rowsperstrip);
+       if (multiply(sp->tbuflen, sizeof (uint32)) == 0 ||
+           (sp->tbuf = (tidata_t*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) {
                TIFFError(module, "%s: No space for SGILog translation buffer",
                    tif->tif_name);
                return (0);
                TIFFError(module, "%s: No space for SGILog translation buffer",
                    tif->tif_name);
                return (0);
@@ -1338,6 +1492,7 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
                        break;
                case SGILOGDATAFMT_RAW:
                        bps = 32, fmt = SAMPLEFORMAT_UINT;
                        break;
                case SGILOGDATAFMT_RAW:
                        bps = 32, fmt = SAMPLEFORMAT_UINT;
+                       TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
                        break;
                case SGILOGDATAFMT_8BIT:
                        bps = 8, fmt = SAMPLEFORMAT_UINT;
                        break;
                case SGILOGDATAFMT_8BIT:
                        bps = 8, fmt = SAMPLEFORMAT_UINT;
@@ -1356,6 +1511,16 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, va_list ap)
                tif->tif_tilesize = TIFFTileSize(tif);
                tif->tif_scanlinesize = TIFFScanlineSize(tif);
                return (1);
                tif->tif_tilesize = TIFFTileSize(tif);
                tif->tif_scanlinesize = TIFFScanlineSize(tif);
                return (1);
+       case TIFFTAG_SGILOGENCODE:
+               sp->encode_meth = va_arg(ap, int);
+               if (sp->encode_meth != SGILOGENCODE_NODITHER &&
+                               sp->encode_meth != SGILOGENCODE_RANDITHER) {
+                       TIFFError(tif->tif_name,
+                               "Unknown encoding %d for LogLuv compression",
+                               sp->encode_meth);
+                       return (0);
+               }
+               return (1);
        default:
                return (*sp->vsetparent)(tif, tag, ap);
        }
        default:
                return (*sp->vsetparent)(tif, tag, ap);
        }
@@ -1377,7 +1542,9 @@ LogLuvVGetField(TIFF* tif, ttag_t tag, va_list ap)
 
 static const TIFFFieldInfo LogLuvFieldInfo[] = {
     { TIFFTAG_SGILOGDATAFMT,     0, 0, TIFF_SHORT,     FIELD_PSEUDO,
 
 static const TIFFFieldInfo LogLuvFieldInfo[] = {
     { TIFFTAG_SGILOGDATAFMT,     0, 0, TIFF_SHORT,     FIELD_PSEUDO,
-      TRUE,    FALSE,  "SGILogDataFmt"}
+      TRUE,    FALSE,  "SGILogDataFmt"},
+    { TIFFTAG_SGILOGENCODE,      0, 0, TIFF_SHORT,     FIELD_PSEUDO,
+      TRUE,    FALSE,  "SGILogEncode"}
 };
 
 int
 };
 
 int
@@ -1395,8 +1562,10 @@ TIFFInitSGILog(TIFF* tif, int scheme)
        if (tif->tif_data == NULL)
                goto bad;
        sp = (LogLuvState*) tif->tif_data;
        if (tif->tif_data == NULL)
                goto bad;
        sp = (LogLuvState*) tif->tif_data;
-       memset(sp, 0, sizeof (*sp));
+       _TIFFmemset((tdata_t)sp, 0, sizeof (*sp));
        sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
        sp->user_datafmt = SGILOGDATAFMT_UNKNOWN;
+       sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ?
+                               SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER;
        sp->tfunc = _logLuvNop;
 
        /*
        sp->tfunc = _logLuvNop;
 
        /*
@@ -1415,10 +1584,10 @@ TIFFInitSGILog(TIFF* tif, int scheme)
 
        /* override SetField so we can handle our private pseudo-tag */
        _TIFFMergeFieldInfo(tif, LogLuvFieldInfo, N(LogLuvFieldInfo));
 
        /* override SetField so we can handle our private pseudo-tag */
        _TIFFMergeFieldInfo(tif, LogLuvFieldInfo, N(LogLuvFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = LogLuvVGetField;   /* hook for codec tags */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = LogLuvVSetField;   /* hook for codec tags */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield = LogLuvVGetField;   /* hook for codec tags */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield = LogLuvVSetField;   /* hook for codec tags */
 
        return (1);
 bad:
 
        return (1);
 bad:
index 16c2b7422f0a719c82886263f258a08f6ea53ee2..9909ee43aa67e518cbd6c8452f8929ffa7b38d3a 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  *
  * The original Berkeley copyright notice appears below in its entirety.
  */
  *
  * The original Berkeley copyright notice appears below in its entirety.
  */
-/* Watcom C++ (or its make utility) doesn't like long filenames */
-#ifdef wxUSE_SHORTNAMES
-#include "tif_pred.h"
-#else
 #include "tif_predict.h"
 #include "tif_predict.h"
-#endif
 
 #include <assert.h>
 #include <stdio.h>
 
 #include <assert.h>
 #include <stdio.h>
@@ -110,6 +105,11 @@ typedef    struct {
 #define        lzw_nextdata    base.nextdata
 #define        lzw_nextbits    base.nextbits
 
 #define        lzw_nextdata    base.nextdata
 #define        lzw_nextbits    base.nextbits
 
+/*
+ * Encoding-specific state.
+ */
+typedef uint16 hcode_t;                        /* codes fit in 16 bits */
+
 /*
  * Decoding-specific state.
  */
 /*
  * Decoding-specific state.
  */
@@ -120,10 +120,12 @@ typedef struct code_ent {
        u_char  firstchar;              /* first token of string */
 } code_t;
 
        u_char  firstchar;              /* first token of string */
 } code_t;
 
-typedef        int (LINKAGEMODE *decodeFunc)(TIFF*, tidata_t, tsize_t, tsample_t);
+typedef        int (*decodeFunc)(TIFF*, tidata_t, tsize_t, tsample_t);
 
 typedef struct {
        LZWBaseState base;
 
 typedef struct {
        LZWBaseState base;
+
+        /* Decoding specific data */
        long    dec_nbitsmask;          /* lzw_nbits 1 bits, right adjusted */
        long    dec_restart;            /* restart count */
 #ifdef LZW_CHECKEOS
        long    dec_nbitsmask;          /* lzw_nbits 1 bits, right adjusted */
        long    dec_restart;            /* restart count */
 #ifdef LZW_CHECKEOS
@@ -135,38 +137,15 @@ typedef struct {
        code_t* dec_free_entp;          /* next free entry */
        code_t* dec_maxcodep;           /* max available entry */
        code_t* dec_codetab;            /* kept separate for small machines */
        code_t* dec_free_entp;          /* next free entry */
        code_t* dec_maxcodep;           /* max available entry */
        code_t* dec_codetab;            /* kept separate for small machines */
-} LZWDecodeState;
-
-/*
- * Encoding-specific state.
- */
-typedef uint16 hcode_t;                        /* codes fit in 16 bits */
-typedef struct {
-       long    hash;
-       hcode_t code;
-} hash_t;
-
-typedef struct {
-       LZWBaseState base;
-       int     enc_oldcode;            /* last code encountered */
-       long    enc_checkpoint;         /* point at which to clear table */
-#define CHECK_GAP      10000           /* enc_ratio check interval */
-       long    enc_ratio;              /* current compression ratio */
-       long    enc_incount;            /* (input) data bytes encoded */
-       long    enc_outcount;           /* encoded (output) bytes */
-       tidata_t enc_rawlimit;          /* bound on tif_rawdata buffer */
-       hash_t* enc_hashtab;            /* kept separate for small machines */
-} LZWEncodeState;
+} LZWCodecState;
 
 #define        LZWState(tif)           ((LZWBaseState*) (tif)->tif_data)
 
 #define        LZWState(tif)           ((LZWBaseState*) (tif)->tif_data)
-#define        DecoderState(tif)       ((LZWDecodeState*) LZWState(tif))
-#define        EncoderState(tif)       ((LZWEncodeState*) LZWState(tif))
+#define        DecoderState(tif)       ((LZWCodecState*) LZWState(tif))
 
 
-static int LINKAGEMODE LZWDecode(TIFF*, tidata_t, tsize_t, tsample_t);
+static int LZWDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 #ifdef LZW_COMPAT
 #ifdef LZW_COMPAT
-static int LINKAGEMODE LZWDecodeCompat(TIFF*, tidata_t, tsize_t, tsample_t);
+static int LZWDecodeCompat(TIFF*, tidata_t, tsize_t, tsample_t);
 #endif
 #endif
-static void cl_hash(LZWEncodeState*);
 
 /*
  * LZW Decoder.
 
 /*
  * LZW Decoder.
@@ -195,11 +174,12 @@ static    void cl_hash(LZWEncodeState*);
 static int
 LZWSetupDecode(TIFF* tif)
 {
 static int
 LZWSetupDecode(TIFF* tif)
 {
-       LZWDecodeState* sp = DecoderState(tif);
-       static const char module[] = " LZWSetupDecode";
+       LZWCodecState* sp = DecoderState(tif);
+       static const char module[] = "LZWSetupDecode";
        int code;
 
        assert(sp != NULL);
        int code;
 
        assert(sp != NULL);
+
        if (sp->dec_codetab == NULL) {
                sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t));
                if (sp->dec_codetab == NULL) {
        if (sp->dec_codetab == NULL) {
                sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t));
                if (sp->dec_codetab == NULL) {
@@ -209,12 +189,13 @@ LZWSetupDecode(TIFF* tif)
                /*
                 * Pre-load the table.
                 */
                /*
                 * Pre-load the table.
                 */
-               for (code = 255; code >= 0; code--) {
-                       sp->dec_codetab[code].value = code;
-                       sp->dec_codetab[code].firstchar = code;
-                       sp->dec_codetab[code].length = 1;
-                       sp->dec_codetab[code].next = NULL;
-               }
+                code = 255;
+                do {
+                    sp->dec_codetab[code].value = (u_char) code;
+                    sp->dec_codetab[code].firstchar = (u_char) code;
+                    sp->dec_codetab[code].length = 1;
+                    sp->dec_codetab[code].next = NULL;
+                } while (code--);
        }
        return (1);
 }
        }
        return (1);
 }
@@ -225,7 +206,7 @@ LZWSetupDecode(TIFF* tif)
 static int
 LZWPreDecode(TIFF* tif, tsample_t s)
 {
 static int
 LZWPreDecode(TIFF* tif, tsample_t s)
 {
-       LZWDecodeState *sp = DecoderState(tif);
+       LZWCodecState *sp = DecoderState(tif);
 
        (void) s;
        assert(sp != NULL);
 
        (void) s;
        assert(sp != NULL);
@@ -316,7 +297,7 @@ codeLoop(TIFF* tif)
 static int
 LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
 {
 static int
 LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
 {
-       LZWDecodeState *sp = DecoderState(tif);
+       LZWCodecState *sp = DecoderState(tif);
        char *op = (char*) op0;
        long occ = (long) occ0;
        char *tp;
        char *op = (char*) op0;
        long occ = (long) occ0;
        char *tp;
@@ -366,7 +347,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                        --tp;
                        t = codep->value;
                        codep = codep->next;
                        --tp;
                        t = codep->value;
                        codep = codep->next;
-                       *tp = t;
+                       *tp = (char) t;
                } while (--residue && codep);
                sp->dec_restart = 0;
        }
                } while (--residue && codep);
                sp->dec_restart = 0;
        }
@@ -392,7 +373,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                        NextCode(tif, sp, bp, code, GetNextCode);
                        if (code == CODE_EOI)
                                break;
                        NextCode(tif, sp, bp, code, GetNextCode);
                        if (code == CODE_EOI)
                                break;
-                       *op++ = code, occ--;
+                       *op++ = (char)code, occ--;
                        oldcodep = sp->dec_codetab + code;
                        continue;
                }
                        oldcodep = sp->dec_codetab + code;
                        continue;
                }
@@ -401,8 +382,22 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                /*
                 * Add the new entry to the code table.
                 */
                /*
                 * Add the new entry to the code table.
                 */
-               assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]);
+               if (free_entp < &sp->dec_codetab[0] ||
+                       free_entp >= &sp->dec_codetab[CSIZE]) {
+                       TIFFError(tif->tif_name,
+                       "LZWDecode: Corrupted LZW table at scanline %d",
+                       tif->tif_row);
+                       return (0);
+               }
+
                free_entp->next = oldcodep;
                free_entp->next = oldcodep;
+               if (free_entp->next < &sp->dec_codetab[0] ||
+                       free_entp->next >= &sp->dec_codetab[CSIZE]) {
+                       TIFFError(tif->tif_name,
+                       "LZWDecode: Corrupted LZW table at scanline %d",
+                       tif->tif_row);
+                       return (0);
+               }
                free_entp->firstchar = free_entp->next->firstchar;
                free_entp->length = free_entp->next->length+1;
                free_entp->value = (codep < free_entp) ?
                free_entp->firstchar = free_entp->next->firstchar;
                free_entp->length = free_entp->next->length+1;
                free_entp->value = (codep < free_entp) ?
@@ -419,6 +414,13 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                         * Code maps to a string, copy string
                         * value to output (written in reverse).
                         */
                         * Code maps to a string, copy string
                         * value to output (written in reverse).
                         */
+                       if(codep->length == 0) {
+                           TIFFError(tif->tif_name,
+                           "LZWDecode: Wrong length of decoded string: "
+                           "data probably corrupted at scanline %d",
+                           tif->tif_row);      
+                           return (0);
+                       }
                        if (codep->length > occ) {
                                /*
                                 * String is too long for decode buffer,
                        if (codep->length > occ) {
                                /*
                                 * String is too long for decode buffer,
@@ -449,7 +451,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                                --tp;
                                t = codep->value;
                                codep = codep->next;
                                --tp;
                                t = codep->value;
                                codep = codep->next;
-                               *tp = t;
+                               *tp = (char) t;
                        } while (codep && tp > op);
                        if (codep) {
                            codeLoop(tif);
                        } while (codep && tp > op);
                        if (codep) {
                            codeLoop(tif);
@@ -457,7 +459,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                        }
                        op += len, occ -= len;
                } else
                        }
                        op += len, occ -= len;
                } else
-                       *op++ = code, occ--;
+                       *op++ = (char)code, occ--;
        }
 
        tif->tif_rawcp = (tidata_t) bp;
        }
 
        tif->tif_rawcp = (tidata_t) bp;
@@ -494,10 +496,10 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
        nextbits -= nbits;                                      \
 }
 
        nextbits -= nbits;                                      \
 }
 
-static int LINKAGEMODE
+static int
 LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
 {
 LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
 {
-       LZWDecodeState *sp = DecoderState(tif);
+       LZWCodecState *sp = DecoderState(tif);
        char *op = (char*) op0;
        long occ = (long) occ0;
        char *tp;
        char *op = (char*) op0;
        long occ = (long) occ0;
        char *tp;
@@ -567,7 +569,7 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                        NextCode(tif, sp, bp, code, GetNextCodeCompat);
                        if (code == CODE_EOI)
                                break;
                        NextCode(tif, sp, bp, code, GetNextCodeCompat);
                        if (code == CODE_EOI)
                                break;
-                       *op++ = code, occ--;
+                       *op++ = (char) code, occ--;
                        oldcodep = sp->dec_codetab + code;
                        continue;
                }
                        oldcodep = sp->dec_codetab + code;
                        continue;
                }
@@ -576,8 +578,22 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                /*
                 * Add the new entry to the code table.
                 */
                /*
                 * Add the new entry to the code table.
                 */
-               assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]);
+               if (free_entp < &sp->dec_codetab[0] ||
+                       free_entp >= &sp->dec_codetab[CSIZE]) {
+                       TIFFError(tif->tif_name,
+                       "LZWDecodeCompat: Corrupted LZW table at scanline %d",
+                       tif->tif_row);
+                       return (0);
+               }
+
                free_entp->next = oldcodep;
                free_entp->next = oldcodep;
+               if (free_entp->next < &sp->dec_codetab[0] ||
+                       free_entp->next >= &sp->dec_codetab[CSIZE]) {
+                       TIFFError(tif->tif_name,
+                       "LZWDecodeCompat: Corrupted LZW table at scanline %d",
+                       tif->tif_row);
+                       return (0);
+               }
                free_entp->firstchar = free_entp->next->firstchar;
                free_entp->length = free_entp->next->length+1;
                free_entp->value = (codep < free_entp) ?
                free_entp->firstchar = free_entp->next->firstchar;
                free_entp->length = free_entp->next->length+1;
                free_entp->value = (codep < free_entp) ?
@@ -594,6 +610,13 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                         * Code maps to a string, copy string
                         * value to output (written in reverse).
                         */
                         * Code maps to a string, copy string
                         * value to output (written in reverse).
                         */
+                       if(codep->length == 0) {
+                           TIFFError(tif->tif_name,
+                           "LZWDecodeCompat: Wrong length of decoded "
+                           "string: data probably corrupted at scanline %d",
+                           tif->tif_row);      
+                           return (0);
+                       }
                        if (codep->length > occ) {
                                /*
                                 * String is too long for decode buffer,
                        if (codep->length > occ) {
                                /*
                                 * String is too long for decode buffer,
@@ -619,11 +642,11 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
                                *--tp = codep->value;
                        } while( (codep = codep->next) != NULL);
                } else
                                *--tp = codep->value;
                        } while( (codep = codep->next) != NULL);
                } else
-                       *op++ = code, occ--;
+                       *op++ = (char) code, occ--;
        }
 
        tif->tif_rawcp = (tidata_t) bp;
        }
 
        tif->tif_rawcp = (tidata_t) bp;
-       sp->lzw_nbits = nbits;
+       sp->lzw_nbits = (u_short) nbits;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
        sp->dec_nbitsmask = nbitsmask;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
        sp->dec_nbitsmask = nbitsmask;
@@ -641,355 +664,59 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
 }
 #endif /* LZW_COMPAT */
 
 }
 #endif /* LZW_COMPAT */
 
-/*
- * LZW Encoding.
- */
-
-static int
-LZWSetupEncode(TIFF* tif)
-{
-       LZWEncodeState* sp = EncoderState(tif);
-       static const char module[] = "LZWSetupEncode";
-
-       assert(sp != NULL);
-       sp->enc_hashtab = (hash_t*) _TIFFmalloc(HSIZE*sizeof (hash_t));
-       if (sp->enc_hashtab == NULL) {
-               TIFFError(module, "No space for LZW hash table");
-               return (0);
-       }
-       return (1);
-}
-
-/*
- * Reset encoding state at the start of a strip.
- */
-static int
-LZWPreEncode(TIFF* tif, tsample_t s)
-{
-       LZWEncodeState *sp = EncoderState(tif);
-
-       (void) s;
-       assert(sp != NULL);
-       sp->lzw_nbits = BITS_MIN;
-       sp->lzw_maxcode = MAXCODE(BITS_MIN);
-       sp->lzw_free_ent = CODE_FIRST;
-       sp->lzw_nextbits = 0;
-       sp->lzw_nextdata = 0;
-       sp->enc_checkpoint = CHECK_GAP;
-       sp->enc_ratio = 0;
-       sp->enc_incount = 0;
-       sp->enc_outcount = 0;
-       /*
-        * The 4 here insures there is space for 2 max-sized
-        * codes in LZWEncode and LZWPostDecode.
-        */
-       sp->enc_rawlimit = tif->tif_rawdata + tif->tif_rawdatasize-1 - 4;
-       cl_hash(sp);            /* clear hash table */
-       sp->enc_oldcode = (hcode_t) -1; /* generates CODE_CLEAR in LZWEncode */
-       return (1);
-}
 
 
-#define        CALCRATIO(sp, rat) {                                    \
-       if (incount > 0x007fffff) { /* NB: shift will overflow */\
-               rat = outcount >> 8;                            \
-               rat = (rat == 0 ? 0x7fffffff : incount/rat);    \
-       } else                                                  \
-               rat = (incount<<8) / outcount;                  \
-}
-#define        PutNextCode(op, c) {                                    \
-       nextdata = (nextdata << nbits) | c;                     \
-       nextbits += nbits;                                      \
-       *op++ = (u_char)(nextdata >> (nextbits-8));             \
-       nextbits -= 8;                                          \
-       if (nextbits >= 8) {                                    \
-               *op++ = (u_char)(nextdata >> (nextbits-8));     \
-               nextbits -= 8;                                  \
-       }                                                       \
-       outcount += nbits;                                      \
-}
 
 
-/*
- * Encode a chunk of pixels.
- *
- * Uses an open addressing double hashing (no chaining) on the
- * prefix code/next character combination.  We do a variant of
- * Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's
- * relatively-prime secondary probe.  Here, the modular division
- * first probe is gives way to a faster exclusive-or manipulation.
- * Also do block compression with an adaptive reset, whereby the
- * code table is cleared when the compression ratio decreases,
- * but after the table fills.  The variable-length output codes
- * are re-sized at this point, and a CODE_CLEAR is generated
- * for the decoder.
- */
-static int LINKAGEMODE
-LZWEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
-{
-       register LZWEncodeState *sp = EncoderState(tif);
-       register long fcode;
-       register hash_t *hp;
-       register int h, c;
-       hcode_t ent;
-       long disp;
-       long incount, outcount, checkpoint;
-       long nextdata, nextbits;
-       int free_ent, maxcode, nbits;
-       tidata_t op, limit;
-
-       (void) s;
-       if (sp == NULL)
-               return (0);
-       /*
-        * Load local state.
-        */
-       incount = sp->enc_incount;
-       outcount = sp->enc_outcount;
-       checkpoint = sp->enc_checkpoint;
-       nextdata = sp->lzw_nextdata;
-       nextbits = sp->lzw_nextbits;
-       free_ent = sp->lzw_free_ent;
-       maxcode = sp->lzw_maxcode;
-       nbits = sp->lzw_nbits;
-       op = tif->tif_rawcp;
-       limit = sp->enc_rawlimit;
-       ent = sp->enc_oldcode;
-
-       if (ent == (hcode_t) -1 && cc > 0) {
-               /*
-                * NB: This is safe because it can only happen
-                *     at the start of a strip where we know there
-                *     is space in the data buffer.
-                */
-               PutNextCode(op, CODE_CLEAR);
-               ent = *bp++; cc--; incount++;
-       }
-       while (cc > 0) {
-               c = *bp++; cc--; incount++;
-               fcode = ((long)c << BITS_MAX) + ent;
-               h = (c << HSHIFT) ^ ent;        /* xor hashing */
-#ifdef _WINDOWS
-               /*
-                * Check hash index for an overflow.
-                */
-               if (h >= HSIZE)
-                       h -= HSIZE;
-#endif
-               hp = &sp->enc_hashtab[h];
-               if (hp->hash == fcode) {
-                       ent = hp->code;
-                       continue;
-               }
-               if (hp->hash >= 0) {
-                       /*
-                        * Primary hash failed, check secondary hash.
-                        */
-                       disp = HSIZE - h;
-                       if (h == 0)
-                               disp = 1;
-                       do {
-                               /*
-                                * Avoid pointer arithmetic 'cuz of
-                                * wraparound problems with segments.
-                                */
-                               if ((h -= disp) < 0)
-                                       h += HSIZE;
-                               hp = &sp->enc_hashtab[h];
-                               if (hp->hash == fcode) {
-                                       ent = hp->code;
-                                       goto hit;
-                               }
-                       } while (hp->hash >= 0);
-               }
-               /*
-                * New entry, emit code and add to table.
-                */
-               /*
-                * Verify there is space in the buffer for the code
-                * and any potential Clear code that might be emitted
-                * below.  The value of limit is setup so that there
-                * are at least 4 bytes free--room for 2 codes.
-                */
-               if (op > limit) {
-                       tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
-                       TIFFFlushData1(tif);
-                       op = tif->tif_rawdata;
-               }
-               PutNextCode(op, ent);
-               ent = c;
-               hp->code = free_ent++;
-               hp->hash = fcode;
-               if (free_ent == CODE_MAX-1) {
-                       /* table is full, emit clear code and reset */
-                       cl_hash(sp);
-                       sp->enc_ratio = 0;
-                       incount = 0;
-                       outcount = 0;
-                       free_ent = CODE_FIRST;
-                       PutNextCode(op, CODE_CLEAR);
-                       nbits = BITS_MIN;
-                       maxcode = MAXCODE(BITS_MIN);
-               } else {
-                       /*
-                        * If the next entry is going to be too big for
-                        * the code size, then increase it, if possible.
-                        */
-                       if (free_ent > maxcode) {
-                               nbits++;
-                               assert(nbits <= BITS_MAX);
-                               maxcode = (int) MAXCODE(nbits);
-                       } else if (incount >= checkpoint) {
-                               long rat;
-                               /*
-                                * Check compression ratio and, if things seem
-                                * to be slipping, clear the hash table and
-                                * reset state.  The compression ratio is a
-                                * 24+8-bit fractional number.
-                                */
-                               checkpoint = incount+CHECK_GAP;
-                               CALCRATIO(sp, rat);
-                               if (rat <= sp->enc_ratio) {
-                                       cl_hash(sp);
-                                       sp->enc_ratio = 0;
-                                       incount = 0;
-                                       outcount = 0;
-                                       free_ent = CODE_FIRST;
-                                       PutNextCode(op, CODE_CLEAR);
-                                       nbits = BITS_MIN;
-                                       maxcode = MAXCODE(BITS_MIN);
-                               } else
-                                       sp->enc_ratio = rat;
-                       }
-               }
-       hit:
-               ;
-       }
-
-       /*
-        * Restore global state.
-        */
-       sp->enc_incount = incount;
-       sp->enc_outcount = outcount;
-       sp->enc_checkpoint = checkpoint;
-       sp->enc_oldcode = ent;
-       sp->lzw_nextdata = nextdata;
-       sp->lzw_nextbits = nextbits;
-       sp->lzw_free_ent = free_ent;
-       sp->lzw_maxcode = maxcode;
-       sp->lzw_nbits = nbits;
-       tif->tif_rawcp = op;
-       return (1);
-}
-
-/*
- * Finish off an encoded strip by flushing the last
- * string and tacking on an End Of Information code.
- */
-static int
-LZWPostEncode(TIFF* tif)
-{
-       register LZWEncodeState *sp = EncoderState(tif);
-       tidata_t op = tif->tif_rawcp;
-       long nextbits = sp->lzw_nextbits;
-       long nextdata = sp->lzw_nextdata;
-       long outcount = sp->enc_outcount;
-       int nbits = sp->lzw_nbits;
-
-       if (op > sp->enc_rawlimit) {
-               tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
-               TIFFFlushData1(tif);
-               op = tif->tif_rawdata;
-       }
-       if (sp->enc_oldcode != (hcode_t) -1) {
-               PutNextCode(op, sp->enc_oldcode);
-               sp->enc_oldcode = (hcode_t) -1;
-       }
-       PutNextCode(op, CODE_EOI);
-       if (nextbits > 0)
-               *op++ = (u_char)(nextdata << (8-nextbits));
-       tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
-       return (1);
-}
-
-/*
- * Reset encoding hash table.
- */
 static void
 static void
-cl_hash(LZWEncodeState* sp)
+LZWCleanup(TIFF* tif)
 {
 {
-       register hash_t *hp = &sp->enc_hashtab[HSIZE-1];
-       register long i = HSIZE-8;
-
-       do {
-               i -= 8;
-               hp[-7].hash = -1;
-               hp[-6].hash = -1;
-               hp[-5].hash = -1;
-               hp[-4].hash = -1;
-               hp[-3].hash = -1;
-               hp[-2].hash = -1;
-               hp[-1].hash = -1;
-               hp[ 0].hash = -1;
-               hp -= 8;
-       } while (i >= 0);
-       for (i += 8; i > 0; i--, hp--)
-               hp->hash = -1;
+    if (tif->tif_data) {
+        if (DecoderState(tif)->dec_codetab)
+            _TIFFfree(DecoderState(tif)->dec_codetab);
+        _TIFFfree(tif->tif_data);
+        tif->tif_data = NULL;
+    }
 }
 
 }
 
-static void
-LZWCleanup(TIFF* tif)
+static int
+LZWSetupEncode(TIFF* tif)
 {
 {
-       if (tif->tif_data) {
-               if (tif->tif_mode == O_RDONLY) {
-                       if (DecoderState(tif)->dec_codetab)
-                               _TIFFfree(DecoderState(tif)->dec_codetab);
-               } else {
-                       if (EncoderState(tif)->enc_hashtab)
-                               _TIFFfree(EncoderState(tif)->enc_hashtab);
-               }
-               _TIFFfree(tif->tif_data);
-               tif->tif_data = NULL;
-       }
+    TIFFError(tif->tif_name,
+              "LZW compression is not available to due to Unisys patent enforcement");
+    return (0);
 }
 
 int
 TIFFInitLZW(TIFF* tif, int scheme)
 {
        assert(scheme == COMPRESSION_LZW);
 }
 
 int
 TIFFInitLZW(TIFF* tif, int scheme)
 {
        assert(scheme == COMPRESSION_LZW);
+
        /*
         * Allocate state block so tag methods have storage to record values.
         */
        /*
         * Allocate state block so tag methods have storage to record values.
         */
-       if (tif->tif_mode == O_RDONLY) {
-               tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWDecodeState));
-               if (tif->tif_data == NULL)
-                       goto bad;
-               DecoderState(tif)->dec_codetab = NULL;
-               DecoderState(tif)->dec_decode = NULL;
-       } else {
-               tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWEncodeState));
-               if (tif->tif_data == NULL)
-                       goto bad;
-               EncoderState(tif)->enc_hashtab = NULL;
-       }
+       tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWCodecState));
+       if (tif->tif_data == NULL)
+               goto bad;
+       DecoderState(tif)->dec_codetab = NULL;
+       DecoderState(tif)->dec_decode = NULL;
+
        /*
         * Install codec methods.
         */
        /*
         * Install codec methods.
         */
+       tif->tif_setupencode = LZWSetupEncode;
        tif->tif_setupdecode = LZWSetupDecode;
        tif->tif_predecode = LZWPreDecode;
        tif->tif_decoderow = LZWDecode;
        tif->tif_decodestrip = LZWDecode;
        tif->tif_decodetile = LZWDecode;
        tif->tif_setupdecode = LZWSetupDecode;
        tif->tif_predecode = LZWPreDecode;
        tif->tif_decoderow = LZWDecode;
        tif->tif_decodestrip = LZWDecode;
        tif->tif_decodetile = LZWDecode;
-       tif->tif_setupencode = LZWSetupEncode;
-       tif->tif_preencode = LZWPreEncode;
-       tif->tif_postencode = LZWPostEncode;
-       tif->tif_encoderow = LZWEncode;
-       tif->tif_encodestrip = LZWEncode;
-       tif->tif_encodetile = LZWEncode;
        tif->tif_cleanup = LZWCleanup;
        tif->tif_cleanup = LZWCleanup;
+
        /*
         * Setup predictor setup.
         */
        (void) TIFFPredictorInit(tif);
        /*
         * Setup predictor setup.
         */
        (void) TIFFPredictorInit(tif);
+
        return (1);
        return (1);
+
 bad:
        TIFFError("TIFFInitLZW", "No space for LZW state block");
        return (0);
 bad:
        TIFFError("TIFFInitLZW", "No space for LZW state block");
        return (0);
index edd292c522ab160f827e79766e91ee834e3d219a..42d631e07fdade4c379cb4ff909bd4600c8be675 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -34,7 +34,7 @@
 
 #define SETPIXEL(op, v) {                      \
        switch (npixels++ & 3) {                \
 
 #define SETPIXEL(op, v) {                      \
        switch (npixels++ & 3) {                \
-       case 0: op[0]  = (v) << 6; break;       \
+       case 0: op[0]  = (u_char) ((v) << 6); break;    \
        case 1: op[0] |= (v) << 4; break;       \
        case 2: op[0] |= (v) << 2; break;       \
        case 3: *op++ |= (v);      break;       \
        case 1: op[0] |= (v) << 4; break;       \
        case 2: op[0] |= (v) << 2; break;       \
        case 3: *op++ |= (v);      break;       \
@@ -45,7 +45,7 @@
 #define LITERALSPAN    0x40
 #define WHITE          ((1<<2)-1)
 
 #define LITERALSPAN    0x40
 #define WHITE          ((1<<2)-1)
 
-static int LINKAGEMODE
+static int
 NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        register u_char *bp, *op;
 NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        register u_char *bp, *op;
@@ -87,7 +87,7 @@ NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                         */
                        off = (bp[0] * 256) + bp[1];
                        n = (bp[2] * 256) + bp[3];
                         */
                        off = (bp[0] * 256) + bp[1];
                        n = (bp[2] * 256) + bp[3];
-                       if (cc < 4+n)
+                       if (cc < 4+n || off+n > scanline)
                                goto bad;
                        _TIFFmemcpy(row+off, bp+4, n);
                        bp += 4+n;
                                goto bad;
                        _TIFFmemcpy(row+off, bp+4, n);
                        bp += 4+n;
@@ -111,7 +111,7 @@ NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
                                n &= 0x3f;
                                while (n-- > 0)
                                        SETPIXEL(op, grey);
                                n &= 0x3f;
                                while (n-- > 0)
                                        SETPIXEL(op, grey);
-                               if (npixels >= imagewidth)
+                               if (npixels >= (int) imagewidth)
                                        break;
                                if (cc == 0)
                                        goto bad;
                                        break;
                                if (cc == 0)
                                        goto bad;
index 5b0e4983a9d40eed20949ec2261edda9e6e96c0a..8273e561323682720b74aa271c6842337a4ff4d8 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  */
 #include "tiffiop.h"
 
  */
 #include "tiffiop.h"
 
-void LINKAGEMODE _TIFFSetDefaultCompressionState(TIFF* tif);
+void _TIFFSetDefaultCompressionState(TIFF* tif);
 
 static const long typemask[13] = {
 
 static const long typemask[13] = {
-       0L,             /* TIFF_NOTYPE */
-       0x000000ffL,    /* TIFF_BYTE */
-       0xffffffffL,    /* TIFF_ASCII */
-       0x0000ffffL,    /* TIFF_SHORT */
-       0xffffffffL,    /* TIFF_LONG */
-       0xffffffffL,    /* TIFF_RATIONAL */
-       0x000000ffL,    /* TIFF_SBYTE */
-       0x000000ffL,    /* TIFF_UNDEFINED */
-       0x0000ffffL,    /* TIFF_SSHORT */
-       0xffffffffL,    /* TIFF_SLONG */
-       0xffffffffL,    /* TIFF_SRATIONAL */
-       0xffffffffL,    /* TIFF_FLOAT */
-       0xffffffffL,    /* TIFF_DOUBLE */
+       (long)0L,               /* TIFF_NOTYPE */
+       (long)0x000000ffL,      /* TIFF_BYTE */
+       (long)0xffffffffL,      /* TIFF_ASCII */
+       (long)0x0000ffffL,      /* TIFF_SHORT */
+       (long)0xffffffffL,      /* TIFF_LONG */
+       (long)0xffffffffL,      /* TIFF_RATIONAL */
+       (long)0x000000ffL,      /* TIFF_SBYTE */
+       (long)0x000000ffL,      /* TIFF_UNDEFINED */
+       (long)0x0000ffffL,      /* TIFF_SSHORT */
+       (long)0xffffffffL,      /* TIFF_SLONG */
+       (long)0xffffffffL,      /* TIFF_SRATIONAL */
+       (long)0xffffffffL,      /* TIFF_FLOAT */
+       (long)0xffffffffL,      /* TIFF_DOUBLE */
 };
 static const int bigTypeshift[13] = {
        0,              /* TIFF_NOTYPE */
 };
 static const int bigTypeshift[13] = {
        0,              /* TIFF_NOTYPE */
@@ -156,6 +156,11 @@ TIFFClientOpen(
        tif->tif_curstrip = (tstrip_t) -1;      /* invalid strip */
        tif->tif_row = (uint32) -1;             /* read/write pre-increment */
        tif->tif_clientdata = clientdata;
        tif->tif_curstrip = (tstrip_t) -1;      /* invalid strip */
        tif->tif_row = (uint32) -1;             /* read/write pre-increment */
        tif->tif_clientdata = clientdata;
+       if (!readproc || !writeproc || !seekproc || !closeproc
+                       || !sizeproc || !mapproc || !unmapproc) {
+               TIFFError(module, "One of the client procedures are NULL pointer");
+               goto bad3;
+       }
        tif->tif_readproc = readproc;
        tif->tif_writeproc = writeproc;
        tif->tif_seekproc = seekproc;
        tif->tif_readproc = readproc;
        tif->tif_writeproc = writeproc;
        tif->tif_seekproc = seekproc;
@@ -170,11 +175,12 @@ TIFFClientOpen(
         * a file is opened read-only.
         */
        tif->tif_flags = FILLORDER_MSB2LSB;
         * a file is opened read-only.
         */
        tif->tif_flags = FILLORDER_MSB2LSB;
-       if (m == O_RDONLY)
+       if (m == O_RDONLY )
+            tif->tif_flags |= TIFF_MAPPED;
+
 #ifdef STRIPCHOP_DEFAULT
 #ifdef STRIPCHOP_DEFAULT
-               tif->tif_flags |= TIFF_MAPPED|STRIPCHOP_DEFAULT;
-#else
-               tif->tif_flags |= TIFF_MAPPED;
+       if (m == O_RDONLY || m == O_RDWR)
+               tif->tif_flags |= STRIPCHOP_DEFAULT;
 #endif
 
        { union { int32 i; char c[4]; } u; u.i = 1; bigendian = u.c[0] == 0; }
 #endif
 
        { union { int32 i; char c[4]; } u; u.i = 1; bigendian = u.c[0] == 0; }
@@ -284,6 +290,15 @@ TIFFClientOpen(
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&tif->tif_header.tiff_version);
                tif->tif_header.tiff_diroff = 0;        /* filled in later */
                if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabShort(&tif->tif_header.tiff_version);
                tif->tif_header.tiff_diroff = 0;        /* filled in later */
+
+                /*
+                 * This seek shouldn't be necessary, but I have had some
+                 * crazy problems with a failed fseek() on Solaris leaving
+                 * the current file pointer out of whack when an fwrite()
+                 * is done. 
+                 */
+                TIFFSeekFile( tif, 0, SEEK_SET );
+
                if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
                        TIFFError(name, "Error writing TIFF header");
                        goto bad;
                if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
                        TIFFError(name, "Error writing TIFF header");
                        goto bad;
@@ -298,6 +313,8 @@ TIFFClientOpen(
                if (!TIFFDefaultDirectory(tif))
                        goto bad;
                tif->tif_diroff = 0;
                if (!TIFFDefaultDirectory(tif))
                        goto bad;
                tif->tif_diroff = 0;
+               tif->tif_dirlist = NULL;
+               tif->tif_dirnumber = 0;
                return (tif);
        }
        /*
                return (tif);
        }
        /*
@@ -327,7 +344,7 @@ TIFFClientOpen(
                TIFFError(name,
                    "Not a TIFF file, bad version number %d (0x%x)",
                    tif->tif_header.tiff_version,
                TIFFError(name,
                    "Not a TIFF file, bad version number %d (0x%x)",
                    tif->tif_header.tiff_version,
-                   tif->tif_header.tiff_version);
+                   tif->tif_header.tiff_version); 
                goto bad;
        }
        tif->tif_flags |= TIFF_MYBUFFER;
                goto bad;
        }
        tif->tif_flags |= TIFF_MYBUFFER;
@@ -369,6 +386,7 @@ bad:
        return ((TIFF*)0);
 bad2:
        (void) (*closeproc)(clientdata);
        return ((TIFF*)0);
 bad2:
        (void) (*closeproc)(clientdata);
+bad3:
        return ((TIFF*)0);
 }
 
        return ((TIFF*)0);
 }
 
index 6d80d0330314b9aa763e62b1c1432346c8076ca9..63a03d14b8df36a7e98f3b40834cfc45db93901b 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -58,7 +58,7 @@ typedef unsigned char tidata;
 /*
  * Encode a run of pixels.
  */
 /*
  * Encode a run of pixels.
  */
-static int LINKAGEMODE
+static int
 PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        u_char* bp = (u_char*) buf;
 PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
 {
        u_char* bp = (u_char*) buf;
@@ -109,16 +109,16 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
                                state = RUN;
                                if (n > 128) {
                                        *op++ = (tidata) -127;
                                state = RUN;
                                if (n > 128) {
                                        *op++ = (tidata) -127;
-                                       *op++ = b;
+                                       *op++ = (tidataval_t) b;
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                        } else {
                                lastliteral = op;
                                *op++ = 0;
                        } else {
                                lastliteral = op;
                                *op++ = 0;
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                                state = LITERAL;
                        }
                        break;
                                state = LITERAL;
                        }
                        break;
@@ -127,32 +127,32 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
                                state = LITERAL_RUN;
                                if (n > 128) {
                                        *op++ = (tidata) -127;
                                state = LITERAL_RUN;
                                if (n > 128) {
                                        *op++ = (tidata) -127;
-                                       *op++ = b;
+                                       *op++ = (tidataval_t) b;
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));  /* encode run */
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));  /* encode run */
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                        } else {                        /* extend literal */
                                if (++(*lastliteral) == 127)
                                        state = BASE;
                        } else {                        /* extend literal */
                                if (++(*lastliteral) == 127)
                                        state = BASE;
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                        }
                        break;
                case RUN:               /* last object was run */
                        if (n > 1) {
                                if (n > 128) {
                                        *op++ = (tidata) -127;
                        }
                        break;
                case RUN:               /* last object was run */
                        if (n > 1) {
                                if (n > 128) {
                                        *op++ = (tidata) -127;
-                                       *op++ = b;
+                                       *op++ = (tidataval_t) b;
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));
                                        n -= 128;
                                        goto again;
                                }
                                *op++ = (tidataval_t)(-(n-1));
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                        } else {
                                lastliteral = op;
                                *op++ = 0;
                        } else {
                                lastliteral = op;
                                *op++ = 0;
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                                state = LITERAL;
                        }
                        break;
                                state = LITERAL;
                        }
                        break;
@@ -185,22 +185,46 @@ PackBitsEncode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
  * the decoder if data is read, for example, by scanlines
  * when it was encoded by strips.
  */
  * the decoder if data is read, for example, by scanlines
  * when it was encoded by strips.
  */
-static int LINKAGEMODE
+static int
 PackBitsEncodeChunk(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
 PackBitsEncodeChunk(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
 {
+#if defined(__hpux) && defined(__LP64__)
+       tsize_t rowsize = (tsize_t)(unsigned long) tif->tif_data;
+#else
        tsize_t rowsize = (tsize_t) tif->tif_data;
        tsize_t rowsize = (tsize_t) tif->tif_data;
+#endif
 
        assert(rowsize > 0);
 
        assert(rowsize > 0);
+    
+#ifdef YCBCR_SUPPORT
+       /* 
+        * YCBCR data isn't really separable into rows, so we
+        * might as well encode the whole tile/strip as one chunk.
+        */
+       if( tif->tif_dir.td_photometric == PHOTOMETRIC_YCBCR ) {
+#if defined(__hpux) && defined(__LP64__)
+               rowsize = (tsize_t)(unsigned long) tif->tif_data;
+#else
+               rowsize = (tsize_t) tif->tif_data;
+#endif
+       }
+#endif
+
        while ((long)cc > 0) {
        while ((long)cc > 0) {
-               if (PackBitsEncode(tif, bp, rowsize, s) < 0)
-                       return (-1);
-               bp += rowsize;
-               cc -= rowsize;
+               int     chunk = rowsize;
+               
+               if( cc < chunk )
+                   chunk = cc;
+
+               if (PackBitsEncode(tif, bp, chunk, s) < 0)
+                   return (-1);
+               bp += chunk;
+               cc -= chunk;
        }
        return (1);
 }
 
        }
        return (1);
 }
 
-static int LINKAGEMODE
+static int
 PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        char *bp;
 PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
 {
        char *bp;
@@ -222,13 +246,29 @@ PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
                if (n < 0) {            /* replicate next byte -n+1 times */
                        if (n == -128)  /* nop */
                                continue;
                if (n < 0) {            /* replicate next byte -n+1 times */
                        if (n == -128)  /* nop */
                                continue;
-                       n = -n + 1;
+                        n = -n + 1;
+                        if( occ < n )
+                        {
+                            TIFFWarning(tif->tif_name,
+                                        "PackBitsDecode: discarding %d bytes "
+                                        "to avoid buffer overrun",
+                                        n - occ);
+                            n = occ;
+                        }
                        occ -= n;
                        b = *bp++, cc--;
                        while (n-- > 0)
                        occ -= n;
                        b = *bp++, cc--;
                        while (n-- > 0)
-                               *op++ = b;
+                               *op++ = (tidataval_t) b;
                } else {                /* copy next n+1 bytes literally */
                } else {                /* copy next n+1 bytes literally */
-                       _TIFFmemcpy(op, bp, ++n);
+                       if (occ < n + 1)
+                        {
+                            TIFFWarning(tif->tif_name,
+                                        "PackBitsDecode: discarding %d bytes "
+                                        "to avoid buffer overrun",
+                                        n - occ + 1);
+                            n = occ - 1;
+                        }
+                        _TIFFmemcpy(op, bp, ++n);
                        op += n; occ -= n;
                        bp += n; cc -= n;
                }
                        op += n; occ -= n;
                        bp += n; cc -= n;
                }
@@ -241,7 +281,6 @@ PackBitsDecode(TIFF* tif, tidata_t op, tsize_t occ, tsample_t s)
                    (long) tif->tif_row);
                return (0);
        }
                    (long) tif->tif_row);
                return (0);
        }
-       /* check for buffer overruns? */
        return (1);
 }
 
        return (1);
 }
 
index 1cf49be8373d71e8da625ceab2088c31cb59a165..a4a162fda87a870a0c4893392e3a2e7f668b87bd 100644 (file)
  * 
  */
 
  * 
  */
 
-/* Watcom C++ (or its make utility) doesn't like long filenames */
-#ifdef __WATCOMC__
-#include "tif_pred.h"
-#else
 #include "tif_predict.h"
 #include "tif_predict.h"
-#endif
-
 #include "zlib.h"
 #include "zlib.h"
-#include "zutil.h"
 
 #include <stdio.h>
 #include <assert.h>
 
 #include <stdio.h>
 #include <assert.h>
@@ -496,8 +489,7 @@ PixarLogMakeTables(PixarLogState *sp)
 
     int  nlin, lt2size;
     int  i, j;
 
     int  nlin, lt2size;
     int  i, j;
-    double  b, c, linstep, max;
-    double  k, v, dv, r, lr2, r2;
+    double  b, c, linstep, v;
     float *ToLinearF;
     uint16 *ToLinear16;
     unsigned char *ToLinear8;
     float *ToLinearF;
     uint16 *ToLinear16;
     unsigned char *ToLinear8;
@@ -506,14 +498,14 @@ PixarLogMakeTables(PixarLogState *sp)
     uint16  *From8;
 
     c = log(RATIO);    
     uint16  *From8;
 
     c = log(RATIO);    
-    nlin = 1./c;       /* nlin must be an integer */
+    nlin = (int)1./c;  /* nlin must be an integer */
     c = 1./nlin;
     b = exp(-c*ONE);   /* multiplicative scale factor [b*exp(c*ONE) = 1] */
     linstep = b*c*exp(1.);
 
     LogK1 = 1./c;      /* if (v >= 2)  token = k1*log(v*k2) */
     LogK2 = 1./b;
     c = 1./nlin;
     b = exp(-c*ONE);   /* multiplicative scale factor [b*exp(c*ONE) = 1] */
     linstep = b*c*exp(1.);
 
     LogK1 = 1./c;      /* if (v >= 2)  token = k1*log(v*k2) */
     LogK2 = 1./b;
-    lt2size = (2./linstep)+1;
+    lt2size = (int)(2./linstep) + 1;
     FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16));
     From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16));
     From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16));
     FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16));
     From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16));
     From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16));
@@ -551,9 +543,9 @@ PixarLogMakeTables(PixarLogState *sp)
 
     for (i = 0; i < TSIZEP1; i++)  {
        v = ToLinearF[i]*65535.0 + 0.5;
 
     for (i = 0; i < TSIZEP1; i++)  {
        v = ToLinearF[i]*65535.0 + 0.5;
-       ToLinear16[i] = (v > 65535.0) ? 65535 : v;
+       ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16)v;
        v = ToLinearF[i]*255.0  + 0.5;
        v = ToLinearF[i]*255.0  + 0.5;
-       ToLinear8[i]  = (v > 255.0) ? 255 : v;
+       ToLinear8[i]  = (v > 255.0) ? 255 : (unsigned char)v;
     }
 
     j = 0;
     }
 
     j = 0;
@@ -638,11 +630,23 @@ PixarLogGuessDataFmt(TIFFDirectory *td)
        return guess;
 }
 
        return guess;
 }
 
+static uint32
+multiply(size_t m1, size_t m2)
+{
+       uint32  bytes = m1 * m2;
+
+       if (m1 && bytes / m1 != m2)
+               bytes = 0;
+
+       return bytes;
+}
+
 static int
 PixarLogSetupDecode(TIFF* tif)
 {
        TIFFDirectory *td = &tif->tif_dir;
        PixarLogState* sp = DecoderState(tif);
 static int
 PixarLogSetupDecode(TIFF* tif)
 {
        TIFFDirectory *td = &tif->tif_dir;
        PixarLogState* sp = DecoderState(tif);
+       tsize_t tbuf_size;
        static const char module[] = "PixarLogSetupDecode";
 
        assert(sp != NULL);
        static const char module[] = "PixarLogSetupDecode";
 
        assert(sp != NULL);
@@ -655,8 +659,13 @@ PixarLogSetupDecode(TIFF* tif)
 
        sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
            td->td_samplesperpixel : 1);
 
        sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
            td->td_samplesperpixel : 1);
-       sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride * 
-               td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
+       tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+                                     td->td_rowsperstrip), sizeof(uint16));
+       if (tbuf_size == 0)
+               return (0);
+       sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
+       if (sp->tbuf == NULL)
+               return (0);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
                sp->user_datafmt = PixarLogGuessDataFmt(td);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
                sp->user_datafmt = PixarLogGuessDataFmt(td);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
@@ -681,7 +690,6 @@ PixarLogSetupDecode(TIFF* tif)
 static int
 PixarLogPreDecode(TIFF* tif, tsample_t s)
 {
 static int
 PixarLogPreDecode(TIFF* tif, tsample_t s)
 {
-       TIFFDirectory *td = &tif->tif_dir;
        PixarLogState* sp = DecoderState(tif);
 
        (void) s;
        PixarLogState* sp = DecoderState(tif);
 
        (void) s;
@@ -807,6 +815,7 @@ PixarLogSetupEncode(TIFF* tif)
 {
        TIFFDirectory *td = &tif->tif_dir;
        PixarLogState* sp = EncoderState(tif);
 {
        TIFFDirectory *td = &tif->tif_dir;
        PixarLogState* sp = EncoderState(tif);
+       tsize_t tbuf_size;
        static const char module[] = "PixarLogSetupEncode";
 
        assert(sp != NULL);
        static const char module[] = "PixarLogSetupEncode";
 
        assert(sp != NULL);
@@ -815,8 +824,13 @@ PixarLogSetupEncode(TIFF* tif)
 
        sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
            td->td_samplesperpixel : 1);
 
        sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ?
            td->td_samplesperpixel : 1);
-       sp->tbuf = (uint16 *) _TIFFmalloc(sp->stride * 
-               td->td_imagewidth * td->td_rowsperstrip * sizeof(uint16));
+       tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth),
+                                     td->td_rowsperstrip), sizeof(uint16));
+       if (tbuf_size == 0)
+               return (0);
+       sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size);
+       if (sp->tbuf == NULL)
+               return (0);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
                sp->user_datafmt = PixarLogGuessDataFmt(td);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN)
                sp->user_datafmt = PixarLogGuessDataFmt(td);
        if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) {
@@ -839,7 +853,6 @@ PixarLogSetupEncode(TIFF* tif)
 static int
 PixarLogPreEncode(TIFF* tif, tsample_t s)
 {
 static int
 PixarLogPreEncode(TIFF* tif, tsample_t s)
 {
-       TIFFDirectory *td = &tif->tif_dir;
        PixarLogState *sp = EncoderState(tif);
 
        (void) s;
        PixarLogState *sp = EncoderState(tif);
 
        (void) s;
@@ -1288,10 +1301,10 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
 
        /* Override SetField so we can handle our private pseudo-tag */
        _TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo));
 
        /* Override SetField so we can handle our private pseudo-tag */
        _TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = PixarLogVGetField;   /* hook for codec tags */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = PixarLogVSetField;   /* hook for codec tags */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield = PixarLogVGetField;   /* hook for codec tags */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield = PixarLogVSetField;   /* hook for codec tags */
 
        /* Default values for codec-specific fields */
        sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */
 
        /* Default values for codec-specific fields */
        sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */
index e47331f321e92ae829e7e45322d49c1007a9b698..0da5c8b36bab93f8f2e186f1b7fec580e0200280 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  * Predictor Tag Support (used by multiple codecs).
  */
 #include "tiffiop.h"
  * Predictor Tag Support (used by multiple codecs).
  */
 #include "tiffiop.h"
-/* Watcom C++ (or its make utility) doesn't like long filenames */
-#ifdef wxUSE_SHORTNAMES
-#include "tif_pred.h"
-#else
 #include "tif_predict.h"
 #include "tif_predict.h"
-#endif
 
 #include <assert.h>
 
 #define        PredictorState(tif)     ((TIFFPredictorState*) (tif)->tif_data)
 
 
 #include <assert.h>
 
 #define        PredictorState(tif)     ((TIFFPredictorState*) (tif)->tif_data)
 
-static void LINKAGEMODE horAcc8(TIFF*, tidata_t, tsize_t);
-static void LINKAGEMODE horAcc16(TIFF*, tidata_t, tsize_t);
-static void LINKAGEMODE swabHorAcc16(TIFF*, tidata_t, tsize_t);
-static void LINKAGEMODE horDiff8(TIFF*, tidata_t, tsize_t);
-static void LINKAGEMODE horDiff16(TIFF*, tidata_t, tsize_t);
-static int LINKAGEMODE PredictorDecodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
-static int LINKAGEMODE PredictorDecodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
-static int LINKAGEMODE PredictorEncodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
-static int LINKAGEMODE PredictorEncodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
+static void horAcc8(TIFF*, tidata_t, tsize_t);
+static void horAcc16(TIFF*, tidata_t, tsize_t);
+static void swabHorAcc16(TIFF*, tidata_t, tsize_t);
+static void horDiff8(TIFF*, tidata_t, tsize_t);
+static void horDiff16(TIFF*, tidata_t, tsize_t);
+static int PredictorDecodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
+static int PredictorDecodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
+static int PredictorEncodeRow(TIFF*, tidata_t, tsize_t, tsample_t);
+static int PredictorEncodeTile(TIFF*, tidata_t, tsize_t, tsample_t);
 
 static int
 PredictorSetup(TIFF* tif)
 
 static int
 PredictorSetup(TIFF* tif)
@@ -165,7 +160,7 @@ static void
 horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
 horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
-       u_int stride = sp->stride;
+       tsize_t stride = sp->stride;
 
        char* cp = (char*) cp0;
        if (cc > stride) {
 
        char* cp = (char*) cp0;
        if (cc > stride) {
@@ -179,9 +174,9 @@ horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
                        u_int cb = cp[2];
                        do {
                                cc -= 3, cp += 3;
                        u_int cb = cp[2];
                        do {
                                cc -= 3, cp += 3;
-                               cp[0] = (cr += cp[0]);
-                               cp[1] = (cg += cp[1]);
-                               cp[2] = (cb += cp[2]);
+                               cp[0] = (char) (cr += cp[0]);
+                               cp[1] = (char) (cg += cp[1]);
+                               cp[2] = (char) (cb += cp[2]);
                        } while ((int32) cc > 0);
                } else if (stride == 4)  {
                        u_int cr = cp[0];
                        } while ((int32) cc > 0);
                } else if (stride == 4)  {
                        u_int cr = cp[0];
@@ -190,14 +185,14 @@ horAcc8(TIFF* tif, tidata_t cp0, tsize_t cc)
                        u_int ca = cp[3];
                        do {
                                cc -= 4, cp += 4;
                        u_int ca = cp[3];
                        do {
                                cc -= 4, cp += 4;
-                               cp[0] = (cr += cp[0]);
-                               cp[1] = (cg += cp[1]);
-                               cp[2] = (cb += cp[2]);
-                               cp[3] = (ca += cp[3]);
+                               cp[0] = (char) (cr += cp[0]);
+                               cp[1] = (char) (cg += cp[1]);
+                               cp[2] = (char) (cb += cp[2]);
+                               cp[3] = (char) (ca += cp[3]);
                        } while ((int32) cc > 0);
                } else  {
                        do {
                        } while ((int32) cc > 0);
                } else  {
                        do {
-                               REPEAT4(stride, cp[stride] += *cp; cp++)
+                               REPEAT4(stride, cp[stride] = (char) (cp[stride] + *cp); cp++)
                                cc -= stride;
                        } while ((int32) cc > 0);
                }
                                cc -= stride;
                        } while ((int32) cc > 0);
                }
@@ -208,7 +203,7 @@ static void
 swabHorAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
 swabHorAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
-       u_int stride = sp->stride;
+       tsize_t stride = sp->stride;
        uint16* wp = (uint16*) cp0;
        tsize_t wc = cc / 2;
 
        uint16* wp = (uint16*) cp0;
        tsize_t wc = cc / 2;
 
@@ -225,7 +220,7 @@ swabHorAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
 static void
 horAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
 static void
 horAcc16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
-       u_int stride = PredictorState(tif)->stride;
+       tsize_t stride = PredictorState(tif)->stride;
        uint16* wp = (uint16*) cp0;
        tsize_t wc = cc / 2;
 
        uint16* wp = (uint16*) cp0;
        tsize_t wc = cc / 2;
 
@@ -288,7 +283,7 @@ static void
 horDiff8(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
 horDiff8(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
-       u_int stride = sp->stride;
+       tsize_t stride = sp->stride;
        char* cp = (char*) cp0;
 
        if (cc > stride) {
        char* cp = (char*) cp0;
 
        if (cc > stride) {
@@ -333,7 +328,7 @@ static void
 horDiff16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
 horDiff16(TIFF* tif, tidata_t cp0, tsize_t cc)
 {
        TIFFPredictorState* sp = PredictorState(tif);
-       u_int stride = sp->stride;
+       tsize_t stride = sp->stride;
        int16 *wp = (int16*) cp0;
        tsize_t wc = cc/2;
 
        int16 *wp = (int16*) cp0;
        tsize_t wc = cc/2;
 
@@ -420,7 +415,7 @@ PredictorVGetField(TIFF* tif, ttag_t tag, va_list ap)
        return (1);
 }
 
        return (1);
 }
 
-static void LINKAGEMODE
+static void
 PredictorPrintDir(TIFF* tif, FILE* fd, long flags)
 {
        TIFFPredictorState* sp = PredictorState(tif);
 PredictorPrintDir(TIFF* tif, FILE* fd, long flags)
 {
        TIFFPredictorState* sp = PredictorState(tif);
@@ -448,12 +443,15 @@ TIFFPredictorInit(TIFF* tif)
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo));
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = PredictorVGetField;/* hook for predictor tag */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = PredictorVSetField;/* hook for predictor tag */
-       sp->printdir = tif->tif_printdir;
-       tif->tif_printdir = PredictorPrintDir;  /* hook for predictor tag */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield =
+            PredictorVGetField;/* hook for predictor tag */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield =
+            PredictorVSetField;/* hook for predictor tag */
+       sp->printdir = tif->tif_tagmethods.printdir;
+       tif->tif_tagmethods.printdir =
+            PredictorPrintDir; /* hook for predictor tag */
 
        sp->setupdecode = tif->tif_setupdecode;
        tif->tif_setupdecode = PredictorSetupDecode;
 
        sp->setupdecode = tif->tif_setupdecode;
        tif->tif_setupdecode = PredictorSetupDecode;
index 7197e652e455a73c0b865193dae8925b6c594391..8fd7165001c3f2655154f308cd13172f3c1edf27 100644 (file)
@@ -72,7 +72,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
        uint16 i;
        long l, n;
 
        uint16 i;
        long l, n;
 
-       fprintf(fd, "TIFF Directory at offset 0x%lx\n", (long) tif->tif_diroff);
+       fprintf(fd, "TIFF Directory at offset 0x%lx\n", tif->tif_diroff);
        td = &tif->tif_dir;
        if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
                fprintf(fd, "  Subfile Type:");
        td = &tif->tif_dir;
        if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
                fprintf(fd, "  Subfile Type:");
@@ -98,6 +98,42 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
                            (u_long) td->td_imagedepth);
                fprintf(fd, "\n");
        }
                            (u_long) td->td_imagedepth);
                fprintf(fd, "\n");
        }
+
+       /* Begin Pixar */
+       if (TIFFFieldSet(tif,FIELD_IMAGEFULLWIDTH) ||
+           TIFFFieldSet(tif,FIELD_IMAGEFULLLENGTH)) {
+         fprintf(fd, "  Pixar Full Image Width: %lu Full Image Length: %lu\n",
+                 (u_long) td->td_imagefullwidth,
+                 (u_long) td->td_imagefulllength);
+       }
+       if (TIFFFieldSet(tif,FIELD_TEXTUREFORMAT))
+         _TIFFprintAsciiTag(fd, "Texture Format", td->td_textureformat);
+       if (TIFFFieldSet(tif,FIELD_WRAPMODES))
+         _TIFFprintAsciiTag(fd, "Texture Wrap Modes", td->td_wrapmodes);
+       if (TIFFFieldSet(tif,FIELD_FOVCOT))
+         fprintf(fd, "  Field of View Cotangent: %g\n", td->td_fovcot);
+       if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOSCREEN)) {
+         typedef float Matrix[4][4];
+         Matrix*               m = (Matrix*)td->td_matrixWorldToScreen;
+         
+         fprintf(fd, "  Matrix NP:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
+                 (*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
+                 (*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
+                 (*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
+                 (*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
+       }
+       if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOCAMERA)) {
+         typedef float Matrix[4][4];
+         Matrix*               m = (Matrix*)td->td_matrixWorldToCamera;
+         
+         fprintf(fd, "  Matrix Nl:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
+                 (*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
+                 (*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
+                 (*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
+                 (*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
+       }
+       /* End Pixar */
+       
        if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
                fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
                    (u_long) td->td_tilewidth, (u_long) td->td_tilelength);
        if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
                fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
                    (u_long) td->td_tilewidth, (u_long) td->td_tilelength);
@@ -149,6 +185,12 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
                case SAMPLEFORMAT_IEEEFP:
                        fprintf(fd, "IEEE floating point\n");
                        break;
                case SAMPLEFORMAT_IEEEFP:
                        fprintf(fd, "IEEE floating point\n");
                        break;
+               case SAMPLEFORMAT_COMPLEXINT:
+                       fprintf(fd, "complex signed integer\n");
+                       break;
+               case SAMPLEFORMAT_COMPLEXIEEEFP:
+                       fprintf(fd, "complex IEEE floating point\n");
+                       break;
                default:
                        fprintf(fd, "%u (0x%x)\n",
                            td->td_sampleformat, td->td_sampleformat);
                default:
                        fprintf(fd, "%u (0x%x)\n",
                            td->td_sampleformat, td->td_sampleformat);
@@ -277,8 +319,19 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
        }
 #ifdef YCBCR_SUPPORT
        if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
        }
 #ifdef YCBCR_SUPPORT
        if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
+        {
+            /*
+             * For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),
+             * we need to fetch this rather than trust what is in our
+             * structures.
+             */
+            uint16 subsampling[2];
+
+            TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
+                          subsampling + 0, subsampling + 1 );
                fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
                fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
-                   td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
+                        subsampling[0], subsampling[1] );
+        }
        if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
                fprintf(fd, "  YCbCr Positioning: ");
                switch (td->td_ycbcrpositioning) {
        if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
                fprintf(fd, "  YCbCr Positioning: ");
                switch (td->td_ycbcrpositioning) {
@@ -309,8 +362,8 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
                _TIFFprintAsciiTag(fd, "Date & Time", td->td_datetime);
        if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
                _TIFFprintAsciiTag(fd, "Host Computer", td->td_hostcomputer);
                _TIFFprintAsciiTag(fd, "Date & Time", td->td_datetime);
        if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
                _TIFFprintAsciiTag(fd, "Host Computer", td->td_hostcomputer);
-       if (TIFFFieldSet(tif,FIELD_SOFTWARE))
-               _TIFFprintAsciiTag(fd, "Software", td->td_software);
+       if (TIFFFieldSet(tif,FIELD_COPYRIGHT))
+               _TIFFprintAsciiTag(fd, "Copyright", td->td_copyright);
        if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
                _TIFFprintAsciiTag(fd, "Document Name", td->td_documentname);
        if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
        if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
                _TIFFprintAsciiTag(fd, "Document Name", td->td_documentname);
        if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
@@ -437,8 +490,85 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
                fputc('\n', fd);
        }
 #endif
                fputc('\n', fd);
        }
 #endif
-       if (tif->tif_printdir)
-               (*tif->tif_printdir)(tif, fd, flags);
+        /*
+        ** Custom tag support.
+        */
+        {
+            int  i;
+            short count;
+
+            count = (short) TIFFGetTagListCount( tif );
+            for( i = 0; i < count; i++ )
+            {
+                ttag_t  tag = TIFFGetTagListEntry( tif, i );
+                const TIFFFieldInfo *fld;
+
+                fld = TIFFFieldWithTag( tif, tag );
+                if( fld == NULL )
+                    continue;
+
+                if( fld->field_passcount )
+                {
+                    short value_count;
+                    int j;
+                    void *raw_data;
+                    
+                    if( TIFFGetField( tif, tag, &value_count, &raw_data ) != 1 )
+                        continue;
+
+                    fprintf(fd, "  %s: ", fld->field_name );
+
+                    for( j = 0; j < value_count; j++ )
+                    {
+                       if( fld->field_type == TIFF_BYTE )
+                            fprintf( fd, "%d",
+                                     (int) ((char *) raw_data)[j] );
+                       else if( fld->field_type == TIFF_SHORT )
+                            fprintf( fd, "%d",
+                                     (int) ((short *) raw_data)[j] );
+                        else if( fld->field_type == TIFF_LONG )
+                            fprintf( fd, "%d",
+                                     (int) ((long *) raw_data)[j] );
+                       else if( fld->field_type == TIFF_RATIONAL )
+                           fprintf( fd, "%f",
+                                    ((float *) raw_data)[j] );
+                        else if( fld->field_type == TIFF_ASCII )
+                        {
+                            fprintf( fd, "%s",
+                                     (char *) raw_data );
+                            break;
+                        }
+                        else if( fld->field_type == TIFF_DOUBLE )
+                            fprintf( fd, "%f",
+                                     ((double *) raw_data)[j] );
+                        else if( fld->field_type == TIFF_FLOAT )
+                            fprintf( fd, "%f",
+                                     ((float *) raw_data)[j] );
+                        else
+                        {
+                            fprintf( fd,
+                                     "<unsupported data type in TIFFPrint>" );
+                            break;
+                        }
+
+                        if( j < value_count-1 )
+                            fprintf( fd, "," );
+                    }
+                    fprintf( fd, "\n" );
+                } 
+                else if( !fld->field_passcount
+                         && fld->field_type == TIFF_ASCII )
+                {
+                    char *data;
+                    
+                    if( TIFFGetField( tif, tag, &data ) )
+                        fprintf(fd, "  %s: %s\n", fld->field_name, data );
+                }
+            }
+        }
+        
+       if (tif->tif_tagmethods.printdir)
+               (*tif->tif_tagmethods.printdir)(tif, fd, flags);
        if ((flags & TIFFPRINT_STRIPS) &&
            TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
                tstrip_t s;
        if ((flags & TIFFPRINT_STRIPS) &&
            TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
                tstrip_t s;
@@ -460,7 +590,7 @@ _TIFFprintAscii(FILE* fd, const char* cp)
        for (; *cp != '\0'; cp++) {
                const char* tp;
 
        for (; *cp != '\0'; cp++) {
                const char* tp;
 
-               if (isprint((int)*cp)) {
+               if (isprint(*cp)) {
                        fputc(*cp, fd);
                        continue;
                }
                        fputc(*cp, fd);
                        continue;
                }
index 14411539ce046f0526634489b9d46aa65d183b66..f39bf45ae6e23a6e05f9454731456a2386903511 100644 (file)
@@ -32,8 +32,8 @@
 #include <stdio.h>
 #include <assert.h>
 
 #include <stdio.h>
 #include <assert.h>
 
-static int TIFFFillStrip(TIFF*, tstrip_t);
-static int TIFFFillTile(TIFF*, ttile_t);
+       int TIFFFillStrip(TIFF*, tstrip_t);
+       int TIFFFillTile(TIFF*, ttile_t);
 static int TIFFStartStrip(TIFF*, tstrip_t);
 static int TIFFStartTile(TIFF*, ttile_t);
 static int TIFFCheckRead(TIFF*, int);
 static int TIFFStartStrip(TIFF*, tstrip_t);
 static int TIFFStartTile(TIFF*, ttile_t);
 static int TIFFCheckRead(TIFF*, int);
@@ -104,7 +104,10 @@ TIFFReadScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
                 */
                e = (*tif->tif_decoderow)
                    (tif, (tidata_t) buf, tif->tif_scanlinesize, sample);
                 */
                e = (*tif->tif_decoderow)
                    (tif, (tidata_t) buf, tif->tif_scanlinesize, sample);
-               tif->tif_row++;
+
+                /* we are now poised at the beginning of the next row */
+                tif->tif_row = row + 1;
+
                if (e)
                        (*tif->tif_postdecode)(tif, (tidata_t) buf,
                            tif->tif_scanlinesize);
                if (e)
                        (*tif->tif_postdecode)(tif, (tidata_t) buf,
                            tif->tif_scanlinesize);
@@ -122,6 +125,7 @@ TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
        TIFFDirectory *td = &tif->tif_dir;
        uint32 nrows;
        tsize_t stripsize;
        TIFFDirectory *td = &tif->tif_dir;
        uint32 nrows;
        tsize_t stripsize;
+        tstrip_t sep_strip, strips_per_sep;
 
        if (!TIFFCheckRead(tif, 0))
                return (-1);
 
        if (!TIFFCheckRead(tif, 0))
                return (-1);
@@ -132,18 +136,29 @@ TIFFReadEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
        }
        /*
         * Calculate the strip size according to the number of
        }
        /*
         * Calculate the strip size according to the number of
-        * rows in the strip (check for truncated last strip).
+        * rows in the strip (check for truncated last strip on any
+         * of the separations).
         */
         */
-       if (strip != td->td_nstrips-1 ||
+        if( td->td_rowsperstrip >= td->td_imagelength )
+            strips_per_sep = 1;
+        else
+            strips_per_sep = (td->td_imagelength+td->td_rowsperstrip-1)
+                / td->td_rowsperstrip;
+
+        sep_strip = strip % strips_per_sep;
+
+       if (sep_strip != strips_per_sep-1 ||
            (nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
                nrows = td->td_rowsperstrip;
            (nrows = td->td_imagelength % td->td_rowsperstrip) == 0)
                nrows = td->td_rowsperstrip;
+
        stripsize = TIFFVStripSize(tif, nrows);
        if (size == (tsize_t) -1)
                size = stripsize;
        else if (size > stripsize)
                size = stripsize;
        stripsize = TIFFVStripSize(tif, nrows);
        if (size == (tsize_t) -1)
                size = stripsize;
        else if (size > stripsize)
                size = stripsize;
-       if (TIFFFillStrip(tif, strip) && (*tif->tif_decodestrip)(tif,
-           (tidata_t) buf, size, (tsample_t)(strip / td->td_stripsperimage))) {
+       if (TIFFFillStrip(tif, strip) 
+            && (*tif->tif_decodestrip)(tif, (tidata_t) buf, size, 
+                         (tsample_t)(strip / td->td_stripsperimage)) > 0 ) {
                (*tif->tif_postdecode)(tif, (tidata_t) buf, size);
                return (size);
        } else
                (*tif->tif_postdecode)(tif, (tidata_t) buf, size);
                return (size);
        } else
@@ -226,7 +241,7 @@ TIFFReadRawStrip(TIFF* tif, tstrip_t strip, tdata_t buf, tsize_t size)
  * The data buffer is expanded, as necessary, to
  * hold the strip's data.
  */
  * The data buffer is expanded, as necessary, to
  * hold the strip's data.
  */
-static int
+int
 TIFFFillStrip(TIFF* tif, tstrip_t strip)
 {
        static const char module[] = "TIFFFillStrip";
 TIFFFillStrip(TIFF* tif, tstrip_t strip)
 {
        static const char module[] = "TIFFFillStrip";
@@ -256,7 +271,7 @@ TIFFFillStrip(TIFF* tif, tstrip_t strip)
                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
                        _TIFFfree(tif->tif_rawdata);
                tif->tif_flags &= ~TIFF_MYBUFFER;
                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
                        _TIFFfree(tif->tif_rawdata);
                tif->tif_flags &= ~TIFF_MYBUFFER;
-               if (td->td_stripoffset[strip] + bytecount > tif->tif_size) {
+               if ( td->td_stripoffset[strip] + bytecount > tif->tif_size) {
                        /*
                         * This error message might seem strange, but it's
                         * what would happen if a read were done instead.
                        /*
                         * This error message might seem strange, but it's
                         * what would happen if a read were done instead.
@@ -423,7 +438,7 @@ TIFFReadRawTile(TIFF* tif, ttile_t tile, tdata_t buf, tsize_t size)
  * The data buffer is expanded, as necessary, to
  * hold the tile's data.
  */
  * The data buffer is expanded, as necessary, to
  * hold the tile's data.
  */
-static int
+int
 TIFFFillTile(TIFF* tif, ttile_t tile)
 {
        static const char module[] = "TIFFFillTile";
 TIFFFillTile(TIFF* tif, ttile_t tile)
 {
        static const char module[] = "TIFFFillTile";
@@ -453,7 +468,7 @@ TIFFFillTile(TIFF* tif, ttile_t tile)
                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
                        _TIFFfree(tif->tif_rawdata);
                tif->tif_flags &= ~TIFF_MYBUFFER;
                if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)
                        _TIFFfree(tif->tif_rawdata);
                tif->tif_flags &= ~TIFF_MYBUFFER;
-               if (td->td_stripoffset[tile] + bytecount > tif->tif_size) {
+               if ( td->td_stripoffset[tile] + bytecount > tif->tif_size) {
                        tif->tif_curtile = NOTILE;
                        return (0);
                }
                        tif->tif_curtile = NOTILE;
                        return (0);
                }
index 2321ad029e4295153fd595e92ee1a55fa6d0af7a..4c8378bd0b3bd7b8e44716d1eced01fefea4a6cc 100644 (file)
  */
 #include "tiffiop.h"
 
  */
 #include "tiffiop.h"
 
+static uint32
+summarize(TIFF* tif, size_t summand1, size_t summand2, const char* where)
+{
+       uint32  bytes = summand1 + summand2;
+
+       if (bytes - summand1 != summand2) {
+               TIFFError(tif->tif_name, "Integer overflow in %s", where);
+               bytes = 0;
+       }
+
+       return (bytes);
+}
+
+static uint32
+multiply(TIFF* tif, size_t nmemb, size_t elem_size, const char* where)
+{
+       uint32  bytes = nmemb * elem_size;
+
+       if (elem_size && bytes / elem_size != nmemb) {
+               TIFFError(tif->tif_name, "Integer overflow in %s", where);
+               bytes = 0;
+       }
+
+       return (bytes);
+}
+
 /*
  * Compute which strip a (row,sample) value is in.
  */
 /*
  * Compute which strip a (row,sample) value is in.
  */
@@ -66,7 +92,8 @@ TIFFNumberOfStrips(TIFF* tif)
             (td->td_imagelength != 0 ? 1 : 0) :
             TIFFhowmany(td->td_imagelength, td->td_rowsperstrip));
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
             (td->td_imagelength != 0 ? 1 : 0) :
             TIFFhowmany(td->td_imagelength, td->td_rowsperstrip));
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
-               nstrips *= td->td_samplesperpixel;
+               nstrips = multiply(tif, nstrips, td->td_samplesperpixel,
+                                  "TIFFNumberOfStrips");
        return (nstrips);
 }
 
        return (nstrips);
 }
 
@@ -92,18 +119,48 @@ TIFFVStripSize(TIFF* tif, uint32 nrows)
                 * horizontal/vertical subsampling area include
                 * YCbCr data for the extended image.
                 */
                 * horizontal/vertical subsampling area include
                 * YCbCr data for the extended image.
                 */
-               tsize_t w =
-                   TIFFroundup(td->td_imagewidth, td->td_ycbcrsubsampling[0]);
-               tsize_t scanline = TIFFhowmany(w*td->td_bitspersample, 8);
-               tsize_t samplingarea =
-                   td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
-               nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]);
+                uint16 ycbcrsubsampling[2];
+                tsize_t w, scanline, samplingarea;
+
+                TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
+                              ycbcrsubsampling + 0, 
+                              ycbcrsubsampling + 1 );
+
+               w = TIFFroundup(td->td_imagewidth, ycbcrsubsampling[0]);
+               scanline = TIFFhowmany8(multiply(tif, w, td->td_bitspersample,
+                                                "TIFFVStripSize"));
+               samplingarea = ycbcrsubsampling[0]*ycbcrsubsampling[1];
+               nrows = TIFFroundup(nrows, ycbcrsubsampling[1]);
                /* NB: don't need TIFFhowmany here 'cuz everything is rounded */
                /* NB: don't need TIFFhowmany here 'cuz everything is rounded */
+               scanline = multiply(tif, nrows, scanline, "TIFFVStripSize");
                return ((tsize_t)
                return ((tsize_t)
-                   (nrows*scanline + 2*(nrows*scanline / samplingarea)));
+                   summarize(tif, scanline,
+                             multiply(tif, 2, scanline / samplingarea,
+                                      "TIFFVStripSize"), "TIFFVStripSize"));
        } else
 #endif
        } else
 #endif
-               return ((tsize_t)(nrows * TIFFScanlineSize(tif)));
+               return ((tsize_t) multiply(tif, nrows, TIFFScanlineSize(tif),
+                                          "TIFFVStripSize"));
+}
+
+
+/*
+ * Compute the # bytes in a raw strip.
+ */
+tsize_t
+TIFFRawStripSize(TIFF* tif, tstrip_t strip)
+{
+       TIFFDirectory* td = &tif->tif_dir;
+       tsize_t bytecount = td->td_stripbytecount[strip];
+
+       if (bytecount <= 0) {
+               TIFFError(tif->tif_name,
+                         "%lu: Invalid strip byte count, strip %lu",
+                         (u_long) bytecount, (u_long) strip);
+               bytecount = (tsize_t) -1;
+       }
+
+       return bytecount;
 }
 
 /*
 }
 
 /*
@@ -164,10 +221,12 @@ TIFFScanlineSize(TIFF* tif)
        TIFFDirectory *td = &tif->tif_dir;
        tsize_t scanline;
        
        TIFFDirectory *td = &tif->tif_dir;
        tsize_t scanline;
        
-       scanline = td->td_bitspersample * td->td_imagewidth;
+       scanline = multiply (tif, td->td_bitspersample, td->td_imagewidth,
+                            "TIFFScanlineSize");
        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
-               scanline *= td->td_samplesperpixel;
-       return ((tsize_t) TIFFhowmany(scanline, 8));
+               scanline = multiply (tif, scanline, td->td_samplesperpixel,
+                                    "TIFFScanlineSize");
+       return ((tsize_t) TIFFhowmany8(scanline));
 }
 
 /*
 }
 
 /*
@@ -182,11 +241,14 @@ TIFFRasterScanlineSize(TIFF* tif)
        TIFFDirectory *td = &tif->tif_dir;
        tsize_t scanline;
        
        TIFFDirectory *td = &tif->tif_dir;
        tsize_t scanline;
        
-       scanline = td->td_bitspersample * td->td_imagewidth;
+       scanline = multiply (tif, td->td_bitspersample, td->td_imagewidth,
+                            "TIFFRasterScanlineSize");
        if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
        if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
-               scanline *= td->td_samplesperpixel;
-               return ((tsize_t) TIFFhowmany(scanline, 8));
+               scanline = multiply (tif, scanline, td->td_samplesperpixel,
+                                    "TIFFRasterScanlineSize");
+               return ((tsize_t) TIFFhowmany8(scanline));
        } else
        } else
-               return ((tsize_t)
-                   TIFFhowmany(scanline, 8)*td->td_samplesperpixel);
+               return ((tsize_t) multiply (tif, TIFFhowmany8(scanline),
+                                           td->td_samplesperpixel,
+                                           "TIFFRasterScanlineSize"));
 }
 }
index 4130155f6d075b006feb5f9f2a7dc8fdd878224b..37962b82a7595a303c5c11790ddcf96f28e3ce45 100644 (file)
@@ -36,7 +36,7 @@ void
 TIFFSwabShort(uint16* wp)
 {
        register u_char* cp = (u_char*) wp;
 TIFFSwabShort(uint16* wp)
 {
        register u_char* cp = (u_char*) wp;
-       int t;
+       u_char t;
 
        t = cp[1]; cp[1] = cp[0]; cp[0] = t;
 }
 
        t = cp[1]; cp[1] = cp[0]; cp[0] = t;
 }
@@ -47,7 +47,7 @@ void
 TIFFSwabLong(uint32* lp)
 {
        register u_char* cp = (u_char*) lp;
 TIFFSwabLong(uint32* lp)
 {
        register u_char* cp = (u_char*) lp;
-       int t;
+       u_char t;
 
        t = cp[3]; cp[3] = cp[0]; cp[0] = t;
        t = cp[2]; cp[2] = cp[1]; cp[1] = t;
 
        t = cp[3]; cp[3] = cp[0]; cp[0] = t;
        t = cp[2]; cp[2] = cp[1]; cp[1] = t;
@@ -59,7 +59,7 @@ void
 TIFFSwabArrayOfShort(uint16* wp, register u_long n)
 {
        register u_char* cp;
 TIFFSwabArrayOfShort(uint16* wp, register u_long n)
 {
        register u_char* cp;
-       register int t;
+       register u_char t;
 
        /* XXX unroll loop some */
        while (n-- > 0) {
 
        /* XXX unroll loop some */
        while (n-- > 0) {
@@ -75,7 +75,7 @@ void
 TIFFSwabArrayOfLong(register uint32* lp, register u_long n)
 {
        register unsigned char *cp;
 TIFFSwabArrayOfLong(register uint32* lp, register u_long n)
 {
        register unsigned char *cp;
-       register int t;
+       register unsigned char t;
 
        /* XXX unroll loop some */
        while (n-- > 0) {
 
        /* XXX unroll loop some */
        while (n-- > 0) {
index 068483f19701f552ed8e7fabd7dd40aebe3b42da..08807959805872c3b5ee16b1115125de77c405d6 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -60,7 +60,7 @@ static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
        if (npixels++ & 1) \
            *op++ |= lastpixel; \
        else \
        if (npixels++ & 1) \
            *op++ |= lastpixel; \
        else \
-           op[0] = lastpixel << 4; \
+           op[0] = (tidataval_t) (lastpixel << 4); \
 }
 
 static int
 }
 
 static int
@@ -91,8 +91,10 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
                        } else
                                lastpixel |= lastpixel << 4;
                        npixels += n;
                        } else
                                lastpixel |= lastpixel << 4;
                        npixels += n;
-                       for (; n > 0; n -= 2)
-                               *op++ = lastpixel;
+                       if (npixels < maxpixels) {
+                               for (; n > 0; n -= 2)
+                                       *op++ = (tidataval_t) lastpixel;
+                       }
                        if (n == -1)
                                *--op &= 0xf0;
                        lastpixel &= 0xf;
                        if (n == -1)
                                *--op &= 0xf0;
                        lastpixel &= 0xf;
@@ -128,7 +130,7 @@ ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels)
        return (1);
 }
 
        return (1);
 }
 
-static int LINKAGEMODE
+static int
 ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        tidata_t row = buf;
 ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 {
        tidata_t row = buf;
index 931b6872bb69f0bd2d7822b358ba6195332ea6fd..5a0b433a20db66656be236d1f2edd85ab17366b1 100644 (file)
  */
 #include "tiffiop.h"
 
  */
 #include "tiffiop.h"
 
+static uint32
+summarize(TIFF* tif, size_t summand1, size_t summand2, const char* where)
+{
+       uint32  bytes = summand1 + summand2;
+
+       if (bytes - summand1 != summand2) {
+               TIFFError(tif->tif_name, "Integer overflow in %s", where);
+               bytes = 0;
+       }
+
+       return (bytes);
+}
+
+static uint32
+multiply(TIFF* tif, size_t nmemb, size_t elem_size, const char* where)
+{
+       uint32  bytes = nmemb * elem_size;
+
+       if (elem_size && bytes / elem_size != nmemb) {
+               TIFFError(tif->tif_name, "Integer overflow in %s", where);
+               bytes = 0;
+       }
+
+       return (bytes);
+}
+
 /*
  * Compute which tile an (x,y,z,s) value is in.
  */
 /*
  * Compute which tile an (x,y,z,s) value is in.
  */
@@ -62,7 +88,7 @@ TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, tsample_t s)
                             xpt*(y/dy) +
                             x/dx;
                else
                             xpt*(y/dy) +
                             x/dx;
                else
-                       tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx + s;
+                       tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx;
        }
        return (tile);
 }
        }
        return (tile);
 }
@@ -119,11 +145,13 @@ TIFFNumberOfTiles(TIFF* tif)
        if (dz == (uint32) -1)
                dz = td->td_imagedepth;
        ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
        if (dz == (uint32) -1)
                dz = td->td_imagedepth;
        ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
-           (TIFFhowmany(td->td_imagewidth, dx) *
-            TIFFhowmany(td->td_imagelength, dy) *
-            TIFFhowmany(td->td_imagedepth, dz));
+           multiply(tif, multiply(tif, TIFFhowmany(td->td_imagewidth, dx),
+                                  TIFFhowmany(td->td_imagelength, dy),
+                                  "TIFFNumberOfTiles"),
+                    TIFFhowmany(td->td_imagedepth, dz), "TIFFNumberOfTiles");
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
-               ntiles *= td->td_samplesperpixel;
+               ntiles = multiply(tif, ntiles, td->td_samplesperpixel,
+                                 "TIFFNumberOfTiles");
        return (ntiles);
 }
 
        return (ntiles);
 }
 
@@ -138,10 +166,12 @@ TIFFTileRowSize(TIFF* tif)
        
        if (td->td_tilelength == 0 || td->td_tilewidth == 0)
                return ((tsize_t) 0);
        
        if (td->td_tilelength == 0 || td->td_tilewidth == 0)
                return ((tsize_t) 0);
-       rowsize = td->td_bitspersample * td->td_tilewidth;
+       rowsize = multiply(tif, td->td_bitspersample, td->td_tilewidth,
+                          "TIFFTileRowSize");
        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
        if (td->td_planarconfig == PLANARCONFIG_CONTIG)
-               rowsize *= td->td_samplesperpixel;
-       return ((tsize_t) TIFFhowmany(rowsize, 8));
+               rowsize = multiply(tif, rowsize, td->td_samplesperpixel,
+                                  "TIFFTileRowSize");
+       return ((tsize_t) TIFFhowmany8(rowsize));
 }
 
 /*
 }
 
 /*
@@ -170,16 +200,24 @@ TIFFVTileSize(TIFF* tif, uint32 nrows)
                 */
                tsize_t w =
                    TIFFroundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]);
                 */
                tsize_t w =
                    TIFFroundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]);
-               tsize_t rowsize = TIFFhowmany(w*td->td_bitspersample, 8);
+               tsize_t rowsize =
+                   TIFFhowmany8(multiply(tif, w, td->td_bitspersample,
+                                         "TIFFVTileSize"));
                tsize_t samplingarea =
                    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
                nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]);
                /* NB: don't need TIFFhowmany here 'cuz everything is rounded */
                tsize_t samplingarea =
                    td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
                nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]);
                /* NB: don't need TIFFhowmany here 'cuz everything is rounded */
-               tilesize = nrows*rowsize + 2*(nrows*rowsize / samplingarea);
+               tilesize = multiply(tif, nrows, rowsize, "TIFFVTileSize");
+               tilesize = summarize(tif, tilesize,
+                                    multiply(tif, 2, tilesize / samplingarea,
+                                             "TIFFVTileSize"),
+                                    "TIFFVTileSize");
        } else
 #endif
        } else
 #endif
-               tilesize = nrows * TIFFTileRowSize(tif);
-       return ((tsize_t)(tilesize * td->td_tiledepth));
+               tilesize = multiply(tif, nrows, TIFFTileRowSize(tif),
+                                   "TIFFVTileSize");
+       return ((tsize_t)
+           multiply(tif, tilesize, td->td_tiledepth, "TIFFVTileSize"));
 }
 
 /*
 }
 
 /*
index 6e4378595e8b6517fbe93eba7697cc1460dbc1d3..dab65b3ceda6535b35d25c246e4499f62ee2653d 100644 (file)
@@ -47,7 +47,11 @@ _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
+#if USE_64BIT_API == 1
+       return ((toff_t) lseek64((int) fd, (off64_t) off, whence));
+#else
        return ((toff_t) lseek((int) fd, (off_t) off, whence));
        return ((toff_t) lseek((int) fd, (off_t) off, whence));
+#endif
 }
 
 static int
 }
 
 static int
@@ -64,10 +68,15 @@ _tiffSizeProc(thandle_t fd)
 #ifdef _AM29K
        long fsize;
        return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize);
 #ifdef _AM29K
        long fsize;
        return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize);
+#else
+#if USE_64BIT_API == 1
+       struct stat64 sb;
+       return (toff_t) (fstat64((int) fd, &sb) < 0 ? 0 : sb.st_size);
 #else
        struct stat sb;
        return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
 #endif
 #else
        struct stat sb;
        return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size);
 #endif
+#endif
 }
 
 #ifdef HAVE_MMAP
 }
 
 #ifdef HAVE_MMAP
@@ -147,8 +156,12 @@ TIFFOpen(const char* name, const char* mode)
         
 #ifdef _AM29K
        fd = open(name, m);
         
 #ifdef _AM29K
        fd = open(name, m);
+#else
+#if USE_64BIT_API == 1
+       fd = open(name, m | O_LARGEFILE, 0666);
 #else
        fd = open(name, m, 0666);
 #else
        fd = open(name, m, 0666);
+#endif
 #endif
        if (fd < 0) {
                TIFFError(module, "%s: Cannot open", name);
 #endif
        if (fd < 0) {
                TIFFError(module, "%s: Cannot open", name);
index 5a3a268c9aef923352ec950dc5238acad0118cae..2b8ccf7708a85fff26c4ae977df9ed3147cf0392 100644 (file)
@@ -24,9 +24,7 @@
  */
 #include "tiffiop.h"
 
  */
 #include "tiffiop.h"
 
-#define VERSION "LIBTIFF, Version 3.5.201\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
-
-static const char TIFFVersion[] = VERSION;
+static const char TIFFVersion[] = TIFFLIB_VERSION_STR;
 
 const char*
 TIFFGetVersion(void)
 
 const char*
 TIFFGetVersion(void)
index eae85229c921d45e2ede8cf81742e97b1e536f78..9ddf5fea1237b7097bed0a030fbb0c14810737fc 100644 (file)
@@ -52,23 +52,30 @@ _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
 static toff_t
 _tiffSeekProc(thandle_t fd, toff_t off, int whence)
 {
-       DWORD dwMoveMethod;
+       DWORD dwMoveMethod, dwMoveHigh;
+
+        /* we use this as a special code, so avoid accepting it */
+        if( off == 0xFFFFFFFF )
+            return 0xFFFFFFFF;
+        
        switch(whence)
        {
        switch(whence)
        {
-       case 0:
+       case SEEK_SET:
                dwMoveMethod = FILE_BEGIN;
                break;
                dwMoveMethod = FILE_BEGIN;
                break;
-       case 1:
+       case SEEK_CUR:
                dwMoveMethod = FILE_CURRENT;
                break;
                dwMoveMethod = FILE_CURRENT;
                break;
-       case 2:
+       case SEEK_END:
                dwMoveMethod = FILE_END;
                break;
        default:
                dwMoveMethod = FILE_BEGIN;
                break;
        }
                dwMoveMethod = FILE_END;
                break;
        default:
                dwMoveMethod = FILE_BEGIN;
                break;
        }
-       return ((toff_t)SetFilePointer(fd, off, NULL, dwMoveMethod));
+        dwMoveHigh = 0;
+       return ((toff_t)SetFilePointer(fd, (LONG) off, (PLONG)&dwMoveHigh,
+                                       dwMoveMethod));
 }
 
 static int
 }
 
 static int
@@ -83,6 +90,9 @@ _tiffSizeProc(thandle_t fd)
        return ((toff_t)GetFileSize(fd, NULL));
 }
 
        return ((toff_t)GetFileSize(fd, NULL));
 }
 
+#ifdef __BORLANDC__
+#pragma argsused
+#endif
 static int
 _tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
 static int
 _tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
 {
@@ -106,7 +116,7 @@ _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
        toff_t size;
        HANDLE hMapFile;
 
        toff_t size;
        HANDLE hMapFile;
 
-       if ((size = _tiffSizeProc(fd)) == (toff_t)-1)
+       if ((size = _tiffSizeProc(fd)) == 0xFFFFFFFF)
                return (0);
        hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, size, NULL);
        if (hMapFile == NULL)
                return (0);
        hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, size, NULL);
        if (hMapFile == NULL)
@@ -119,6 +129,9 @@ _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
        return(1);
 }
 
        return(1);
 }
 
+#ifdef __BORLANDC__
+#pragma argsused
+#endif
 static void
 _tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 {
 static void
 _tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size)
 {
@@ -139,7 +152,7 @@ TIFF*
 TIFFFdOpen(int ifd, const char* name, const char* mode)
 {
        TIFF* tif;
 TIFFFdOpen(int ifd, const char* name, const char* mode)
 {
        TIFF* tif;
-       BOOL fSuppressMap = (mode[1] == 'u' || mode[2] == 'u');
+       BOOL fSuppressMap = (mode[1] == 'u' || (mode[1]!=0 && mode[2] == 'u'));
 
        tif = TIFFClientOpen(name, mode,
                 (thandle_t)ifd,
 
        tif = TIFFClientOpen(name, mode,
                 (thandle_t)ifd,
@@ -211,14 +224,23 @@ _TIFFfree(tdata_t p)
 tdata_t
 _TIFFrealloc(tdata_t p, tsize_t s)
 {
 tdata_t
 _TIFFrealloc(tdata_t p, tsize_t s)
 {
-       void* pvTmp;
-       if ((pvTmp = GlobalReAlloc(p, s, 0)) == NULL) {
-               if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
-                       CopyMemory(pvTmp, p, GlobalSize(p));
-                       GlobalFree(p);
-               }
-       }
-       return ((tdata_t)pvTmp);
+  void* pvTmp;
+  tsize_t old=GlobalSize(p);
+  if (old>=s)
+    {
+      if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
+       CopyMemory(pvTmp, p, s);
+       GlobalFree(p);
+      }
+    }
+  else
+    {
+      if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
+       CopyMemory(pvTmp, p, old);
+       GlobalFree(p);
+      }
+    }
+  return ((tdata_t)pvTmp);
 }
 
 void
 }
 
 void
@@ -236,8 +258,8 @@ _TIFFmemcpy(void* d, const tdata_t s, tsize_t c)
 int
 _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
 {
 int
 _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
 {
-       register const BYTE *pb1 = p1;
-       register const BYTE *pb2 = p2;
+       register const BYTE *pb1 = (const BYTE *) p1;
+       register const BYTE *pb2 = (const BYTE *) p2;
        register DWORD dwTmp = c;
        register int iTmp;
        for (iTmp = 0; dwTmp-- && !iTmp; iTmp = (int)*pb1++ - (int)*pb2++)
        register DWORD dwTmp = c;
        register int iTmp;
        for (iTmp = 0; dwTmp-- && !iTmp; iTmp = (int)*pb1++ - (int)*pb2++)
index a30ebd41f3d5dddedf0d7996095b518af1473c78..7b8cab50cee63e9294dadfa4b101ad32fe0e3007 100644 (file)
@@ -33,6 +33,8 @@
 #include <assert.h>
 #include <stdio.h>
 
 #include <assert.h>
 #include <stdio.h>
 
+#define REWRITE_HACK
+
 #define        STRIPINCR       20              /* expansion factor on strip array */
 
 #define        WRITECHECKSTRIPS(tif, module)                           \
 #define        STRIPINCR       20              /* expansion factor on strip array */
 
 #define        WRITECHECKSTRIPS(tif, module)                           \
 #define        WRITECHECKTILES(tif, module)                            \
        (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module))
 #define        BUFFERCHECK(tif)                                        \
 #define        WRITECHECKTILES(tif, module)                            \
        (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module))
 #define        BUFFERCHECK(tif)                                        \
-       (((tif)->tif_flags & TIFF_BUFFERSETUP) ||               \
+       ((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \
            TIFFWriteBufferSetup((tif), NULL, (tsize_t) -1))
 
            TIFFWriteBufferSetup((tif), NULL, (tsize_t) -1))
 
-static int TIFFWriteCheck(TIFF*, int, const char*);
 static int TIFFGrowStrips(TIFF*, int, const char*);
 static int TIFFAppendToStrip(TIFF*, tstrip_t, tidata_t, tsize_t);
 static int TIFFGrowStrips(TIFF*, int, const char*);
 static int TIFFAppendToStrip(TIFF*, tstrip_t, tidata_t, tsize_t);
-static int TIFFSetupStrips(TIFF*);
 
 int
 TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
 
 int
 TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
@@ -152,9 +152,15 @@ TIFFWriteScanline(TIFF* tif, tdata_t buf, uint32 row, tsample_t sample)
                        return (-1);
                tif->tif_row = row;
        }
                        return (-1);
                tif->tif_row = row;
        }
+
+        /* swab if needed - note that source buffer will be altered */
+        tif->tif_postdecode( tif, (tidata_t) buf, tif->tif_scanlinesize );
+
        status = (*tif->tif_encoderow)(tif, (tidata_t) buf,
            tif->tif_scanlinesize, sample);
        status = (*tif->tif_encoderow)(tif, (tidata_t) buf,
            tif->tif_scanlinesize, sample);
-       tif->tif_row++;
+
+        /* we are now poised at the beginning of the next row */
+       tif->tif_row = row + 1;
        return (status);
 }
 
        return (status);
 }
 
@@ -208,10 +214,29 @@ TIFFWriteEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc)
                        return ((tsize_t) -1);
                tif->tif_flags |= TIFF_CODERSETUP;
        }
                        return ((tsize_t) -1);
                tif->tif_flags |= TIFF_CODERSETUP;
        }
+        
+#ifdef REWRITE_HACK        
+       tif->tif_rawcc = 0;
+       tif->tif_rawcp = tif->tif_rawdata;
+
+        if( td->td_stripbytecount[strip] > 0 )
+        {
+            /* if we are writing over existing tiles, zero length. */
+            td->td_stripbytecount[strip] = 0;
+
+            /* this forces TIFFAppendToStrip() to do a seek */
+            tif->tif_curoff = 0;
+        }
+#endif
+        
        tif->tif_flags &= ~TIFF_POSTENCODE;
        sample = (tsample_t)(strip / td->td_stripsperimage);
        if (!(*tif->tif_preencode)(tif, sample))
                return ((tsize_t) -1);
        tif->tif_flags &= ~TIFF_POSTENCODE;
        sample = (tsample_t)(strip / td->td_stripsperimage);
        if (!(*tif->tif_preencode)(tif, sample))
                return ((tsize_t) -1);
+
+        /* swab if needed - note that source buffer will be altered */
+        tif->tif_postdecode( tif, (tidata_t) data, cc );
+
        if (!(*tif->tif_encodestrip)(tif, (tidata_t) data, cc, sample))
                return ((tsize_t) 0);
        if (!(*tif->tif_postencode)(tif))
        if (!(*tif->tif_encodestrip)(tif, (tidata_t) data, cc, sample))
                return ((tsize_t) 0);
        if (!(*tif->tif_postencode)(tif))
@@ -329,6 +354,21 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
        if (!BUFFERCHECK(tif))
                return ((tsize_t) -1);
        tif->tif_curtile = tile;
        if (!BUFFERCHECK(tif))
                return ((tsize_t) -1);
        tif->tif_curtile = tile;
+
+#ifdef REWRITE_HACK        
+       tif->tif_rawcc = 0;
+       tif->tif_rawcp = tif->tif_rawdata;
+
+        if( td->td_stripbytecount[tile] > 0 )
+        {
+            /* if we are writing over existing tiles, zero length. */
+            td->td_stripbytecount[tile] = 0;
+
+            /* this forces TIFFAppendToStrip() to do a seek */
+            tif->tif_curoff = 0;
+        }
+#endif
+        
        /* 
         * Compute tiles per row & per column to compute
         * current row and column
        /* 
         * Compute tiles per row & per column to compute
         * current row and column
@@ -352,8 +392,12 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
         * done so that callers can pass in some large number
         * (e.g. -1) and have the tile size used instead.
         */
         * done so that callers can pass in some large number
         * (e.g. -1) and have the tile size used instead.
         */
-       if ((uint32) cc > tif->tif_tilesize)
+       if ( cc < 1 || cc > tif->tif_tilesize)
                cc = tif->tif_tilesize;
                cc = tif->tif_tilesize;
+
+        /* swab if needed - note that source buffer will be altered */
+        tif->tif_postdecode( tif, (tidata_t) data, cc );
+
        if (!(*tif->tif_encodetile)(tif, (tidata_t) data, cc, sample))
                return ((tsize_t) 0);
        if (!(*tif->tif_postencode)(tif))
        if (!(*tif->tif_encodetile)(tif, (tidata_t) data, cc, sample))
                return ((tsize_t) 0);
        if (!(*tif->tif_postencode)(tif))
@@ -398,7 +442,7 @@ TIFFWriteRawTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc)
 #define        isUnspecified(tif, f) \
     (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
 
 #define        isUnspecified(tif, f) \
     (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
 
-static int
+int
 TIFFSetupStrips(TIFF* tif)
 {
        TIFFDirectory* td = &tif->tif_dir;
 TIFFSetupStrips(TIFF* tif)
 {
        TIFFDirectory* td = &tif->tif_dir;
@@ -438,7 +482,7 @@ TIFFSetupStrips(TIFF* tif)
  * we also "freeze" the state of the directory so
  * that important information is not changed.
  */
  * we also "freeze" the state of the directory so
  * that important information is not changed.
  */
-static int
+int
 TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
 {
        if (tif->tif_mode == O_RDONLY) {
 TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
 {
        if (tif->tif_mode == O_RDONLY) {
@@ -452,6 +496,24 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
                    "Can not write scanlines to a tiled image");
                return (0);
        }
                    "Can not write scanlines to a tiled image");
                return (0);
        }
+        
+        /*
+         * While we allow compressed TIFF files to be opened in update mode,
+         * we don't allow writing any image blocks in an existing compressed
+         * image.  Eventually we could do so, by moving blocks that grow
+         * to the end of the file, but we don't for now. 
+         */
+       if (tif->tif_dir.td_stripoffset != NULL 
+            && tif->tif_dir.td_compression != COMPRESSION_NONE )
+        {
+            TIFFError( module,
+                       "%s:\n"
+                       "In place update to compressed TIFF images not "
+                       "supported.",
+                       tif->tif_name );
+            return (0);
+        }
+
        /*
         * On the first write verify all the required information
         * has been setup and initialize any data structures that
        /*
         * On the first write verify all the required information
         * has been setup and initialize any data structures that
@@ -480,7 +542,11 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
                    tif->tif_name, isTiled(tif) ? "tile" : "strip");
                return (0);
        }
                    tif->tif_name, isTiled(tif) ? "tile" : "strip");
                return (0);
        }
-       tif->tif_tilesize = TIFFTileSize(tif);
+       if (isTiled(tif)) 
+               tif->tif_tilesize = TIFFTileSize(tif);
+       else
+               tif->tif_tilesize = (tsize_t) -1;
+               
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
        tif->tif_flags |= TIFF_BEENWRITING;
        return (1);
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
        tif->tif_flags |= TIFF_BEENWRITING;
        return (1);
@@ -535,21 +601,30 @@ TIFFWriteBufferSetup(TIFF* tif, tdata_t bp, tsize_t size)
 static int
 TIFFGrowStrips(TIFF* tif, int delta, const char* module)
 {
 static int
 TIFFGrowStrips(TIFF* tif, int delta, const char* module)
 {
-       TIFFDirectory *td = &tif->tif_dir;
+       TIFFDirectory   *td = &tif->tif_dir;
+       uint32          *new_stripoffset, *new_stripbytecount;
 
        assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
 
        assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
-       td->td_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
-           (td->td_nstrips + delta) * sizeof (uint32));
-       td->td_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
-           (td->td_nstrips + delta) * sizeof (uint32));
-       if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) {
+       new_stripoffset = (uint32*)_TIFFrealloc(td->td_stripoffset,
+               (td->td_nstrips + delta) * sizeof (uint32));
+       new_stripbytecount = (uint32*)_TIFFrealloc(td->td_stripbytecount,
+               (td->td_nstrips + delta) * sizeof (uint32));
+       if (new_stripoffset == NULL || new_stripbytecount == NULL) {
+               if (new_stripoffset)
+                       _TIFFfree(new_stripoffset);
+               if (new_stripbytecount)
+                       _TIFFfree(new_stripbytecount);
                td->td_nstrips = 0;
                TIFFError(module, "%s: No space to expand strip arrays",
                td->td_nstrips = 0;
                TIFFError(module, "%s: No space to expand strip arrays",
-                   tif->tif_name);
+                         tif->tif_name);
                return (0);
        }
                return (0);
        }
-       _TIFFmemset(td->td_stripoffset+td->td_nstrips, 0, delta*sizeof (uint32));
-       _TIFFmemset(td->td_stripbytecount+td->td_nstrips, 0, delta*sizeof (uint32));
+       td->td_stripoffset = new_stripoffset;
+       td->td_stripbytecount = new_stripbytecount;
+       _TIFFmemset(td->td_stripoffset + td->td_nstrips,
+                   0, delta*sizeof (uint32));
+       _TIFFmemset(td->td_stripbytecount + td->td_nstrips,
+                   0, delta*sizeof (uint32));
        td->td_nstrips += delta;
        return (1);
 }
        td->td_nstrips += delta;
        return (1);
 }
index 38e98a96c8efb09bc77772a4c22c2f771ea286ce..3539500cb48119f877478b1a330b5c9ccfcb186f 100644 (file)
  * directory ftp://ftp.uu.net/pub/archiving/zip/doc.  The library was
  * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
  */
  * directory ftp://ftp.uu.net/pub/archiving/zip/doc.  The library was
  * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
  */
-/* Watcom C++ (or its make utility) doesn't like long filenames */
-#ifdef __WATCOMC__
-#include "tif_pred.h"
-#else
 #include "tif_predict.h"
 #include "tif_predict.h"
-#endif
-
 #include "zlib.h"
 
 #include <stdio.h>
 #include "zlib.h"
 
 #include <stdio.h>
@@ -234,7 +228,8 @@ ZIPPostEncode(TIFF* tif)
                switch (state) {
                case Z_STREAM_END:
                case Z_OK:
                switch (state) {
                case Z_STREAM_END:
                case Z_OK:
-                   if (sp->stream.avail_out != tif->tif_rawdatasize) {
+                   if ((int)sp->stream.avail_out != (int)tif->tif_rawdatasize)
+                    {
                            tif->tif_rawcc =
                                tif->tif_rawdatasize - sp->stream.avail_out;
                            TIFFFlushData1(tif);
                            tif->tif_rawcc =
                                tif->tif_rawdatasize - sp->stream.avail_out;
                            TIFFFlushData1(tif);
@@ -318,7 +313,7 @@ TIFFInitZIP(TIFF* tif, int scheme)
 {
        ZIPState* sp;
 
 {
        ZIPState* sp;
 
-       assert(scheme == COMPRESSION_DEFLATE);
+       assert( (scheme == COMPRESSION_DEFLATE) || (scheme == COMPRESSION_ADOBE_DEFLATE));
 
        /*
         * Allocate state block so tag methods have storage to record values.
 
        /*
         * Allocate state block so tag methods have storage to record values.
@@ -337,10 +332,10 @@ TIFFInitZIP(TIFF* tif, int scheme)
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, zipFieldInfo, N(zipFieldInfo));
         * override parent get/set field methods.
         */
        _TIFFMergeFieldInfo(tif, zipFieldInfo, N(zipFieldInfo));
-       sp->vgetparent = tif->tif_vgetfield;
-       tif->tif_vgetfield = ZIPVGetField;      /* hook for codec tags */
-       sp->vsetparent = tif->tif_vsetfield;
-       tif->tif_vsetfield = ZIPVSetField;      /* hook for codec tags */
+       sp->vgetparent = tif->tif_tagmethods.vgetfield;
+       tif->tif_tagmethods.vgetfield = ZIPVGetField;   /* hook for codec tags */
+       sp->vsetparent = tif->tif_tagmethods.vsetfield;
+       tif->tif_tagmethods.vsetfield = ZIPVSetField;   /* hook for codec tags */
 
        /* Default values for codec-specific fields */
        sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */
 
        /* Default values for codec-specific fields */
        sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */
index e7ab091c47bb5324c4d4b266b85e64dcdb8b748c..eaa1b35f20bd073447ca3d2c69756ffeca8d79e1 100644 (file)
@@ -133,6 +133,22 @@ SOURCE=.\tif_codec.c
 # End Source File
 # Begin Source File
 
 # End Source File
 # Begin Source File
 
+SOURCE=.\tif_color.c
+
+!IF  "$(CFG)" == "tiff - Win32 Release"
+
+# ADD CPP /I ".."
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF  "$(CFG)" == "tiff - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF 
+
+# End Source File
+# Begin Source File
+
 SOURCE=.\tif_compress.c
 
 !IF  "$(CFG)" == "tiff - Win32 Release"
 SOURCE=.\tif_compress.c
 
 !IF  "$(CFG)" == "tiff - Win32 Release"
index 61d6aa408ee7a839734adbc862a9076433aace72..a73c07501effe1117d9d1cff25395fa51d6f0526 100644 (file)
 #define        TIFF_BIGENDIAN          0x4d4d
 #define        TIFF_LITTLEENDIAN       0x4949
 
 #define        TIFF_BIGENDIAN          0x4d4d
 #define        TIFF_LITTLEENDIAN       0x4949
 
-#ifndef _TIFF_DATA_TYPEDEFS_
+/*
+ * The so called TIFF types conflict with definitions from inttypes.h 
+ * included from sys/types.h on AIX (at least using VisualAge compiler). 
+ * We try to work around this by detecting this case.  Defining 
+ * _TIFF_DATA_TYPEDEFS_ short circuits the later definitions in tiff.h, and
+ * we will in the holes not provided for by inttypes.h. 
+ *
+ * See http://bugzilla.remotesensing.org/show_bug.cgi?id=39
+ */
+#if defined(_H_INTTYPES) && defined(_ALL_SOURCE) && defined(USING_VISUALAGE)
+
 #define _TIFF_DATA_TYPEDEFS_
 #define _TIFF_DATA_TYPEDEFS_
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef unsigned int uint32;
+
+#endif
+
 /*
  * Intrinsic data types required by the file format:
  *
 /*
  * Intrinsic data types required by the file format:
  *
  * 32-bit quantities   int32/uint32
  * strings             unsigned char*
  */
  * 32-bit quantities   int32/uint32
  * strings             unsigned char*
  */
-#ifndef _AIX43 /* int{8,16,32} already defined on AIX */
+#ifndef _TIFF_DATA_TYPEDEFS_
+#define _TIFF_DATA_TYPEDEFS_
+
 #ifdef __STDC__
 typedef        signed char int8;       /* NB: non-ANSI compilers may not grok */
 #else
 typedef        char int8;
 #endif
 #ifdef __STDC__
 typedef        signed char int8;       /* NB: non-ANSI compilers may not grok */
 #else
 typedef        char int8;
 #endif
-typedef        short int16;
-#endif
 typedef        unsigned char uint8;
 typedef        unsigned char uint8;
+typedef        short int16;
 typedef        unsigned short uint16;  /* sizeof (uint16) must == 2 */
 typedef        unsigned short uint16;  /* sizeof (uint16) must == 2 */
-#if defined(__alpha) || (defined(_MIPS_SZLONG) && _MIPS_SZLONG == 64)
+#if defined(__alpha) || (defined(_MIPS_SZLONG) && _MIPS_SZLONG == 64) || defined(__LP64__) || defined(__arch64__)
 typedef        int int32;
 typedef        unsigned int uint32;    /* sizeof (uint32) must == 4 */
 #else
 typedef        int int32;
 typedef        unsigned int uint32;    /* sizeof (uint32) must == 4 */
 #else
-#ifndef _AIX43
 typedef        long int32;
 typedef        long int32;
-#endif
 typedef        unsigned long uint32;   /* sizeof (uint32) must == 4 */
 #endif
 #endif /* _TIFF_DATA_TYPEDEFS_ */
 typedef        unsigned long uint32;   /* sizeof (uint32) must == 4 */
 #endif
 #endif /* _TIFF_DATA_TYPEDEFS_ */
@@ -101,10 +116,10 @@ typedef   struct {
  * offset field.
  */
 typedef        struct {
  * offset field.
  */
 typedef        struct {
-       uint16  tdir_tag;       /* see below */
-       uint16  tdir_type;      /* data type; see below */
-       uint32  tdir_count;     /* number of items; length in spec */
-       uint32  tdir_offset;    /* byte offset to field data */
+       uint16          tdir_tag;       /* see below */
+       uint16          tdir_type;      /* data type; see below */
+       uint32          tdir_count;     /* number of items; length in spec */
+       uint32          tdir_offset;    /* byte offset to field data */
 } TIFFDirEntry;
 
 /*
 } TIFFDirEntry;
 
 /*
@@ -133,7 +148,8 @@ typedef     enum {
        TIFF_SLONG      = 9,    /* !32-bit signed integer */
        TIFF_SRATIONAL  = 10,   /* !64-bit signed fraction */
        TIFF_FLOAT      = 11,   /* !32-bit IEEE floating point */
        TIFF_SLONG      = 9,    /* !32-bit signed integer */
        TIFF_SRATIONAL  = 10,   /* !64-bit signed fraction */
        TIFF_FLOAT      = 11,   /* !32-bit IEEE floating point */
-       TIFF_DOUBLE     = 12    /* !64-bit IEEE floating point */
+       TIFF_DOUBLE     = 12,   /* !64-bit IEEE floating point */
+       TIFF_IFD        = 13    /* %32-bit unsigned integer (offset) */
 } TIFFDataType;
 
 /*
 } TIFFDataType;
 
 /*
@@ -154,15 +170,17 @@ typedef   enum {
 #define            COMPRESSION_NONE            1       /* dump mode */
 #define            COMPRESSION_CCITTRLE        2       /* CCITT modified Huffman RLE */
 #define            COMPRESSION_CCITTFAX3       3       /* CCITT Group 3 fax encoding */
 #define            COMPRESSION_NONE            1       /* dump mode */
 #define            COMPRESSION_CCITTRLE        2       /* CCITT modified Huffman RLE */
 #define            COMPRESSION_CCITTFAX3       3       /* CCITT Group 3 fax encoding */
+#define     COMPRESSION_CCITT_T4        3       /* CCITT T.4 (TIFF 6 name) */
 #define            COMPRESSION_CCITTFAX4       4       /* CCITT Group 4 fax encoding */
 #define            COMPRESSION_CCITTFAX4       4       /* CCITT Group 4 fax encoding */
-#define            COMPRESSION_LZW             5       /* Lempel-Ziv  & Welch */
+#define     COMPRESSION_CCITT_T6        4       /* CCITT T.6 (TIFF 6 name) */
+#define            COMPRESSION_LZW             5       /* Lempel-Ziv  & Welch */
 #define            COMPRESSION_OJPEG           6       /* !6.0 JPEG */
 #define            COMPRESSION_JPEG            7       /* %JPEG DCT compression */
 #define            COMPRESSION_NEXT            32766   /* NeXT 2-bit RLE */
 #define            COMPRESSION_CCITTRLEW       32771   /* #1 w/ word alignment */
 #define            COMPRESSION_PACKBITS        32773   /* Macintosh RLE */
 #define            COMPRESSION_THUNDERSCAN     32809   /* ThunderScan RLE */
 #define            COMPRESSION_OJPEG           6       /* !6.0 JPEG */
 #define            COMPRESSION_JPEG            7       /* %JPEG DCT compression */
 #define            COMPRESSION_NEXT            32766   /* NeXT 2-bit RLE */
 #define            COMPRESSION_CCITTRLEW       32771   /* #1 w/ word alignment */
 #define            COMPRESSION_PACKBITS        32773   /* Macintosh RLE */
 #define            COMPRESSION_THUNDERSCAN     32809   /* ThunderScan RLE */
-/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@etsinc.com) */
+/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
 #define            COMPRESSION_IT8CTPAD        32895   /* IT8 CT w/padding */
 #define            COMPRESSION_IT8LW           32896   /* IT8 Linework RLE */
 #define            COMPRESSION_IT8MP           32897   /* IT8 Monochrome picture */
 #define            COMPRESSION_IT8CTPAD        32895   /* IT8 CT w/padding */
 #define            COMPRESSION_IT8LW           32896   /* IT8 Linework RLE */
 #define            COMPRESSION_IT8MP           32897   /* IT8 Monochrome picture */
@@ -171,11 +189,13 @@ typedef   enum {
 #define     COMPRESSION_PIXARFILM      32908   /* Pixar companded 10bit LZW */
 #define            COMPRESSION_PIXARLOG        32909   /* Pixar companded 11bit ZIP */
 #define            COMPRESSION_DEFLATE         32946   /* Deflate compression */
 #define     COMPRESSION_PIXARFILM      32908   /* Pixar companded 10bit LZW */
 #define            COMPRESSION_PIXARLOG        32909   /* Pixar companded 11bit ZIP */
 #define            COMPRESSION_DEFLATE         32946   /* Deflate compression */
+#define     COMPRESSION_ADOBE_DEFLATE   8       /* Deflate compression, as recognized by Adobe */
 /* compression code 32947 is reserved for Oceana Matrix <dev@oceana.com> */
 #define     COMPRESSION_DCS             32947   /* Kodak DCS encoding */
 #define            COMPRESSION_JBIG            34661   /* ISO JBIG */
 #define     COMPRESSION_SGILOG         34676   /* SGI Log Luminance RLE */
 #define     COMPRESSION_SGILOG24       34677   /* SGI Log 24-bit packed */
 /* compression code 32947 is reserved for Oceana Matrix <dev@oceana.com> */
 #define     COMPRESSION_DCS             32947   /* Kodak DCS encoding */
 #define            COMPRESSION_JBIG            34661   /* ISO JBIG */
 #define     COMPRESSION_SGILOG         34676   /* SGI Log Luminance RLE */
 #define     COMPRESSION_SGILOG24       34677   /* SGI Log 24-bit packed */
+#define     COMPRESSION_JP2000          34712   /* Leadtools JPEG2000 */
 #define        TIFFTAG_PHOTOMETRIC             262     /* photometric interpretation */
 #define            PHOTOMETRIC_MINISWHITE      0       /* min value is white */
 #define            PHOTOMETRIC_MINISBLACK      1       /* min value is black */
 #define        TIFFTAG_PHOTOMETRIC             262     /* photometric interpretation */
 #define            PHOTOMETRIC_MINISWHITE      0       /* min value is white */
 #define            PHOTOMETRIC_MINISBLACK      1       /* min value is black */
@@ -185,6 +205,8 @@ typedef     enum {
 #define            PHOTOMETRIC_SEPARATED       5       /* !color separations */
 #define            PHOTOMETRIC_YCBCR           6       /* !CCIR 601 */
 #define            PHOTOMETRIC_CIELAB          8       /* !1976 CIE L*a*b* */
 #define            PHOTOMETRIC_SEPARATED       5       /* !color separations */
 #define            PHOTOMETRIC_YCBCR           6       /* !CCIR 601 */
 #define            PHOTOMETRIC_CIELAB          8       /* !1976 CIE L*a*b* */
+#define            PHOTOMETRIC_ICCLAB          9       /* ICC L*a*b* [Adobe TIFF Technote 4] */
+#define            PHOTOMETRIC_ITULAB          10      /* ITU L*a*b* */
 #define     PHOTOMETRIC_LOGL           32844   /* CIE Log2(L) */
 #define     PHOTOMETRIC_LOGLUV         32845   /* CIE Log2(L) (u',v') */
 #define        TIFFTAG_THRESHHOLDING           263     /* +thresholding used on data */
 #define     PHOTOMETRIC_LOGL           32844   /* CIE Log2(L) */
 #define     PHOTOMETRIC_LOGLUV         32845   /* CIE Log2(L) (u',v') */
 #define        TIFFTAG_THRESHHOLDING           263     /* +thresholding used on data */
@@ -233,10 +255,12 @@ typedef   enum {
 #define            GRAYRESPONSEUNIT_100000S    5       /* hundred-thousandths */
 #define        TIFFTAG_GRAYRESPONSECURVE       291     /* $gray scale response curve */
 #define        TIFFTAG_GROUP3OPTIONS           292     /* 32 flag bits */
 #define            GRAYRESPONSEUNIT_100000S    5       /* hundred-thousandths */
 #define        TIFFTAG_GRAYRESPONSECURVE       291     /* $gray scale response curve */
 #define        TIFFTAG_GROUP3OPTIONS           292     /* 32 flag bits */
+#define        TIFFTAG_T4OPTIONS               292     /* TIFF 6.0 proper name alias */
 #define            GROUP3OPT_2DENCODING        0x1     /* 2-dimensional coding */
 #define            GROUP3OPT_UNCOMPRESSED      0x2     /* data not compressed */
 #define            GROUP3OPT_FILLBITS          0x4     /* fill to byte boundary */
 #define        TIFFTAG_GROUP4OPTIONS           293     /* 32 flag bits */
 #define            GROUP3OPT_2DENCODING        0x1     /* 2-dimensional coding */
 #define            GROUP3OPT_UNCOMPRESSED      0x2     /* data not compressed */
 #define            GROUP3OPT_FILLBITS          0x4     /* fill to byte boundary */
 #define        TIFFTAG_GROUP4OPTIONS           293     /* 32 flag bits */
+#define TIFFTAG_T6OPTIONS               293     /* TIFF 6.0 proper name */
 #define            GROUP4OPT_UNCOMPRESSED      0x2     /* data not compressed */
 #define        TIFFTAG_RESOLUTIONUNIT          296     /* units of resolutions */
 #define            RESUNIT_NONE                1       /* no meaningful units */
 #define            GROUP4OPT_UNCOMPRESSED      0x2     /* data not compressed */
 #define        TIFFTAG_RESOLUTIONUNIT          296     /* units of resolutions */
 #define            RESUNIT_NONE                1       /* no meaningful units */
@@ -271,7 +295,8 @@ typedef     enum {
 #define        TIFFTAG_CONSECUTIVEBADFAXLINES  328     /* max consecutive bad lines */
 #define        TIFFTAG_SUBIFD                  330     /* subimage descriptors */
 #define        TIFFTAG_INKSET                  332     /* !inks in separated image */
 #define        TIFFTAG_CONSECUTIVEBADFAXLINES  328     /* max consecutive bad lines */
 #define        TIFFTAG_SUBIFD                  330     /* subimage descriptors */
 #define        TIFFTAG_INKSET                  332     /* !inks in separated image */
-#define            INKSET_CMYK                 1       /* !cyan-magenta-yellow-black */
+#define            INKSET_CMYK                 1       /* !cyan-magenta-yellow-black color */
+#define            INKSET_MULTIINK             2       /* !multi-ink or hi-fi color */
 #define        TIFFTAG_INKNAMES                333     /* !ascii names of inks */
 #define        TIFFTAG_NUMBEROFINKS            334     /* !number of inks */
 #define        TIFFTAG_DOTRANGE                336     /* !0% and 100% dot codes */
 #define        TIFFTAG_INKNAMES                333     /* !ascii names of inks */
 #define        TIFFTAG_NUMBEROFINKS            334     /* !number of inks */
 #define        TIFFTAG_DOTRANGE                336     /* !0% and 100% dot codes */
@@ -285,9 +310,16 @@ typedef    enum {
 #define            SAMPLEFORMAT_INT            2       /* !signed integer data */
 #define            SAMPLEFORMAT_IEEEFP         3       /* !IEEE floating point data */
 #define            SAMPLEFORMAT_VOID           4       /* !untyped data */
 #define            SAMPLEFORMAT_INT            2       /* !signed integer data */
 #define            SAMPLEFORMAT_IEEEFP         3       /* !IEEE floating point data */
 #define            SAMPLEFORMAT_VOID           4       /* !untyped data */
+#define            SAMPLEFORMAT_COMPLEXINT     5       /* !complex signed int */
+#define            SAMPLEFORMAT_COMPLEXIEEEFP  6       /* !complex ieee floating */
 #define        TIFFTAG_SMINSAMPLEVALUE         340     /* !variable MinSampleValue */
 #define        TIFFTAG_SMAXSAMPLEVALUE         341     /* !variable MaxSampleValue */
 #define        TIFFTAG_SMINSAMPLEVALUE         340     /* !variable MinSampleValue */
 #define        TIFFTAG_SMAXSAMPLEVALUE         341     /* !variable MaxSampleValue */
+#define        TIFFTAG_CLIPPATH                343     /* %ClipPath [Adobe TIFF technote 2] */
+#define        TIFFTAG_XCLIPPATHUNITS  344     /* %XClipPathUnits [Adobe TIFF technote 2] */
+#define        TIFFTAG_YCLIPPATHUNITS  344     /* %YClipPathUnits [Adobe TIFF technote 2] */
+#define        TIFFTAG_INDEXED                 345     /* %Indexed [Adobe TIFF Technote 3] */
 #define        TIFFTAG_JPEGTABLES              347     /* %JPEG table stream */
 #define        TIFFTAG_JPEGTABLES              347     /* %JPEG table stream */
+#define        TIFFTAG_OPIPROXY                351     /* %OPI Proxy [Adobe TIFF technote] */
 /*
  * Tags 512-521 are obsoleted by Technical Note #2
  * which specifies a revised JPEG-in-TIFF scheme.
 /*
  * Tags 512-521 are obsoleted by Technical Note #2
  * which specifies a revised JPEG-in-TIFF scheme.
@@ -309,6 +341,8 @@ typedef     enum {
 #define            YCBCRPOSITION_CENTERED      1       /* !as in PostScript Level 2 */
 #define            YCBCRPOSITION_COSITED       2       /* !as in CCIR 601-1 */
 #define        TIFFTAG_REFERENCEBLACKWHITE     532     /* !colorimetry info */
 #define            YCBCRPOSITION_CENTERED      1       /* !as in PostScript Level 2 */
 #define            YCBCRPOSITION_COSITED       2       /* !as in CCIR 601-1 */
 #define        TIFFTAG_REFERENCEBLACKWHITE     532     /* !colorimetry info */
+#define        TIFFTAG_XMLPACKET               700             /* %XML packet [Adobe XMP technote 9-14-02] (dkelly@apago.com) */
+#define TIFFTAG_OPIIMAGEID             32781   /* %OPI ImageID [Adobe TIFF technote] */
 /* tags 32952-32956 are private tags registered to Island Graphics */
 #define TIFFTAG_REFPTS                 32953   /* image reference points */
 #define TIFFTAG_REGIONTACKPOINT                32954   /* region-xform tack point */
 /* tags 32952-32956 are private tags registered to Island Graphics */
 #define TIFFTAG_REFPTS                 32953   /* image reference points */
 #define TIFFTAG_REGIONTACKPOINT                32954   /* region-xform tack point */
@@ -329,13 +363,21 @@ typedef   enum {
  */
 #define TIFFTAG_PIXAR_IMAGEFULLWIDTH    33300   /* full image size in x */
 #define TIFFTAG_PIXAR_IMAGEFULLLENGTH   33301   /* full image size in y */
  */
 #define TIFFTAG_PIXAR_IMAGEFULLWIDTH    33300   /* full image size in x */
 #define TIFFTAG_PIXAR_IMAGEFULLLENGTH   33301   /* full image size in y */
+ /* Tags 33302-33306 are used to identify special image modes and data
+  * used by Pixar's texture formats.
+  */
+#define TIFFTAG_PIXAR_TEXTUREFORMAT    33302   /* texture map format */
+#define TIFFTAG_PIXAR_WRAPMODES                33303   /* s & t wrap modes */
+#define TIFFTAG_PIXAR_FOVCOT           33304   /* cotan(fov) for env. maps */
+#define TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN 33305
+#define TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA 33306
 /* tag 33405 is a private tag registered to Eastman Kodak */
 #define TIFFTAG_WRITERSERIALNUMBER      33405   /* device serial number */
 /* tag 33432 is listed in the 6.0 spec w/ unknown ownership */
 #define        TIFFTAG_COPYRIGHT               33432   /* copyright string */
 /* IPTC TAG from RichTIFF specifications */
 #define TIFFTAG_RICHTIFFIPTC    33723
 /* tag 33405 is a private tag registered to Eastman Kodak */
 #define TIFFTAG_WRITERSERIALNUMBER      33405   /* device serial number */
 /* tag 33432 is listed in the 6.0 spec w/ unknown ownership */
 #define        TIFFTAG_COPYRIGHT               33432   /* copyright string */
 /* IPTC TAG from RichTIFF specifications */
 #define TIFFTAG_RICHTIFFIPTC    33723
-/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@etsinc.com) */
+/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
 #define TIFFTAG_IT8SITE                        34016   /* site name */
 #define TIFFTAG_IT8COLORSEQUENCE       34017   /* color seq. [RGB,CMYK,etc] */
 #define TIFFTAG_IT8HEADER              34018   /* DDES Header */
 #define TIFFTAG_IT8SITE                        34016   /* site name */
 #define TIFFTAG_IT8COLORSEQUENCE       34017   /* color seq. [RGB,CMYK,etc] */
 #define TIFFTAG_IT8HEADER              34018   /* DDES Header */
@@ -350,6 +392,9 @@ typedef     enum {
 #define TIFFTAG_IT8PIXELINTENSITYRANGE 34027   /* MP pixel intensity value */
 #define TIFFTAG_IT8TRANSPARENCYINDICATOR 34028 /* HC transparency switch */
 #define TIFFTAG_IT8COLORCHARACTERIZATION 34029 /* color character. table */
 #define TIFFTAG_IT8PIXELINTENSITYRANGE 34027   /* MP pixel intensity value */
 #define TIFFTAG_IT8TRANSPARENCYINDICATOR 34028 /* HC transparency switch */
 #define TIFFTAG_IT8COLORCHARACTERIZATION 34029 /* color character. table */
+#define TIFFTAG_IT8HCUSAGE                     34030   /* HC usage indicator */
+#define TIFFTAG_IT8TRAPINDICATOR       34031   /* Trapping indicator (untrapped=0, trapped=1) */
+#define TIFFTAG_IT8CMYKEQUIVALENT      34032   /* CMYK color equivalents */
 /* tags 34232-34236 are private tags registered to Texas Instruments */
 #define TIFFTAG_FRAMECOUNT              34232   /* Sequence Frame Count */
 /* tag 34750 is a private tag registered to Adobe? */
 /* tags 34232-34236 are private tags registered to Texas Instruments */
 #define TIFFTAG_FRAMECOUNT              34232   /* Sequence Frame Count */
 /* tag 34750 is a private tag registered to Adobe? */
@@ -431,4 +476,7 @@ typedef     enum {
 #define     SGILOGDATAFMT_16BIT                1       /* 16-bit samples */
 #define     SGILOGDATAFMT_RAW          2       /* uninterpreted data */
 #define     SGILOGDATAFMT_8BIT         3       /* 8-bit RGB monitor values */
 #define     SGILOGDATAFMT_16BIT                1       /* 16-bit samples */
 #define     SGILOGDATAFMT_RAW          2       /* uninterpreted data */
 #define     SGILOGDATAFMT_8BIT         3       /* 8-bit RGB monitor values */
+#define TIFFTAG_SGILOGENCODE           65561 /* SGILog data encoding control*/
+#define     SGILOGENCODE_NODITHER      0     /* do not dither encoded values*/
+#define     SGILOGENCODE_RANDITHER     1     /* randomly dither encd values */
 #endif /* _TIFF_ */
 #endif /* _TIFF_ */
index 89c2a57c19e8a8d29470520ce1410152c2f7f40a..86c0a15e579bb183e89972f1d6c42bf653d1e3c3 100644 (file)
 #endif
 
 #if defined(__MWERKS__) || defined(THINK_C)
 #endif
 
 #if defined(__MWERKS__) || defined(THINK_C)
-#ifdef __MACH__
-#include <sys/types.h>
-#else
 #include <unix.h>
 #include <math.h>
 #endif
 #include <unix.h>
 #include <math.h>
 #endif
-#endif
-
-#if defined (__SC__) && !defined (__DMC__)
-    #define __SYMANTEC__
-#endif
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
-#if defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__)
+#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
 #include <types.h>
 #elif !defined(__MWERKS__) && !defined(THINK_C) && !defined(__acornriscos) && !defined(applec)
 #include <sys/types.h>
 #include <types.h>
 #elif !defined(__MWERKS__) && !defined(THINK_C) && !defined(__acornriscos) && !defined(applec)
 #include <sys/types.h>
  * additional includes are also done to pull in the
  * appropriate definitions we're looking for.
  */
  * additional includes are also done to pull in the
  * appropriate definitions we're looking for.
  */
-#if defined(__MWERKS__) || defined(THINK_C) || defined(__PPCC__) || defined(__SYMANTEC__) || defined(__MRC__)
+#if defined(__MWERKS__) || defined(THINK_C) || defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
 #include <stdlib.h>
 #include <stdlib.h>
-#ifndef __MACH__
 #define        BSDTYPES
 #define        BSDTYPES
-#endif
 #define        HAVE_UNISTD_H   0
 #define        HAVE_UNISTD_H   0
-#elif defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
-#define BSDTYPES
-#elif defined(__DJGPP__)
-#define BSDTYPES
+#elif (defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) || defined(_WIN32)) && !defined(unix)
+#define        BSDTYPES
 #elif defined(OS2_16) || defined(OS2_32)
 #define        BSDTYPES
 #elif defined(__acornriscos)
 #elif defined(OS2_16) || defined(OS2_32)
 #define        BSDTYPES
 #elif defined(__acornriscos)
  * then define BSDTYPES in your Makefile.
  */
 #if defined(BSDTYPES)
  * then define BSDTYPES in your Makefile.
  */
 #if defined(BSDTYPES)
+# ifndef _BSDTYPES_DEFINED
+#  ifndef __u_char_defined
 typedef        unsigned char u_char;
 typedef        unsigned short u_short;
 typedef        unsigned int u_int;
 typedef        unsigned long u_long;
 typedef        unsigned char u_char;
 typedef        unsigned short u_short;
 typedef        unsigned int u_int;
 typedef        unsigned long u_long;
-#endif
+#   define __u_char_defined
+#  endif /* __u_char_defined */
+#  define _BSDTYPES_DEFINED
+# endif /* _BSDTYPES_DEFINED */
+#endif /* BSDTYPES */
 
 /*
  * dblparam_t is the type that a double precision
 
 /*
  * dblparam_t is the type that a double precision
@@ -143,7 +137,7 @@ typedef     unsigned long u_long;
  * stack (when coerced by the compiler).
  */
 /* Note: on MacPowerPC "extended" is undefined. So only use it for 68K-Macs */
  * stack (when coerced by the compiler).
  */
 /* Note: on MacPowerPC "extended" is undefined. So only use it for 68K-Macs */
-#if defined(__SYMANTEC__) || defined(THINK_C)
+#if defined(__SC__) || defined(THINK_C)
 typedef extended dblparam_t;
 #else
 typedef double dblparam_t;
 typedef extended dblparam_t;
 #else
 typedef double dblparam_t;
index 7e2d6701f8fab767d6408b8f3ae46d94e082ae5e..7ca5b081b1e308774bca4a04224590c182a49a9d 100644 (file)
@@ -33,7 +33,7 @@
  * #defines on the command line, this file can be edited to
  * configure the library.  Otherwise, one can override portability
  * and configuration-related definitions from a Makefile or command
  * #defines on the command line, this file can be edited to
  * configure the library.  Otherwise, one can override portability
  * and configuration-related definitions from a Makefile or command
- * line by defining FEATURE_SUPPORT and COMPRESSION_SUPPORT (see below).
+ * line by defining COMPRESSION_SUPPORT (see below).
  */
 
 /*
  */
 
 /*
@@ -51,6 +51,8 @@
  * HOST_BIGENDIAN      native cpu byte order: 1 if big-endian (Motorola)
  *                     or 0 if little-endian (Intel); this may be used
  *                     in codecs to optimize code
  * HOST_BIGENDIAN      native cpu byte order: 1 if big-endian (Motorola)
  *                     or 0 if little-endian (Intel); this may be used
  *                     in codecs to optimize code
+ * USE_64BIT_API       set to 1 if tif_unix.c should use lseek64(),
+ *                      fstat64() and stat64 allowing 2-4GB files.
  */
 #ifndef HAVE_IEEEFP
 #define        HAVE_IEEEFP     1
  */
 #ifndef HAVE_IEEEFP
 #define        HAVE_IEEEFP     1
 #define        HOST_BIGENDIAN  1
 #endif
 
 #define        HOST_BIGENDIAN  1
 #endif
 
-#ifndef FEATURE_SUPPORT
-/*
- * Feature support definitions:
- *
- *    COLORIMETRY_SUPPORT enable support for 6.0 colorimetry tags
- *    YCBCR_SUPPORT    enable support for 6.0 YCbCr tags
- *    CMYK_SUPPORT     enable support for 6.0 CMYK tags
- *    ICC_SUPPORT      enable support for ICC profile tag
- *    PHOTOSHOP_SUPPORT enable support for PHOTOSHOP resource tag
- *    IPTC_SUPPORT  enable support for RichTIFF IPTC tag
- */
-#define        COLORIMETRY_SUPPORT
-#define        YCBCR_SUPPORT
-#define        CMYK_SUPPORT
-#define        ICC_SUPPORT
-#define PHOTOSHOP_SUPPORT
-#define IPTC_SUPPORT
-#endif /* FEATURE_SUPPORT */
+#ifndef USE_64BIT_API
+#  define USE_64BIT_API        0
+#endif
 
 #ifndef COMPRESSION_SUPPORT
 /*
 
 #ifndef COMPRESSION_SUPPORT
 /*
@@ -91,7 +78,7 @@
  *    THUNDER_SUPPORT  enable support for ThunderScan 4-bit RLE algorithm
  *    NEXT_SUPPORT     enable support for NeXT 2-bit RLE algorithm
  *    OJPEG_SUPPORT    enable support for 6.0-style JPEG DCT algorithms
  *    THUNDER_SUPPORT  enable support for ThunderScan 4-bit RLE algorithm
  *    NEXT_SUPPORT     enable support for NeXT 2-bit RLE algorithm
  *    OJPEG_SUPPORT    enable support for 6.0-style JPEG DCT algorithms
- *                     (no builtin support, only a codec hook)
+ *                     (requires IJG software)
  *    JPEG_SUPPORT     enable support for post-6.0-style JPEG DCT algorithms
  *                     (requires freely available IJG software, see tif_jpeg.c)
  *    ZIP_SUPPORT      enable support for Deflate algorithm
  *    JPEG_SUPPORT     enable support for post-6.0-style JPEG DCT algorithms
  *                     (requires freely available IJG software, see tif_jpeg.c)
  *    ZIP_SUPPORT      enable support for Deflate algorithm
  *                     or not to convert single-strip uncompressed images
  *                     to mutiple strips of ~8Kb--to reduce memory use)
  * SUBIFD_SUPPORT      enable support for SubIFD tag (thumbnails and such)
  *                     or not to convert single-strip uncompressed images
  *                     to mutiple strips of ~8Kb--to reduce memory use)
  * SUBIFD_SUPPORT      enable support for SubIFD tag (thumbnails and such)
+ * DEFAULT_EXTRASAMPLE_AS_ALPHA
+ *                      The RGBA interface will treat a fourth sample with
+ *                      no EXTRASAMPLE_ value as being ASSOCALPHA.  Many
+ *                      packages produce RGBA files but don't mark the alpha
+ *                      properly.
+ * CHECK_JPEG_YCBCR_SUBSAMPLING
+ *                      Enable picking up YCbCr subsampling info from the
+ *                      JPEG data stream to support files lacking the tag.
+ *                      See Bug 168 in Bugzilla, and JPEGFixupTestSubsampling()
+ *                      for details. 
  */
 #ifndef STRIPCHOP_DEFAULT
 #define        STRIPCHOP_DEFAULT       TIFF_STRIPCHOP  /* default is to enable */
  */
 #ifndef STRIPCHOP_DEFAULT
 #define        STRIPCHOP_DEFAULT       TIFF_STRIPCHOP  /* default is to enable */
 #ifndef SUBIFD_SUPPORT
 #define        SUBIFD_SUPPORT          1       /* enable SubIFD tag (330) support */
 #endif
 #ifndef SUBIFD_SUPPORT
 #define        SUBIFD_SUPPORT          1       /* enable SubIFD tag (330) support */
 #endif
+#ifndef DEFAULT_EXTRASAMPLE_AS_ALPHA
+#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1
+#endif
+#ifndef CHECK_JPEG_YCBCR_SUBSAMPLING
+#define CHECK_JPEG_YCBCR_SUBSAMPLING 1
+#endif
+
+/*
+ * Feature support definitions.
+ * XXX: These macros are obsoleted. Don't use them in your apps!
+ * Macros stays here for backward compatibility and should be always defined.
+ */
+#define        COLORIMETRY_SUPPORT
+#define        YCBCR_SUPPORT
+#define        CMYK_SUPPORT
+#define        ICC_SUPPORT
+#define PHOTOSHOP_SUPPORT
+#define IPTC_SUPPORT
+
 #endif /* _TIFFCONF_ */
 #endif /* _TIFFCONF_ */
index 1ce1a415cb80606967598a313d6fcad04d3e250e..778f2f594117d28c75ac52800d2b5edd0dd461e5 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
  * TIFF I/O Library Definitions.
  */
 #include "tiff.h"
  * TIFF I/O Library Definitions.
  */
 #include "tiff.h"
-
-/*
- * This define can be used in code that requires
- * compilation-related definitions specific to a
- * version or versions of the library.  Runtime
- * version checking should be done based on the
- * string returned by TIFFGetVersion.
- */
-#define        TIFFLIB_VERSION 19970127        /* January 27, 1997 */
+#include "tiffvers.h"
 
 /*
  * TIFF is defined as an incomplete type to hide the
 
 /*
  * TIFF is defined as an incomplete type to hide the
@@ -63,7 +55,8 @@ typedef       struct tiff TIFF;
  * NB: tsize_t is int32 and not uint32 because some functions
  *     return -1.
  * NB: toff_t is not off_t for many reasons; TIFFs max out at
  * NB: tsize_t is int32 and not uint32 because some functions
  *     return -1.
  * NB: toff_t is not off_t for many reasons; TIFFs max out at
- *     32-bit file offsets being the most important
+ *     32-bit file offsets being the most important, and to ensure
+ *     that it is unsigned, rather than signed.
  */
 typedef        uint32 ttag_t;          /* directory tag */
 typedef        uint16 tdir_t;          /* directory index */
  */
 typedef        uint32 ttag_t;          /* directory tag */
 typedef        uint16 tdir_t;          /* directory index */
@@ -72,12 +65,27 @@ typedef     uint32 tstrip_t;        /* strip number */
 typedef uint32 ttile_t;                /* tile number */
 typedef        int32 tsize_t;          /* i/o size in bytes */
 typedef        void* tdata_t;          /* image data ref */
 typedef uint32 ttile_t;                /* tile number */
 typedef        int32 tsize_t;          /* i/o size in bytes */
 typedef        void* tdata_t;          /* image data ref */
-typedef        int32 toff_t;           /* file offset */
+typedef        uint32 toff_t;          /* file offset */
 
 #if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
 #define __WIN32__
 #endif
 
 #if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
 #define __WIN32__
 #endif
+
+/*
+ * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c
+ * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c).
+ *
+ * By default tif_win32.c is assumed on windows if not using the cygwin
+ * environment.
+ */
+
 #if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
 #if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
+#  if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && !defined(USE_WIN32_FILIO)
+#    define USE_WIN32_FILEIO
+#  endif
+#endif
+
+#if defined(USE_WIN32_FILEIO)
 #include <windows.h>
 #ifdef __WIN32__
 DECLARE_HANDLE(thandle_t);     /* Win32 file handle */
 #include <windows.h>
 #ifdef __WIN32__
 DECLARE_HANDLE(thandle_t);     /* Win32 file handle */
@@ -88,12 +96,6 @@ typedef      HFILE thandle_t;        /* client data handle */
 typedef        void* thandle_t;        /* client data handle */
 #endif
 
 typedef        void* thandle_t;        /* client data handle */
 #endif
 
-#if defined(__VISAGECPP__)
-#define LINKAGEMODE _Optlink
-#else
-#define LINKAGEMODE
-#endif
-
 #ifndef NULL
 #define        NULL    0
 #endif
 #ifndef NULL
 #define        NULL    0
 #endif
@@ -112,39 +114,92 @@ typedef   void* thandle_t;        /* client data handle */
 #define        TIFFPRINT_JPEGACTABLES  0x200           /* JPEG AC tables */
 #define        TIFFPRINT_JPEGDCTABLES  0x200           /* JPEG DC tables */
 
 #define        TIFFPRINT_JPEGACTABLES  0x200           /* JPEG AC tables */
 #define        TIFFPRINT_JPEGDCTABLES  0x200           /* JPEG DC tables */
 
+/* 
+ * Colour conversion stuff
+ */
+
+/* reference white */
+#define D65_X0 (95.0470F)
+#define D65_Y0 (100.0F)
+#define D65_Z0 (108.8827F)
+
+#define D50_X0 (96.4250F)
+#define D50_Y0 (100.0F)
+#define D50_Z0 (82.4680F)
+
+/* Structure for holding information about a display device. */
+
+typedef        unsigned char TIFFRGBValue;             /* 8-bit samples */
+
+typedef struct {
+       float d_mat[3][3];              /* XYZ -> luminance matrix */
+       float d_YCR;                    /* Light o/p for reference white */
+       float d_YCG;
+       float d_YCB;
+       uint32 d_Vrwr;                  /* Pixel values for ref. white */
+       uint32 d_Vrwg;
+       uint32 d_Vrwb;
+       float d_Y0R;                    /* Residual light for black pixel */
+       float d_Y0G;
+       float d_Y0B;
+       float d_gammaR;                 /* Gamma values for the three guns */
+       float d_gammaG;
+       float d_gammaB;
+} TIFFDisplay;
+
+typedef struct {                               /* YCbCr->RGB support */
+       TIFFRGBValue* clamptab;                 /* range clamping table */
+       int*    Cr_r_tab;
+       int*    Cb_b_tab;
+       int32*  Cr_g_tab;
+       int32*  Cb_g_tab;
+        int32*  Y_tab;
+} TIFFYCbCrToRGB;
+
+typedef struct {                               /* CIE Lab 1976->RGB support */
+       int     range;                          /* Size of conversion table */
+#define CIELABTORGB_TABLE_RANGE 1500
+       float   rstep, gstep, bstep;
+       float   X0, Y0, Z0;                     /* Reference white point */
+       TIFFDisplay display;
+       float   Yr2r[CIELABTORGB_TABLE_RANGE + 1];  /* Conversion of Yr to r */
+       float   Yg2g[CIELABTORGB_TABLE_RANGE + 1];  /* Conversion of Yg to g */
+       float   Yb2b[CIELABTORGB_TABLE_RANGE + 1];  /* Conversion of Yb to b */
+} TIFFCIELabToRGB;
+
+extern int TIFFCIELabToRGBInit(TIFFCIELabToRGB*, TIFFDisplay *, float*);
+extern void TIFFCIELabToXYZ(TIFFCIELabToRGB *, uint32, int32, int32,
+                           float *, float *, float *);
+extern void TIFFXYZToRGB(TIFFCIELabToRGB *, float, float, float,
+                        uint32 *, uint32 *, uint32 *);
+
+extern int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB*, float*, float*);
+extern void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *, uint32, int32, int32,
+                          uint32 *, uint32 *, uint32 *);
+
 /*
  * RGBA-style image support.
  */
 /*
  * RGBA-style image support.
  */
-typedef        unsigned char TIFFRGBValue;             /* 8-bit samples */
 typedef struct _TIFFRGBAImage TIFFRGBAImage;
 /*
  * The image reading and conversion routines invoke
  * ``put routines'' to copy/image/whatever tiles of
 typedef struct _TIFFRGBAImage TIFFRGBAImage;
 /*
  * The image reading and conversion routines invoke
  * ``put routines'' to copy/image/whatever tiles of
- * raw image data.  A default set of routines are
+ * raw image data.  A default set of routines are 
  * provided to convert/copy raw image data to 8-bit
  * packed ABGR format rasters.  Applications can supply
  * alternate routines that unpack the data into a
  * different format or, for example, unpack the data
  * and draw the unpacked raster on the display.
  */
  * provided to convert/copy raw image data to 8-bit
  * packed ABGR format rasters.  Applications can supply
  * alternate routines that unpack the data into a
  * different format or, for example, unpack the data
  * and draw the unpacked raster on the display.
  */
-typedef void (LINKAGEMODE *tileContigRoutine)
+typedef void (*tileContigRoutine)
     (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
        unsigned char*);
     (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
        unsigned char*);
-typedef void (LINKAGEMODE *tileSeparateRoutine)
+typedef void (*tileSeparateRoutine)
     (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
        unsigned char*, unsigned char*, unsigned char*, unsigned char*);
 /*
  * RGBA-reader state.
  */
     (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
        unsigned char*, unsigned char*, unsigned char*, unsigned char*);
 /*
  * RGBA-reader state.
  */
-typedef struct {                               /* YCbCr->RGB support */
-       TIFFRGBValue* clamptab;                 /* range clamping table */
-       int*    Cr_r_tab;
-       int*    Cb_b_tab;
-       int32*  Cr_g_tab;
-       int32*  Cb_g_tab;
-       float   coeffs[3];                      /* cached for repeated use */
-} TIFFYCbCrToRGB;
-
 struct _TIFFRGBAImage {
        TIFF*   tif;                            /* image handle */
        int     stoponerr;                      /* stop on read error */
 struct _TIFFRGBAImage {
        TIFF*   tif;                            /* image handle */
        int     stoponerr;                      /* stop on read error */
@@ -155,12 +210,13 @@ struct _TIFFRGBAImage {
        uint16  bitspersample;                  /* image bits/sample */
        uint16  samplesperpixel;                /* image samples/pixel */
        uint16  orientation;                    /* image orientation */
        uint16  bitspersample;                  /* image bits/sample */
        uint16  samplesperpixel;                /* image samples/pixel */
        uint16  orientation;                    /* image orientation */
+       uint16  req_orientation;                /* requested orientation */
        uint16  photometric;                    /* image photometric interp */
        uint16* redcmap;                        /* colormap pallete */
        uint16* greencmap;
        uint16* bluecmap;
                                                /* get image data routine */
        uint16  photometric;                    /* image photometric interp */
        uint16* redcmap;                        /* colormap pallete */
        uint16* greencmap;
        uint16* bluecmap;
                                                /* get image data routine */
-       int     (LINKAGEMODE *get)(TIFFRGBAImage*, uint32*, uint32, uint32);
+       int     (*get)(TIFFRGBAImage*, uint32*, uint32, uint32);
        union {
            void (*any)(TIFFRGBAImage*);
            tileContigRoutine   contig;
        union {
            void (*any)(TIFFRGBAImage*);
            tileContigRoutine   contig;
@@ -170,6 +226,7 @@ struct _TIFFRGBAImage {
        uint32** BWmap;                         /* black&white map */
        uint32** PALmap;                        /* palette image map */
        TIFFYCbCrToRGB* ycbcr;                  /* YCbCr conversion state */
        uint32** BWmap;                         /* black&white map */
        uint32** PALmap;                        /* palette image map */
        TIFFYCbCrToRGB* ycbcr;                  /* YCbCr conversion state */
+        TIFFCIELabToRGB* cielab;               /* CIE L*a*b conversion state */
 
         int    row_offset;
         int     col_offset;
 
         int    row_offset;
         int     col_offset;
@@ -191,7 +248,7 @@ struct _TIFFRGBAImage {
  * More codecs may be registered through calls to the library
  * and/or the builtin implementations may be overridden.
  */
  * More codecs may be registered through calls to the library
  * and/or the builtin implementations may be overridden.
  */
-typedef        int (LINKAGEMODE *TIFFInitMethod)(TIFF*, int);
+typedef        int (*TIFFInitMethod)(TIFF*, int);
 typedef struct {
        char*           name;
        uint16          scheme;
 typedef struct {
        char*           name;
        uint16          scheme;
@@ -201,23 +258,29 @@ typedef struct {
 #include <stdio.h>
 #include <stdarg.h>
 
 #include <stdio.h>
 #include <stdarg.h>
 
+/* share internal LogLuv conversion routines? */
+#ifndef LOGLUV_PUBLIC
+#define LOGLUV_PUBLIC          1       
+#endif
+
 #if defined(__cplusplus)
 extern "C" {
 #endif
 #if defined(__cplusplus)
 extern "C" {
 #endif
-typedef        void (LINKAGEMODE *TIFFErrorHandler)(const char*, const char*, va_list);
-typedef        tsize_t (LINKAGEMODE *TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);
-typedef        toff_t (LINKAGEMODE *TIFFSeekProc)(thandle_t, toff_t, int);
-typedef        int (LINKAGEMODE *TIFFCloseProc)(thandle_t);
-typedef        toff_t (LINKAGEMODE *TIFFSizeProc)(thandle_t);
-typedef        int (LINKAGEMODE *TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);
-typedef        void (LINKAGEMODE *TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);
-typedef        void (LINKAGEMODE *TIFFExtendProc)(TIFF*);
+typedef        void (*TIFFErrorHandler)(const char*, const char*, va_list);
+typedef        tsize_t (*TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);
+typedef        toff_t (*TIFFSeekProc)(thandle_t, toff_t, int);
+typedef        int (*TIFFCloseProc)(thandle_t);
+typedef        toff_t (*TIFFSizeProc)(thandle_t);
+typedef        int (*TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);
+typedef        void (*TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);
+typedef        void (*TIFFExtendProc)(TIFF*); 
 
 extern const char* TIFFGetVersion(void);
 
 extern const TIFFCodec* TIFFFindCODEC(uint16);
 extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod);
 extern void TIFFUnRegisterCODEC(TIFFCodec*);
 
 extern const char* TIFFGetVersion(void);
 
 extern const TIFFCodec* TIFFFindCODEC(uint16);
 extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod);
 extern void TIFFUnRegisterCODEC(TIFFCodec*);
+extern  int TIFFIsCODECConfigured(uint16);
 
 extern tdata_t _TIFFmalloc(tsize_t);
 extern tdata_t _TIFFrealloc(tdata_t, tsize_t);
 
 extern tdata_t _TIFFmalloc(tsize_t);
 extern tdata_t _TIFFrealloc(tdata_t, tsize_t);
@@ -237,6 +300,7 @@ extern      int TIFFReadDirectory(TIFF*);
 extern tsize_t TIFFScanlineSize(TIFF*);
 extern tsize_t TIFFRasterScanlineSize(TIFF*);
 extern tsize_t TIFFStripSize(TIFF*);
 extern tsize_t TIFFScanlineSize(TIFF*);
 extern tsize_t TIFFRasterScanlineSize(TIFF*);
 extern tsize_t TIFFStripSize(TIFF*);
+extern tsize_t TIFFRawStripSize(TIFF*, tstrip_t);
 extern tsize_t TIFFVStripSize(TIFF*, uint32);
 extern tsize_t TIFFTileRowSize(TIFF*);
 extern tsize_t TIFFTileSize(TIFF*);
 extern tsize_t TIFFVStripSize(TIFF*, uint32);
 extern tsize_t TIFFTileRowSize(TIFF*);
 extern tsize_t TIFFTileSize(TIFF*);
@@ -257,6 +321,9 @@ extern      tstrip_t TIFFCurrentStrip(TIFF*);
 extern ttile_t TIFFCurrentTile(TIFF*);
 extern int TIFFReadBufferSetup(TIFF*, tdata_t, tsize_t);
 extern int TIFFWriteBufferSetup(TIFF*, tdata_t, tsize_t);
 extern ttile_t TIFFCurrentTile(TIFF*);
 extern int TIFFReadBufferSetup(TIFF*, tdata_t, tsize_t);
 extern int TIFFWriteBufferSetup(TIFF*, tdata_t, tsize_t);
+extern int TIFFSetupStrips(TIFF *);
+extern  int TIFFWriteCheck(TIFF*, int, const char *);
+extern  int TIFFCreateDirectory(TIFF*);
 extern int TIFFLastDirectory(TIFF*);
 extern int TIFFSetDirectory(TIFF*, tdir_t);
 extern int TIFFSetSubDirectory(TIFF*, uint32);
 extern int TIFFLastDirectory(TIFF*);
 extern int TIFFSetDirectory(TIFF*, tdir_t);
 extern int TIFFSetSubDirectory(TIFF*, uint32);
@@ -264,6 +331,8 @@ extern      int TIFFUnlinkDirectory(TIFF*, tdir_t);
 extern int TIFFSetField(TIFF*, ttag_t, ...);
 extern int TIFFVSetField(TIFF*, ttag_t, va_list);
 extern int TIFFWriteDirectory(TIFF *);
 extern int TIFFSetField(TIFF*, ttag_t, ...);
 extern int TIFFVSetField(TIFF*, ttag_t, va_list);
 extern int TIFFWriteDirectory(TIFF *);
+extern int TIFFCheckpointDirectory(TIFF *);
+extern int TIFFRewriteDirectory(TIFF *);
 extern int TIFFReassignTagToIgnore(enum TIFFIgnoreSense, int);
 
 #if defined(c_plusplus) || defined(__cplusplus)
 extern int TIFFReassignTagToIgnore(enum TIFFIgnoreSense, int);
 
 #if defined(c_plusplus) || defined(__cplusplus)
@@ -271,11 +340,14 @@ extern    void TIFFPrintDirectory(TIFF*, FILE*, long = 0);
 extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
 extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
 extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0);
 extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
 extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
 extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0);
+extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*,
+                                     int = ORIENTATION_BOTLEFT, int = 0);
 #else
 extern void TIFFPrintDirectory(TIFF*, FILE*, long);
 extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t);
 extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t);
 extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int);
 #else
 extern void TIFFPrintDirectory(TIFF*, FILE*, long);
 extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t);
 extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t);
 extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int);
+extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int);
 #endif
 
 extern int TIFFReadRGBAStrip(TIFF*, tstrip_t, uint32 * );
 #endif
 
 extern int TIFFReadRGBAStrip(TIFF*, tstrip_t, uint32 * );
@@ -315,6 +387,7 @@ extern      tsize_t TIFFWriteEncodedStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteRawStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteEncodedTile(TIFF*, ttile_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteRawTile(TIFF*, ttile_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteRawStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteEncodedTile(TIFF*, ttile_t, tdata_t, tsize_t);
 extern tsize_t TIFFWriteRawTile(TIFF*, ttile_t, tdata_t, tsize_t);
+extern int TIFFDataWidth(TIFFDataType);    /* table of tag datatype widths */
 extern void TIFFSetWriteOffset(TIFF*, toff_t);
 extern void TIFFSwabShort(uint16*);
 extern void TIFFSwabLong(uint32*);
 extern void TIFFSetWriteOffset(TIFF*, toff_t);
 extern void TIFFSwabShort(uint16*);
 extern void TIFFSwabLong(uint32*);
@@ -324,6 +397,80 @@ extern     void TIFFSwabArrayOfLong(uint32*, unsigned long);
 extern void TIFFSwabArrayOfDouble(double*, unsigned long);
 extern void TIFFReverseBits(unsigned char *, unsigned long);
 extern const unsigned char* TIFFGetBitRevTable(int);
 extern void TIFFSwabArrayOfDouble(double*, unsigned long);
 extern void TIFFReverseBits(unsigned char *, unsigned long);
 extern const unsigned char* TIFFGetBitRevTable(int);
+
+#ifdef LOGLUV_PUBLIC
+#define U_NEU          0.210526316
+#define V_NEU          0.473684211
+#define UVSCALE                410.
+extern double LogL16toY(int);
+extern double LogL10toY(int);
+extern void XYZtoRGB24(float*, uint8*);
+extern int uv_decode(double*, double*, int);
+extern void LogLuv24toXYZ(uint32, float*);
+extern void LogLuv32toXYZ(uint32, float*);
+#if defined(c_plusplus) || defined(__cplusplus)
+extern int LogL16fromY(double, int = SGILOGENCODE_NODITHER);
+extern int LogL10fromY(double, int = SGILOGENCODE_NODITHER);
+extern int uv_encode(double, double, int = SGILOGENCODE_NODITHER);
+extern uint32 LogLuv24fromXYZ(float*, int = SGILOGENCODE_NODITHER);
+extern uint32 LogLuv32fromXYZ(float*, int = SGILOGENCODE_NODITHER);
+#else
+extern int LogL16fromY(double, int);
+extern int LogL10fromY(double, int);
+extern int uv_encode(double, double, int);
+extern uint32 LogLuv24fromXYZ(float*, int);
+extern uint32 LogLuv32fromXYZ(float*, int);
+#endif
+#endif /* LOGLUV_PUBLIC */
+
+/*
+** New stuff going public in 3.6.x.
+*/
+extern  int  TIFFGetTagListCount( TIFF * );
+extern  ttag_t TIFFGetTagListEntry( TIFF *, int tag_index );
+    
+#define        TIFF_ANY        TIFF_NOTYPE     /* for field descriptor searching */
+#define        TIFF_VARIABLE   -1              /* marker for variable length tags */
+#define        TIFF_SPP        -2              /* marker for SamplesPerPixel tags */
+#define        TIFF_VARIABLE2  -3              /* marker for uint32 var-length tags */
+
+#define FIELD_CUSTOM    65    
+
+typedef        struct {
+       ttag_t  field_tag;              /* field's tag */
+       short   field_readcount;        /* read count/TIFF_VARIABLE/TIFF_SPP */
+       short   field_writecount;       /* write count/TIFF_VARIABLE */
+       TIFFDataType field_type;        /* type of associated data */
+        unsigned short field_bit;      /* bit in fieldsset bit vector */
+       unsigned char field_oktochange; /* if true, can change while writing */
+       unsigned char field_passcount;  /* if true, pass dir count on set */
+       char    *field_name;            /* ASCII name */
+} TIFFFieldInfo;
+
+typedef struct _TIFFTagValue {
+    const TIFFFieldInfo  *info;
+    int             count;
+    void           *value;
+} TIFFTagValue;
+
+extern void TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], int);
+extern const TIFFFieldInfo* TIFFFindFieldInfo(TIFF*, ttag_t, TIFFDataType);
+extern const TIFFFieldInfo* TIFFFieldWithTag(TIFF*, ttag_t);
+
+typedef        int (*TIFFVSetMethod)(TIFF*, ttag_t, va_list);
+typedef        int (*TIFFVGetMethod)(TIFF*, ttag_t, va_list);
+typedef        void (*TIFFPrintMethod)(TIFF*, FILE*, long);
+    
+typedef struct {
+    TIFFVSetMethod     vsetfield;      /* tag set routine */
+    TIFFVGetMethod     vgetfield;      /* tag get routine */
+    TIFFPrintMethod    printdir;       /* directory print routine */
+} TIFFTagMethods;
+        
+extern  TIFFTagMethods *TIFFAccessTagMethods( TIFF * );
+extern  void *TIFFGetClientInfo( TIFF *, const char * );
+extern  void TIFFSetClientInfo( TIFF *, void *, const char * );
+    
 #if defined(__cplusplus)
 }
 #endif
 #if defined(__cplusplus)
 }
 #endif
index cb0a20c079816c6696215e4e35799cc4343c6cf2..24de55df1bf60d22dac375a5f23b2a0a5d5226f2 100644 (file)
@@ -4,23 +4,23 @@
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
- * Permission to use, copy, modify, distribute, and sell this software and
+ * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
  * its documentation for any purpose is hereby granted without fee, provided
  * that (i) the above copyright notices and this permission notice appear in
  * all copies of the software and related documentation, and (ii) the names of
  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  * publicity relating to the software without the specific, prior written
  * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  */
 
  * OF THIS SOFTWARE.
  */
 
@@ -34,7 +34,7 @@
  * a port.h file that reflects the system capabilities.
  * Doing this obviates all the dreck done in tiffcomp.h.
  */
  * a port.h file that reflects the system capabilities.
  * Doing this obviates all the dreck done in tiffcomp.h.
  */
-#if (defined(unix) || defined(__unix)) && !defined(__DJGPP__)
+#if defined(unix) || defined(__unix)
 #include "port.h"
 #include "tiffconf.h"
 #else
 #include "port.h"
 #include "tiffconf.h"
 #else
 #define        FALSE   0
 #endif
 
 #define        FALSE   0
 #endif
 
+typedef struct client_info {
+    struct client_info *next;
+    void      *data;
+    char      *name;
+} TIFFClientInfoLink;
+
 /*
  * Typedefs for ``method pointers'' used internally.
  */
 /*
  * Typedefs for ``method pointers'' used internally.
  */
@@ -58,14 +64,11 @@ typedef     tidataval_t* tidata_t;          /* reference to internal image data */
 typedef        void (*TIFFVoidMethod)(TIFF*);
 typedef        int (*TIFFBoolMethod)(TIFF*);
 typedef        int (*TIFFPreMethod)(TIFF*, tsample_t);
 typedef        void (*TIFFVoidMethod)(TIFF*);
 typedef        int (*TIFFBoolMethod)(TIFF*);
 typedef        int (*TIFFPreMethod)(TIFF*, tsample_t);
-typedef        int (LINKAGEMODE *TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
-typedef        int (LINKAGEMODE *TIFFSeekMethod)(TIFF*, uint32);
-typedef        void (LINKAGEMODE *TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
-typedef        int (*TIFFVSetMethod)(TIFF*, ttag_t, va_list);
-typedef        int (*TIFFVGetMethod)(TIFF*, ttag_t, va_list);
-typedef        void (LINKAGEMODE *TIFFPrintMethod)(TIFF*, FILE*, long);
-typedef        uint32 (LINKAGEMODE *TIFFStripMethod)(TIFF*, uint32);
-typedef        void (LINKAGEMODE *TIFFTileMethod)(TIFF*, uint32*, uint32*);
+typedef        int (*TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
+typedef        int (*TIFFSeekMethod)(TIFF*, uint32);
+typedef        void (*TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
+typedef        uint32 (*TIFFStripMethod)(TIFF*, uint32);
+typedef        void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
 
 struct tiff {
        char*           tif_name;       /* name of open file */
 
 struct tiff {
        char*           tif_name;       /* name of open file */
@@ -85,13 +88,15 @@ struct tiff {
 #define        TIFF_MAPPED             0x0800  /* file is mapped into memory */
 #define        TIFF_POSTENCODE         0x1000  /* need call to postencode routine */
 #define        TIFF_INSUBIFD           0x2000  /* currently writing a subifd */
 #define        TIFF_MAPPED             0x0800  /* file is mapped into memory */
 #define        TIFF_POSTENCODE         0x1000  /* need call to postencode routine */
 #define        TIFF_INSUBIFD           0x2000  /* currently writing a subifd */
-#define        TIFF_UPSAMPLED          0x4000  /* library is doing data up-sampling */
+#define        TIFF_UPSAMPLED          0x4000  /* library is doing data up-sampling */ 
 #define        TIFF_STRIPCHOP          0x8000  /* enable strip chopping support */
        toff_t          tif_diroff;     /* file offset of current directory */
        toff_t          tif_nextdiroff; /* file offset of following directory */
 #define        TIFF_STRIPCHOP          0x8000  /* enable strip chopping support */
        toff_t          tif_diroff;     /* file offset of current directory */
        toff_t          tif_nextdiroff; /* file offset of following directory */
+       toff_t*         tif_dirlist;    /* list of offsets to already seen */
+                                       /* directories to prevent IFD looping */
+       uint16          tif_dirnumber;  /* number of already seen directories */
        TIFFDirectory   tif_dir;        /* internal rep of current directory */
        TIFFHeader      tif_header;     /* file's header block */
        TIFFDirectory   tif_dir;        /* internal rep of current directory */
        TIFFHeader      tif_header;     /* file's header block */
-        tidata_t        tif_clientdir;  /* client TIFF directory */
        const int*      tif_typeshift;  /* data type shift counts */
        const long*     tif_typemask;   /* data type masks */
        uint32          tif_row;        /* current scanline */
        const int*      tif_typeshift;  /* data type shift counts */
        const long*     tif_typemask;   /* data type masks */
        uint32          tif_row;        /* current scanline */
@@ -108,9 +113,11 @@ struct tiff {
        ttile_t         tif_curtile;    /* current tile for read/write */
        tsize_t         tif_tilesize;   /* # of bytes in a tile */
 /* compression scheme hooks */
        ttile_t         tif_curtile;    /* current tile for read/write */
        tsize_t         tif_tilesize;   /* # of bytes in a tile */
 /* compression scheme hooks */
+       int             tif_decodestatus;
        TIFFBoolMethod  tif_setupdecode;/* called once before predecode */
        TIFFPreMethod   tif_predecode;  /* pre- row/strip/tile decoding */
        TIFFBoolMethod  tif_setupencode;/* called once before preencode */
        TIFFBoolMethod  tif_setupdecode;/* called once before predecode */
        TIFFPreMethod   tif_predecode;  /* pre- row/strip/tile decoding */
        TIFFBoolMethod  tif_setupencode;/* called once before preencode */
+       int             tif_encodestatus;
        TIFFPreMethod   tif_preencode;  /* pre- row/strip/tile encoding */
        TIFFBoolMethod  tif_postencode; /* post- row/strip/tile encoding */
        TIFFCodeMethod  tif_decoderow;  /* scanline decoding routine */
        TIFFPreMethod   tif_preencode;  /* pre- row/strip/tile encoding */
        TIFFBoolMethod  tif_postencode; /* post- row/strip/tile encoding */
        TIFFCodeMethod  tif_decoderow;  /* scanline decoding routine */
@@ -149,9 +156,8 @@ struct tiff {
 /* tag support */
        TIFFFieldInfo** tif_fieldinfo;  /* sorted table of registered tags */
        int             tif_nfields;    /* # entries in registered tag table */
 /* tag support */
        TIFFFieldInfo** tif_fieldinfo;  /* sorted table of registered tags */
        int             tif_nfields;    /* # entries in registered tag table */
-       TIFFVSetMethod  tif_vsetfield;  /* tag set routine */
-       TIFFVGetMethod  tif_vgetfield;  /* tag get routine */
-       TIFFPrintMethod tif_printdir;   /* directory print routine */
+        TIFFTagMethods  tif_tagmethods; /* tag get/set/print routines */
+        TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
 };
 
 #define        isPseudoTag(t)  (t > 0xffff)    /* is tag value normal or pseudo */
 };
 
 #define        isPseudoTag(t)  (t > 0xffff)    /* is tag value normal or pseudo */
@@ -180,7 +186,7 @@ struct tiff {
  */
 #ifndef ReadOK
 #define        ReadOK(tif, buf, size) \
  */
 #ifndef ReadOK
 #define        ReadOK(tif, buf, size) \
-       (TIFFReadFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size)
+       (TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size))
 #endif
 #ifndef SeekOK
 #define        SeekOK(tif, off) \
 #endif
 #ifndef SeekOK
 #define        SeekOK(tif, off) \
@@ -192,8 +198,12 @@ struct tiff {
 #endif
 
 /* NB: the uint32 casts are to silence certain ANSI-C compilers */
 #endif
 
 /* NB: the uint32 casts are to silence certain ANSI-C compilers */
-#define        TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
-#define        TIFFroundup(x, y) (TIFFhowmany(x,y)*((uint32)(y)))
+#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
+#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
+#define        TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
+
+#define TIFFmax(A,B) ((A)>(B)?(A):(B))
+#define TIFFmin(A,B) ((A)<(B)?(A):(B))
 
 #if defined(__cplusplus)
 extern "C" {
 
 #if defined(__cplusplus)
 extern "C" {
@@ -206,15 +216,16 @@ extern    int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 extern int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 extern int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
 extern int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 extern int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
 extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
+extern  int  _TIFFNoPreCode (TIFF*, tsample_t); 
 extern int _TIFFNoSeek(TIFF*, uint32);
 extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
 extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
 extern void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
 extern int _TIFFNoSeek(TIFF*, uint32);
 extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
 extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
 extern void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
-extern int  TIFFFlushData1(TIFF*);
-extern void  TIFFFreeDirectory(TIFF*);
-extern int  TIFFDefaultDirectory(TIFF*);
-extern int  TIFFSetCompressionScheme(TIFF*, uint16);
-extern int  TIFFSetDefaultCompressionState(TIFF*);
+extern int TIFFFlushData1(TIFF*);
+extern void TIFFFreeDirectory(TIFF*);
+extern int TIFFDefaultDirectory(TIFF*);
+extern int TIFFSetCompressionScheme(TIFF*, int);
+extern int TIFFSetDefaultCompressionState(TIFF*);
 extern uint32 _TIFFDefaultStripSize(TIFF*, uint32);
 extern void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
 
 extern uint32 _TIFFDefaultStripSize(TIFF*, uint32);
 extern void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
 
@@ -231,7 +242,7 @@ extern      void _TIFFprintAsciiTag(FILE*, const char*, const char*);
 GLOBALDATA(TIFFErrorHandler,_TIFFwarningHandler);
 GLOBALDATA(TIFFErrorHandler,_TIFFerrorHandler);
 
 GLOBALDATA(TIFFErrorHandler,_TIFFwarningHandler);
 GLOBALDATA(TIFFErrorHandler,_TIFFerrorHandler);
 
-extern int TIFFInitDumpMode(TIFF*, int);
+extern int TIFFInitDumpMode(TIFF*, int);
 #ifdef PACKBITS_SUPPORT
 extern int TIFFInitPackBits(TIFF*, int);
 #endif
 #ifdef PACKBITS_SUPPORT
 extern int TIFFInitPackBits(TIFF*, int);
 #endif
index 0fdac1322222c9e35c72db8469ed1947849ac75e..8d96e445837c1843d19a34301cec1e0c08b02e5a 100644 (file)
 /* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */
 /* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */
-#define UV_SQSIZ       0.003500
+#define UV_SQSIZ       (float)0.003500
 #define UV_NDIVS       16289
 #define UV_NDIVS       16289
-#define UV_VSTART      0.016940
+#define UV_VSTART      (float)0.016940
 #define UV_NVS         163
 static struct {
        float   ustart;
        short   nus, ncum;
 }      uv_row[UV_NVS] = {
 #define UV_NVS         163
 static struct {
        float   ustart;
        short   nus, ncum;
 }      uv_row[UV_NVS] = {
-       { 0.247663,     4,      0 },
-       { 0.243779,     6,      4 },
-       { 0.241684,     7,      10 },
-       { 0.237874,     9,      17 },
-       { 0.235906,     10,     26 },
-       { 0.232153,     12,     36 },
-       { 0.228352,     14,     48 },
-       { 0.226259,     15,     62 },
-       { 0.222371,     17,     77 },
-       { 0.220410,     18,     94 },
-       { 0.214710,     21,     112 },
-       { 0.212714,     22,     133 },
-       { 0.210721,     23,     155 },
-       { 0.204976,     26,     178 },
-       { 0.202986,     27,     204 },
-       { 0.199245,     29,     231 },
-       { 0.195525,     31,     260 },
-       { 0.193560,     32,     291 },
-       { 0.189878,     34,     323 },
-       { 0.186216,     36,     357 },
-       { 0.186216,     36,     393 },
-       { 0.182592,     38,     429 },
-       { 0.179003,     40,     467 },
-       { 0.175466,     42,     507 },
-       { 0.172001,     44,     549 },
-       { 0.172001,     44,     593 },
-       { 0.168612,     46,     637 },
-       { 0.168612,     46,     683 },
-       { 0.163575,     49,     729 },
-       { 0.158642,     52,     778 },
-       { 0.158642,     52,     830 },
-       { 0.158642,     52,     882 },
-       { 0.153815,     55,     934 },
-       { 0.153815,     55,     989 },
-       { 0.149097,     58,     1044 },
-       { 0.149097,     58,     1102 },
-       { 0.142746,     62,     1160 },
-       { 0.142746,     62,     1222 },
-       { 0.142746,     62,     1284 },
-       { 0.138270,     65,     1346 },
-       { 0.138270,     65,     1411 },
-       { 0.138270,     65,     1476 },
-       { 0.132166,     69,     1541 },
-       { 0.132166,     69,     1610 },
-       { 0.126204,     73,     1679 },
-       { 0.126204,     73,     1752 },
-       { 0.126204,     73,     1825 },
-       { 0.120381,     77,     1898 },
-       { 0.120381,     77,     1975 },
-       { 0.120381,     77,     2052 },
-       { 0.120381,     77,     2129 },
-       { 0.112962,     82,     2206 },
-       { 0.112962,     82,     2288 },
-       { 0.112962,     82,     2370 },
-       { 0.107450,     86,     2452 },
-       { 0.107450,     86,     2538 },
-       { 0.107450,     86,     2624 },
-       { 0.107450,     86,     2710 },
-       { 0.100343,     91,     2796 },
-       { 0.100343,     91,     2887 },
-       { 0.100343,     91,     2978 },
-       { 0.095126,     95,     3069 },
-       { 0.095126,     95,     3164 },
-       { 0.095126,     95,     3259 },
-       { 0.095126,     95,     3354 },
-       { 0.088276,     100,    3449 },
-       { 0.088276,     100,    3549 },
-       { 0.088276,     100,    3649 },
-       { 0.088276,     100,    3749 },
-       { 0.081523,     105,    3849 },
-       { 0.081523,     105,    3954 },
-       { 0.081523,     105,    4059 },
-       { 0.081523,     105,    4164 },
-       { 0.074861,     110,    4269 },
-       { 0.074861,     110,    4379 },
-       { 0.074861,     110,    4489 },
-       { 0.074861,     110,    4599 },
-       { 0.068290,     115,    4709 },
-       { 0.068290,     115,    4824 },
-       { 0.068290,     115,    4939 },
-       { 0.068290,     115,    5054 },
-       { 0.063573,     119,    5169 },
-       { 0.063573,     119,    5288 },
-       { 0.063573,     119,    5407 },
-       { 0.063573,     119,    5526 },
-       { 0.057219,     124,    5645 },
-       { 0.057219,     124,    5769 },
-       { 0.057219,     124,    5893 },
-       { 0.057219,     124,    6017 },
-       { 0.050985,     129,    6141 },
-       { 0.050985,     129,    6270 },
-       { 0.050985,     129,    6399 },
-       { 0.050985,     129,    6528 },
-       { 0.050985,     129,    6657 },
-       { 0.044859,     134,    6786 },
-       { 0.044859,     134,    6920 },
-       { 0.044859,     134,    7054 },
-       { 0.044859,     134,    7188 },
-       { 0.040571,     138,    7322 },
-       { 0.040571,     138,    7460 },
-       { 0.040571,     138,    7598 },
-       { 0.040571,     138,    7736 },
-       { 0.036339,     142,    7874 },
-       { 0.036339,     142,    8016 },
-       { 0.036339,     142,    8158 },
-       { 0.036339,     142,    8300 },
-       { 0.032139,     146,    8442 },
-       { 0.032139,     146,    8588 },
-       { 0.032139,     146,    8734 },
-       { 0.032139,     146,    8880 },
-       { 0.027947,     150,    9026 },
-       { 0.027947,     150,    9176 },
-       { 0.027947,     150,    9326 },
-       { 0.023739,     154,    9476 },
-       { 0.023739,     154,    9630 },
-       { 0.023739,     154,    9784 },
-       { 0.023739,     154,    9938 },
-       { 0.019504,     158,    10092 },
-       { 0.019504,     158,    10250 },
-       { 0.019504,     158,    10408 },
-       { 0.016976,     161,    10566 },
-       { 0.016976,     161,    10727 },
-       { 0.016976,     161,    10888 },
-       { 0.016976,     161,    11049 },
-       { 0.012639,     165,    11210 },
-       { 0.012639,     165,    11375 },
-       { 0.012639,     165,    11540 },
-       { 0.009991,     168,    11705 },
-       { 0.009991,     168,    11873 },
-       { 0.009991,     168,    12041 },
-       { 0.009016,     170,    12209 },
-       { 0.009016,     170,    12379 },
-       { 0.009016,     170,    12549 },
-       { 0.006217,     173,    12719 },
-       { 0.006217,     173,    12892 },
-       { 0.005097,     175,    13065 },
-       { 0.005097,     175,    13240 },
-       { 0.005097,     175,    13415 },
-       { 0.003909,     177,    13590 },
-       { 0.003909,     177,    13767 },
-       { 0.002340,     177,    13944 },
-       { 0.002389,     170,    14121 },
-       { 0.001068,     164,    14291 },
-       { 0.001653,     157,    14455 },
-       { 0.000717,     150,    14612 },
-       { 0.001614,     143,    14762 },
-       { 0.000270,     136,    14905 },
-       { 0.000484,     129,    15041 },
-       { 0.001103,     123,    15170 },
-       { 0.001242,     115,    15293 },
-       { 0.001188,     109,    15408 },
-       { 0.001011,     103,    15517 },
-       { 0.000709,     97,     15620 },
-       { 0.000301,     89,     15717 },
-       { 0.002416,     82,     15806 },
-       { 0.003251,     76,     15888 },
-       { 0.003246,     69,     15964 },
-       { 0.004141,     62,     16033 },
-       { 0.005963,     55,     16095 },
-       { 0.008839,     47,     16150 },
-       { 0.010490,     40,     16197 },
-       { 0.016994,     31,     16237 },
-       { 0.023659,     21,     16268 },
+       (float)0.247663,        4,      0,
+       (float)0.243779,        6,      4,
+       (float)0.241684,        7,      10,
+       (float)0.237874,        9,      17,
+       (float)0.235906,        10,     26,
+       (float)0.232153,        12,     36,
+       (float)0.228352,        14,     48,
+       (float)0.226259,        15,     62,
+       (float)0.222371,        17,     77,
+       (float)0.220410,        18,     94,
+       (float)0.214710,        21,     112,
+       (float)0.212714,        22,     133,
+       (float)0.210721,        23,     155,
+       (float)0.204976,        26,     178,
+       (float)0.202986,        27,     204,
+       (float)0.199245,        29,     231,
+       (float)0.195525,        31,     260,
+       (float)0.193560,        32,     291,
+       (float)0.189878,        34,     323,
+       (float)0.186216,        36,     357,
+       (float)0.186216,        36,     393,
+       (float)0.182592,        38,     429,
+       (float)0.179003,        40,     467,
+       (float)0.175466,        42,     507,
+       (float)0.172001,        44,     549,
+       (float)0.172001,        44,     593,
+       (float)0.168612,        46,     637,
+       (float)0.168612,        46,     683,
+       (float)0.163575,        49,     729,
+       (float)0.158642,        52,     778,
+       (float)0.158642,        52,     830,
+       (float)0.158642,        52,     882,
+       (float)0.153815,        55,     934,
+       (float)0.153815,        55,     989,
+       (float)0.149097,        58,     1044,
+       (float)0.149097,        58,     1102,
+       (float)0.142746,        62,     1160,
+       (float)0.142746,        62,     1222,
+       (float)0.142746,        62,     1284,
+       (float)0.138270,        65,     1346,
+       (float)0.138270,        65,     1411,
+       (float)0.138270,        65,     1476,
+       (float)0.132166,        69,     1541,
+       (float)0.132166,        69,     1610,
+       (float)0.126204,        73,     1679,
+       (float)0.126204,        73,     1752,
+       (float)0.126204,        73,     1825,
+       (float)0.120381,        77,     1898,
+       (float)0.120381,        77,     1975,
+       (float)0.120381,        77,     2052,
+       (float)0.120381,        77,     2129,
+       (float)0.112962,        82,     2206,
+       (float)0.112962,        82,     2288,
+       (float)0.112962,        82,     2370,
+       (float)0.107450,        86,     2452,
+       (float)0.107450,        86,     2538,
+       (float)0.107450,        86,     2624,
+       (float)0.107450,        86,     2710,
+       (float)0.100343,        91,     2796,
+       (float)0.100343,        91,     2887,
+       (float)0.100343,        91,     2978,
+       (float)0.095126,        95,     3069,
+       (float)0.095126,        95,     3164,
+       (float)0.095126,        95,     3259,
+       (float)0.095126,        95,     3354,
+       (float)0.088276,        100,    3449,
+       (float)0.088276,        100,    3549,
+       (float)0.088276,        100,    3649,
+       (float)0.088276,        100,    3749,
+       (float)0.081523,        105,    3849,
+       (float)0.081523,        105,    3954,
+       (float)0.081523,        105,    4059,
+       (float)0.081523,        105,    4164,
+       (float)0.074861,        110,    4269,
+       (float)0.074861,        110,    4379,
+       (float)0.074861,        110,    4489,
+       (float)0.074861,        110,    4599,
+       (float)0.068290,        115,    4709,
+       (float)0.068290,        115,    4824,
+       (float)0.068290,        115,    4939,
+       (float)0.068290,        115,    5054,
+       (float)0.063573,        119,    5169,
+       (float)0.063573,        119,    5288,
+       (float)0.063573,        119,    5407,
+       (float)0.063573,        119,    5526,
+       (float)0.057219,        124,    5645,
+       (float)0.057219,        124,    5769,
+       (float)0.057219,        124,    5893,
+       (float)0.057219,        124,    6017,
+       (float)0.050985,        129,    6141,
+       (float)0.050985,        129,    6270,
+       (float)0.050985,        129,    6399,
+       (float)0.050985,        129,    6528,
+       (float)0.050985,        129,    6657,
+       (float)0.044859,        134,    6786,
+       (float)0.044859,        134,    6920,
+       (float)0.044859,        134,    7054,
+       (float)0.044859,        134,    7188,
+       (float)0.040571,        138,    7322,
+       (float)0.040571,        138,    7460,
+       (float)0.040571,        138,    7598,
+       (float)0.040571,        138,    7736,
+       (float)0.036339,        142,    7874,
+       (float)0.036339,        142,    8016,
+       (float)0.036339,        142,    8158,
+       (float)0.036339,        142,    8300,
+       (float)0.032139,        146,    8442,
+       (float)0.032139,        146,    8588,
+       (float)0.032139,        146,    8734,
+       (float)0.032139,        146,    8880,
+       (float)0.027947,        150,    9026,
+       (float)0.027947,        150,    9176,
+       (float)0.027947,        150,    9326,
+       (float)0.023739,        154,    9476,
+       (float)0.023739,        154,    9630,
+       (float)0.023739,        154,    9784,
+       (float)0.023739,        154,    9938,
+       (float)0.019504,        158,    10092,
+       (float)0.019504,        158,    10250,
+       (float)0.019504,        158,    10408,
+       (float)0.016976,        161,    10566,
+       (float)0.016976,        161,    10727,
+       (float)0.016976,        161,    10888,
+       (float)0.016976,        161,    11049,
+       (float)0.012639,        165,    11210,
+       (float)0.012639,        165,    11375,
+       (float)0.012639,        165,    11540,
+       (float)0.009991,        168,    11705,
+       (float)0.009991,        168,    11873,
+       (float)0.009991,        168,    12041,
+       (float)0.009016,        170,    12209,
+       (float)0.009016,        170,    12379,
+       (float)0.009016,        170,    12549,
+       (float)0.006217,        173,    12719,
+       (float)0.006217,        173,    12892,
+       (float)0.005097,        175,    13065,
+       (float)0.005097,        175,    13240,
+       (float)0.005097,        175,    13415,
+       (float)0.003909,        177,    13590,
+       (float)0.003909,        177,    13767,
+       (float)0.002340,        177,    13944,
+       (float)0.002389,        170,    14121,
+       (float)0.001068,        164,    14291,
+       (float)0.001653,        157,    14455,
+       (float)0.000717,        150,    14612,
+       (float)0.001614,        143,    14762,
+       (float)0.000270,        136,    14905,
+       (float)0.000484,        129,    15041,
+       (float)0.001103,        123,    15170,
+       (float)0.001242,        115,    15293,
+       (float)0.001188,        109,    15408,
+       (float)0.001011,        103,    15517,
+       (float)0.000709,        97,     15620,
+       (float)0.000301,        89,     15717,
+       (float)0.002416,        82,     15806,
+       (float)0.003251,        76,     15888,
+       (float)0.003246,        69,     15964,
+       (float)0.004141,        62,     16033,
+       (float)0.005963,        55,     16095,
+       (float)0.008839,        47,     16150,
+       (float)0.010490,        40,     16197,
+       (float)0.016994,        31,     16237,
+       (float)0.023659,        21,     16268,
 };
 };