tif_extension.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_extension.c,v 1.7 2010-03-10 18:56:48 bfriesen Exp $ */
  2. /*
  3. * Copyright (c) 1988-1997 Sam Leffler
  4. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and
  7. * its documentation for any purpose is hereby granted without fee, provided
  8. * that (i) the above copyright notices and this permission notice appear in
  9. * all copies of the software and related documentation, and (ii) the names of
  10. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11. * publicity relating to the software without the specific, prior written
  12. * permission of Sam Leffler and Silicon Graphics.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  16. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  22. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. /*
  26. * TIFF Library.
  27. *
  28. * Various routines support external extension of the tag set, and other
  29. * application extension capabilities.
  30. */
  31. #include "tiffiop.h"
  32. int TIFFGetTagListCount( TIFF *tif )
  33. {
  34. TIFFDirectory* td = &tif->tif_dir;
  35. return td->td_customValueCount;
  36. }
  37. uint32 TIFFGetTagListEntry( TIFF *tif, int tag_index )
  38. {
  39. TIFFDirectory* td = &tif->tif_dir;
  40. if( tag_index < 0 || tag_index >= td->td_customValueCount )
  41. return (uint32)(-1);
  42. else
  43. return td->td_customValues[tag_index].info->field_tag;
  44. }
  45. /*
  46. ** This provides read/write access to the TIFFTagMethods within the TIFF
  47. ** structure to application code without giving access to the private
  48. ** TIFF structure.
  49. */
  50. TIFFTagMethods *TIFFAccessTagMethods( TIFF *tif )
  51. {
  52. return &(tif->tif_tagmethods);
  53. }
  54. void *TIFFGetClientInfo( TIFF *tif, const char *name )
  55. {
  56. TIFFClientInfoLink *link = tif->tif_clientinfo;
  57. while( link != NULL && strcmp(link->name,name) != 0 )
  58. link = link->next;
  59. if( link != NULL )
  60. return link->data;
  61. else
  62. return NULL;
  63. }
  64. void TIFFSetClientInfo( TIFF *tif, void *data, const char *name )
  65. {
  66. TIFFClientInfoLink *link = tif->tif_clientinfo;
  67. /*
  68. ** Do we have an existing link with this name? If so, just
  69. ** set it.
  70. */
  71. while( link != NULL && strcmp(link->name,name) != 0 )
  72. link = link->next;
  73. if( link != NULL )
  74. {
  75. link->data = data;
  76. return;
  77. }
  78. /*
  79. ** Create a new link.
  80. */
  81. link = (TIFFClientInfoLink *) _TIFFmalloc(sizeof(TIFFClientInfoLink));
  82. assert (link != NULL);
  83. link->next = tif->tif_clientinfo;
  84. link->name = (char *) _TIFFmalloc((tmsize_t)(strlen(name)+1));
  85. assert (link->name != NULL);
  86. strcpy(link->name, name);
  87. link->data = data;
  88. tif->tif_clientinfo = link;
  89. }
  90. /*
  91. * Local Variables:
  92. * mode: c
  93. * c-basic-offset: 8
  94. * fill-column: 78
  95. * End:
  96. */