2012.07.26 02:50 "[Tiff] Confused about 4.0 API changes: TIFFField vs TIFFFieldInfo", by Tom Lane

2012.07.27 03:34 "Re: [Tiff] Confused about 4.0 API changes: TIFFField vs TIFFFieldInfo", by Tom Lane

So I propose we add five trivial accessor functions:

        int TIFFFieldReadCount(const TIFFField*);
        int TIFFFieldWriteCount(const TIFFField*);
        TIFFDataType TIFFFieldDataType(const TIFFField*);
        int TIFFFieldPassCount(const TIFFField*);
        const char* TIFFFieldName(const TIFFField*);

that just fetch the indicated field (and, probably, dump core if passed a NULL pointer - is there use in something more complex?)

These look good to me.

Attached is a draft patch for this. Aside from adding the functions themselves, as a test case I converted tiffset.c to use these functions and not have to pry into any library-private headers. That led me to also expose a TIFFFieldTag() function that returns the tag value. (This seems useful and symmetric given that we have both TIFFFieldWithTag and TIFFFieldWithName: it seems proper to be able to get the tag number after a lookup by name, or vice versa.)

I've never added functions to libtiff before, so it'd be good if someone would review this and see if I missed anything. In particular, I did not touch html/man/ since those files look like they are automatically generated from man/... is that correct? (Also, my groff-fu sucks, so comments on the man pages would be useful.)

regards, tom lane

Index: ChangeLog

=================================================================== RCS file: /cvs/maptools/cvsroot/libtiff/ChangeLog,v retrieving revision 1.915

diff -c -r1.915 ChangeLog

*** ChangeLog   19 Jul 2012 15:43:41 -0000      1.915
--- ChangeLog   27 Jul 2012 03:20:05 -0000
***************
*** 1,3 ****
--- 1,13 ----
+ 2012-07-26  Tom Lane  <tgl@sss.pgh.pa.us>

+       * libtiff/{tiffio.h, tif_dirinfo.c, libtiff.def}: Add six new
+       functions TIFFFieldTag(), TIFFFieldName(), TIFFFieldDataType(),
+       TIFFFieldPassCount(), TIFFFieldReadCount(), TIFFFieldWriteCount()
+       as external accessors for the opaque type TIFFField.

+       * tools/tiffset.c: Make tiffset use the above functions instead of
+       relying on library private headers.

  2012-07-19  Tom Lane  <tgl@sss.pgh.pa.us>

        * tools/tiff2pdf.c: Fix two places where t2p_error didn't get set
Index: configure.com
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/configure.com,v
retrieving revision 1.2
diff -c -r1.2 configure.com
*** configure.com       23 Nov 2007 10:01:34 -0000      1.2
--- configure.com       27 Jul 2012 03:20:05 -0000
***************
*** 503,508 ****
--- 503,514 ----
  TIFFFindFieldInfoByName=PROCEDURE,-
  TIFFFieldWithName=PROCEDURE,-
  TIFFFieldWithTag=PROCEDURE,-
+ TIFFFieldTag=PROCEDURE,-
+ TIFFFieldName=PROCEDURE,-
+ TIFFFieldDataType=PROCEDURE,-
+ TIFFFieldPassCount=PROCEDURE,-
+ TIFFFieldReadCount=PROCEDURE,-
+ TIFFFieldWriteCount=PROCEDURE,-
  TIFFCurrentDirOffset=PROCEDURE,-
  TIFFWriteCheck=PROCEDURE,-
  TIFFRGBAImageOK=PROCEDURE,-
***************
*** 648,653 ****
--- 654,665 ----
  UNIVERSAL=TIFFFindFieldInfoByName
  UNIVERSAL=TIFFFieldWithName
  UNIVERSAL=TIFFFieldWithTag
+ UNIVERSAL=TIFFFieldTag
+ UNIVERSAL=TIFFFieldName
+ UNIVERSAL=TIFFFieldDataType
+ UNIVERSAL=TIFFFieldPassCount
+ UNIVERSAL=TIFFFieldReadCount
+ UNIVERSAL=TIFFFieldWriteCount
  UNIVERSAL=TIFFCurrentDirOffset
  UNIVERSAL=TIFFWriteCheck
  UNIVERSAL=TIFFRGBAImageOK
Index: libtiff/libtiff.def
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/libtiff.def,v
retrieving revision 1.33
diff -c -r1.33 libtiff.def
*** libtiff/libtiff.def 16 Jun 2012 17:07:53 -0000      1.33
--- libtiff/libtiff.def 27 Jul 2012 03:20:05 -0000
***************
*** 119,124 ****
--- 119,130 ----
        TIFFSetTagExtender
        TIFFFieldWithName
        TIFFFieldWithTag
+       TIFFFieldTag
+       TIFFFieldName
+       TIFFFieldDataType
+       TIFFFieldPassCount
+       TIFFFieldReadCount
+       TIFFFieldWriteCount
        TIFFCurrentDirOffset
        TIFFWriteCheck
        TIFFRGBAImageOK
Index: libtiff/tif_dirinfo.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dirinfo.c,v
retrieving revision 1.115
diff -c -r1.115 tif_dirinfo.c
*** libtiff/tif_dirinfo.c       6 Jul 2012 19:18:31 -0000       1.115
--- libtiff/tif_dirinfo.c       27 Jul 2012 03:20:05 -0000
***************
*** 556,561 ****
--- 556,597 ----
        return (fip);
  }

+ uint32
+ TIFFFieldTag(const TIFFField* fip)
+ {
+       return fip->field_tag;
+ }

+ const char *
+ TIFFFieldName(const TIFFField* fip)
+ {
+       return fip->field_name;
+ }

+ TIFFDataType
+ TIFFFieldDataType(const TIFFField* fip)
+ {
+       return fip->field_type;
+ }

+ int
+ TIFFFieldPassCount(const TIFFField* fip)
+ {
+       return fip->field_passcoi   ees