tif_dir.c
上传用户:looem2003
上传日期:2014-07-20
资源大小:13733k
文件大小:39k
- /* $Id: tif_dir.c,v 1.72 2006/03/15 12:49:35 dron Exp $ */
- /*
- * Copyright (c) 1988-1997 Sam Leffler
- * Copyright (c) 1991-1997 Silicon Graphics, Inc.
- *
- * 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.
- *
- * 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,
- * 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.
- */
- /*
- * TIFF Library.
- *
- * Directory Tag Get & Set Routines.
- * (and also some miscellaneous stuff)
- */
- #include "tiffiop.h"
- /*
- * These are used in the backwards compatibility code...
- */
- #define DATATYPE_VOID 0 /* !untyped data */
- #define DATATYPE_INT 1 /* !signed integer data */
- #define DATATYPE_UINT 2 /* !unsigned integer data */
- #define DATATYPE_IEEEFP 3 /* !IEEE floating point data */
- static void
- setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
- {
- if (*vpp)
- _TIFFfree(*vpp), *vpp = 0;
- 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, uint32 n)
- { setByteArray(vpp, vp, n, 1); }
- void _TIFFsetString(char** cpp, char* cp)
- { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); }
- void _TIFFsetNString(char** cpp, char* cp, uint32 n)
- { setByteArray((void**) cpp, (void*) cp, n, 1); }
- void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
- { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
- void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
- { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }
- void _TIFFsetFloatArray(float** fpp, float* fp, uint32 n)
- { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); }
- void _TIFFsetDoubleArray(double** dpp, double* dp, uint32 n)
- { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); }
- /*
- * Install extra samples information.
- */
- static int
- setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v)
- {
- uint16* va;
- uint32 i;
- *v = va_arg(ap, uint32);
- if ((uint16) *v > td->td_samplesperpixel)
- return (0);
- va = va_arg(ap, uint16*);
- if (*v > 0 && va == NULL) /* typically missing param */
- return (0);
- for (i = 0; i < *v; i++)
- if (va[i] > EXTRASAMPLE_UNASSALPHA)
- return (0);
- td->td_extrasamples = (uint16) *v;
- _TIFFsetShortArray(&td->td_sampleinfo, va, td->td_extrasamples);
- return (1);
- }
- static uint32
- checkInkNamesString(TIFF* tif, uint32 slen, const char* s)
- {
- TIFFDirectory* td = &tif->tif_dir;
- uint16 i = td->td_samplesperpixel;
- if (slen > 0) {
- const char* ep = s+slen;
- const char* cp = s;
- for (; i > 0; i--) {
- for (; *cp != ' '; cp++)
- if (cp >= ep)
- goto bad;
- cp++; /* skip