]> git.saurik.com Git - wxWidgets.git/blobdiff - src/tiff/tools/tiffset.c
Fix stc doxygen warnings and regen stc files.
[wxWidgets.git] / src / tiff / tools / tiffset.c
index 8f75388a8e5c9f2718c1698274aedd3974970758..cfa42374c78f3389b34478e1bd82bcaf2238ef09 100644 (file)
@@ -1,5 +1,4 @@
 /******************************************************************************
- * $Id$
  *
  * Project:  libtiff tools
  * Purpose:  Mainline for setting metadata in existing TIFF files.
  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  * OF THIS SOFTWARE.
  ******************************************************************************
- *
- * $Log: tiffset.c,v $
- * Revision 1.11  2005/09/13 14:13:42  dron
- * Avoid warnings.
- *
- * Revision 1.10  2005/02/24 14:47:11  fwarmerdam
- * Updated header.
- *
  */
 
 
@@ -48,6 +39,8 @@ static char* usageMsg[] = {
 "usage: tiffset [options] filename",
 "where options are:",
 " -s <tagname> [count] <value>...   set the tag value",
+" -d <dirno> set the directory",
+" -sd <diroff> set the subdirectory",
 " -sf <tagname> <filename>  read the tag value from file (for ASCII tags only)",
 NULL
 };
@@ -61,10 +54,10 @@ usage(void)
        exit(-1);
 }
 
-static const TIFFFieldInfo *
+static const TIFFField *
 GetField(TIFF *tiff, const char *tagname)
 {
-    const TIFFFieldInfo *fip;
+    const TIFFField *fip;
 
     if( atoi(tagname) > 0 )
         fip = TIFFFieldWithTag(tiff, (ttag_t)atoi(tagname));
@@ -72,8 +65,8 @@ GetField(TIFF *tiff, const char *tagname)
         fip = TIFFFieldWithName(tiff, tagname);
 
     if (!fip) {
-        fprintf( stderr, "Field name %s not recognised.\n", tagname );
-        return (TIFFFieldInfo *)NULL;
+        fprintf( stderr, "Field name \"%s\" is not recognised.\n", tagname );
+        return (TIFFField *)NULL;
     }
 
     return fip;
@@ -93,8 +86,26 @@ main(int argc, char* argv[])
         return 2;
 
     for( arg_index = 1; arg_index < argc-1; arg_index++ ) {
+       if (strcmp(argv[arg_index],"-d") == 0 && arg_index < argc-2) {
+           arg_index++;
+           if( TIFFSetDirectory(tiff, atoi(argv[arg_index]) ) != 1 )
+            {
+               fprintf( stderr, "Failed to set directory=%s\n", argv[arg_index] );
+               return 6;
+            }
+           arg_index++;
+       }
+       if (strcmp(argv[arg_index],"-sd") == 0 && arg_index < argc-2) {
+           arg_index++;
+           if( TIFFSetSubDirectory(tiff, atoi(argv[arg_index]) ) != 1 )
+            {
+               fprintf( stderr, "Failed to set sub directory=%s\n", argv[arg_index] );
+               return 7;
+            }
+           arg_index++;
+       }
         if (strcmp(argv[arg_index],"-s") == 0 && arg_index < argc-3) {
-            const TIFFFieldInfo *fip;
+            const TIFFField *fip;
             const char *tagname;
 
             arg_index++;
@@ -105,24 +116,25 @@ main(int argc, char* argv[])
                 return 3;
 
             arg_index++;
-            if (fip->field_type == TIFF_ASCII) {
-                if (TIFFSetField(tiff, fip->field_tag, argv[arg_index]) != 1)
+            if (TIFFFieldDataType(fip) == TIFF_ASCII) {
+                if (TIFFSetField(tiff, TIFFFieldTag(fip), argv[arg_index]) != 1)
                     fprintf( stderr, "Failed to set %s=%s\n",
-                             fip->field_name, argv[arg_index] );
-            } else if (fip->field_writecount > 0) {
+                             TIFFFieldName(fip), argv[arg_index] );
+            } else if (TIFFFieldWriteCount(fip) > 0
+                      || TIFFFieldWriteCount(fip) == TIFF_VARIABLE) {
                 int     ret = 1;
                 short   wc;
 
-                if (fip->field_writecount == TIFF_VARIABLE)
+                if (TIFFFieldWriteCount(fip) == TIFF_VARIABLE)
                         wc = atoi(argv[arg_index++]);
                 else
-                        wc = fip->field_writecount;
+                        wc = TIFFFieldWriteCount(fip);
 
                 if (argc - arg_index < wc) {
                     fprintf( stderr,
                              "Number of tag values is not enough. "
                              "Expected %d values for %s tag, got %d\n",
-                             wc, fip->field_name, argc - arg_index);
+                             wc, TIFFFieldName(fip), argc - arg_index);
                     return 4;
                 }
                     
@@ -130,7 +142,7 @@ main(int argc, char* argv[])
                         int     i, size;
                         void    *array;
 
-                        switch (fip->field_type) {
+                        switch (TIFFFieldDataType(fip)) {
                                 /*
                                  * XXX: We can't use TIFFDataWidth()
                                  * to determine the space needed to store
@@ -172,7 +184,7 @@ main(int argc, char* argv[])
                                 return 4;
                         }
 
-                        switch (fip->field_type) {
+                        switch (TIFFFieldDataType(fip)) {
                             case TIFF_BYTE:
                                 for (i = 0; i < wc; i++)
                                     ((uint8 *)array)[i] = atoi(argv[arg_index+i]);
@@ -212,38 +224,49 @@ main(int argc, char* argv[])
                                 break;
                         }
                 
-                        if (fip->field_passcount) {
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                        if (TIFFFieldPassCount(fip)) {
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    wc, array);
-                        } else {
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                        } else if (TIFFFieldTag(fip) == TIFFTAG_PAGENUMBER
+                                  || TIFFFieldTag(fip) == TIFFTAG_HALFTONEHINTS
+                                  || TIFFFieldTag(fip) == TIFFTAG_YCBCRSUBSAMPLING
+                                  || TIFFFieldTag(fip) == TIFFTAG_DOTRANGE) {
+                                       if (TIFFFieldDataType(fip) == TIFF_BYTE) {
+                                       ret = TIFFSetField(tiff, TIFFFieldTag(fip),
+                                               ((uint8 *)array)[0], ((uint8 *)array)[1]);
+                               } else if (TIFFFieldDataType(fip) == TIFF_SHORT) {
+                                       ret = TIFFSetField(tiff, TIFFFieldTag(fip),
+                                               ((uint16 *)array)[0], ((uint16 *)array)[1]);
+                               }
+                       } else {
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    array);
                         }
 
                         _TIFFfree(array);
                 } else {
-                        switch (fip->field_type) {
+                        switch (TIFFFieldDataType(fip)) {
                             case TIFF_BYTE:
                             case TIFF_SHORT:
                             case TIFF_SBYTE:
                             case TIFF_SSHORT:
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    atoi(argv[arg_index++]));
                                 break;
                             case TIFF_LONG:
                             case TIFF_SLONG:
                             case TIFF_IFD:
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    atol(argv[arg_index++]));
                                 break;
                             case TIFF_DOUBLE:
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    atof(argv[arg_index++]));
                                 break;
                             case TIFF_RATIONAL:
                             case TIFF_SRATIONAL:
                             case TIFF_FLOAT:
-                                ret = TIFFSetField(tiff, fip->field_tag,
+                                ret = TIFFSetField(tiff, TIFFFieldTag(fip),
                                                    (float)atof(argv[arg_index++]));
                                 break;
                             default:
@@ -252,14 +275,14 @@ main(int argc, char* argv[])
                 }
 
                 if (ret != 1)
-                    fprintf(stderr, "Failed to set %s\n", fip->field_name);
+                    fprintf(stderr, "Failed to set %s\n", TIFFFieldName(fip));
                 arg_index += wc;
             }
         } else if (strcmp(argv[arg_index],"-sf") == 0 && arg_index < argc-3) {
             FILE    *fp;
-            const TIFFFieldInfo *fip;
+            const TIFFField *fip;
             char    *text;
-            int     len;
+            size_t  len;
 
             arg_index++;
             fip = GetField(tiff, argv[arg_index]);
@@ -267,10 +290,10 @@ main(int argc, char* argv[])
             if (!fip)
                 return 3;
 
-            if (fip->field_type != TIFF_ASCII) {
+            if (TIFFFieldDataType(fip) != TIFF_ASCII) {
                 fprintf( stderr,
                          "Only ASCII tags can be set from file. "
-                         "%s is not ASCII tag.\n", fip->field_name );
+                         "%s is not ASCII tag.\n", TIFFFieldName(fip) );
                 return 5;
             }
 
@@ -287,9 +310,9 @@ main(int argc, char* argv[])
 
             fclose( fp );
 
-            if(TIFFSetField( tiff, fip->field_tag, text ) != 1) {
+            if(TIFFSetField( tiff, TIFFFieldTag(fip), text ) != 1) {
                 fprintf(stderr, "Failed to set %s from file %s\n", 
-                        fip->field_name, argv[arg_index]);
+                        TIFFFieldName(fip), argv[arg_index]);
             }
 
             _TIFFfree( text );
@@ -307,3 +330,10 @@ main(int argc, char* argv[])
 }
 
 /* vim: set ts=8 sts=8 sw=8 noet: */
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */