⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tif_ojpeg.c

📁 奇趣公司比较新的qt/emd版本
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $Id: tif_ojpeg.c,v 1.16 2006/03/01 11:09:13 dron Exp $ */#include "tiffiop.h"#ifdef OJPEG_SUPPORT/* JPEG Compression support, as per the original TIFF 6.0 specification.   WARNING: KLUDGE ALERT!  The type of JPEG encapsulation defined by the TIFF                           Version 6.0 specification is now totally obsolete and   deprecated for new applications and images.  This file is an unsupported hack   that was created solely in order to read (but NOT write!) a few old,   unconverted images still present on some users' computer systems.  The code   isn't pretty or robust, and it won't read every "old format" JPEG-in-TIFF   file (see Samuel Leffler's draft "TIFF Technical Note No. 2" for a long and   incomplete list of known problems), but it seems to work well enough in the   few cases of practical interest to the author; so, "caveat emptor"!  This   file should NEVER be enhanced to write new images using anything other than   the latest approved JPEG-in-TIFF encapsulation method, implemented by the   "tif_jpeg.c" file elsewhere in this library.   This file interfaces with Release 6B of the JPEG Library written by theu   Independent JPEG Group, which you can find on the Internet at:   ftp://ftp.uu.net:/graphics/jpeg/.   The "C" Preprocessor macros, "[CD]_LOSSLESS_SUPPORTED", are defined by your   JPEG Library Version 6B only if you have applied a (massive!) patch by Ken   Murchison of Oceana Matrix Ltd. <ken@oceana.com> to support lossless Huffman   encoding (TIFF "JPEGProc" tag value = 14).  This patch can be found on the   Internet at: ftp://ftp.oceana.com/pub/ljpeg-6b.tar.gz.   Some old files produced by the Wang Imaging application for Microsoft Windows   apparently can be decoded only with a special patch to the JPEG Library,   which defines a subroutine named "jpeg_reset_huff_decode()" in its "jdhuff.c"   module (the "jdshuff.c" module, if Ken Murchison's patch has been applied).   Unfortunately the patch differs slightly in each case, and some TIFF Library   have reported problems finding the code, so both versions appear below; you   should carefully extract and apply only the version that applies to your JPEG   Library!   Contributed by Scott Marovich <marovich@hpl.hp.com> with considerable help   from Charles Auer <Bumble731@msn.com> to unravel the mysteries of image files   created by the Wang Imaging application for Microsoft Windows.*/#if 0  /* Patch for JPEG Library WITHOUT lossless Huffman coding */*** jdhuff.c.orig	Mon Oct 20 17:51:10 1997--- jdhuff.c	Sun Nov 11 17:33:58 2001****************** 648,651 ****--- 648,683 ----    for (i = 0; i < NUM_HUFF_TBLS; i++) {      entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;    }  }+ + /*+  * BEWARE OF KLUDGE:  This subroutine is a hack for decoding illegal JPEG-in-+  *                    TIFF encapsulations produced by Microsoft's Wang Imaging+  * for Windows application with the public-domain TIFF Library.  Based upon an+  * examination of selected output files, this program apparently divides a JPEG+  * bit-stream into consecutive horizontal TIFF "strips", such that the JPEG+  * encoder's/decoder's DC coefficients for each image component are reset before+  * each "strip".  Moreover, a "strip" is not necessarily encoded in a multiple+  * of 8 bits, so one must sometimes discard 1-7 bits at the end of each "strip"+  * for alignment to the next input-Byte storage boundary.  IJG JPEG Library+  * decoder state is not normally exposed to client applications, so this sub-+  * routine provides the TIFF Library with a "hook" to make these corrections.+  * It should be called after "jpeg_start_decompress()" and before+  * "jpeg_finish_decompress()", just before decoding each "strip" using+  * "jpeg_read_raw_data()" or "jpeg_read_scanlines()".+  *+  * This kludge is not sanctioned or supported by the Independent JPEG Group, and+  * future changes to the IJG JPEG Library might invalidate it.  Do not send bug+  * reports about this code to IJG developers.  Instead, contact the author for+  * advice: Scott B. Marovich <marovich@hpl.hp.com>, Hewlett-Packard Labs, 6/01.+  */+ GLOBAL(void)+ jpeg_reset_huff_decode (register j_decompress_ptr cinfo)+ { register huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;+   register int ci = 0;+ +   /* Discard encoded input bits, up to the next Byte boundary */+   entropy->bitstate.bits_left &= ~7;+   /* Re-initialize DC predictions to 0 */+   do entropy->saved.last_dc_val[ci] = 0; while (++ci < cinfo->comps_in_scan);+ }#endif /* Patch for JPEG Library WITHOUT lossless Huffman coding */#if 0  /* Patch for JPEG Library WITH lossless Huffman coding */*** jdshuff.c.orig	Mon Mar 11 16:44:54 2002--- jdshuff.c	Mon Mar 11 16:44:54 2002****************** 357,360 ****--- 357,393 ----    for (i = 0; i < NUM_HUFF_TBLS; i++) {      entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;    }  }+ + /*+  * BEWARE OF KLUDGE:  This subroutine is a hack for decoding illegal JPEG-in-+  *                    TIFF encapsulations produced by Microsoft's Wang Imaging+  * for Windows application with the public-domain TIFF Library.  Based upon an+  * examination of selected output files, this program apparently divides a JPEG+  * bit-stream into consecutive horizontal TIFF "strips", such that the JPEG+  * encoder's/decoder's DC coefficients for each image component are reset before+  * each "strip".  Moreover, a "strip" is not necessarily encoded in a multiple+  * of 8 bits, so one must sometimes discard 1-7 bits at the end of each "strip"+  * for alignment to the next input-Byte storage boundary.  IJG JPEG Library+  * decoder state is not normally exposed to client applications, so this sub-+  * routine provides the TIFF Library with a "hook" to make these corrections.+  * It should be called after "jpeg_start_decompress()" and before+  * "jpeg_finish_decompress()", just before decoding each "strip" using+  * "jpeg_read_raw_data()" or "jpeg_read_scanlines()".+  *+  * This kludge is not sanctioned or supported by the Independent JPEG Group, and+  * future changes to the IJG JPEG Library might invalidate it.  Do not send bug+  * reports about this code to IJG developers.  Instead, contact the author for+  * advice: Scott B. Marovich <marovich@hpl.hp.com>, Hewlett-Packard Labs, 6/01.+  */+ GLOBAL(void)+ jpeg_reset_huff_decode (register j_decompress_ptr cinfo)+ { register shuff_entropy_ptr entropy = (shuff_entropy_ptr)+                                        ((j_lossy_d_ptr)cinfo->codec)->entropy_private;+   register int ci = 0;+ +   /* Discard encoded input bits, up to the next Byte boundary */+   entropy->bitstate.bits_left &= ~7;+   /* Re-initialize DC predictions to 0 */+   do entropy->saved.last_dc_val[ci] = 0; while (++ci < cinfo->comps_in_scan);+ }#endif /* Patch for JPEG Library WITH lossless Huffman coding */#include <setjmp.h>#include <stdio.h>#ifdef FAR#undef FAR /* Undefine FAR to avoid conflict with JPEG definition */#endif#define JPEG_INTERNALS /* Include "jpegint.h" for "DSTATE_*" symbols */#define JPEG_CJPEG_DJPEG /* Include all Version 6B+ "jconfig.h" options */#undef INLINE#include "jpeglib.h"#undef JPEG_CJPEG_DJPEG#undef JPEG_INTERNALS/* Hack for files produced by Wang Imaging application on Microsoft Windows */extern void jpeg_reset_huff_decode(j_decompress_ptr);/* On some machines, it may be worthwhile to use "_setjmp()" or "sigsetjmp()"   instead of "setjmp()".  These macros make it easier:*/#define SETJMP(jbuf)setjmp(jbuf)#define LONGJMP(jbuf,code)longjmp(jbuf,code)#define JMP_BUF jmp_buf#define TIFFTAG_WANG_PAGECONTROL 32934/* Bit-vector offsets for keeping track of TIFF records that we've parsed. */#define FIELD_JPEGPROC FIELD_CODEC#define FIELD_JPEGIFOFFSET (FIELD_CODEC+1)#define FIELD_JPEGIFBYTECOUNT (FIELD_CODEC+2)#define FIELD_JPEGRESTARTINTERVAL (FIELD_CODEC+3)#define FIELD_JPEGTABLES (FIELD_CODEC+4) /* New, post-6.0 JPEG-in-TIFF tag! */#define FIELD_JPEGLOSSLESSPREDICTORS (FIELD_CODEC+5)#define FIELD_JPEGPOINTTRANSFORM (FIELD_CODEC+6)#define FIELD_JPEGQTABLES (FIELD_CODEC+7)#define FIELD_JPEGDCTABLES (FIELD_CODEC+8)#define FIELD_JPEGACTABLES (FIELD_CODEC+9)#define FIELD_WANG_PAGECONTROL (FIELD_CODEC+10)#define FIELD_JPEGCOLORMODE (FIELD_CODEC+11)typedef struct jpeg_destination_mgr jpeg_destination_mgr;typedef struct jpeg_source_mgr jpeg_source_mgr;typedef struct jpeg_error_mgr jpeg_error_mgr;/* State variable for each open TIFF file that uses "libjpeg" for JPEG   decompression.  (Note:  This file should NEVER perform JPEG compression   except in the manner implemented by the "tif_jpeg.c" file, elsewhere in this   library; see comments above.)  JPEG Library internal state is recorded in a   "jpeg_{de}compress_struct", while a "jpeg_common_struct" records a few items   common to both compression and expansion.  The "cinfo" field containing JPEG   Library state MUST be the 1st member of our own state variable, so that we   can safely "cast" pointers back and forth.*/typedef struct             /* This module's private, per-image state variable */  {    union         /* JPEG Library state variable; this MUST be our 1st field! */      {        struct jpeg_compress_struct c;        struct jpeg_decompress_struct d;        struct jpeg_common_struct comm;      } cinfo;    jpeg_error_mgr err;                         /* JPEG Library error manager */    JMP_BUF exit_jmpbuf;             /* ...for catching JPEG Library failures */#   ifdef never /* (The following two fields could be a "union", but they're small enough that    it's not worth the effort.) */    jpeg_destination_mgr dest;             /* Destination for compressed data */#   endif    jpeg_source_mgr src;                           /* Source of expanded data */    JSAMPARRAY ds_buffer[MAX_COMPONENTS]; /* ->Temporary downsampling buffers */    TIFF *tif;                        /* Reverse pointer, needed by some code */    TIFFVGetMethod vgetparent;                    /* "Super class" methods... */    TIFFVSetMethod vsetparent;    TIFFStripMethod defsparent;    TIFFTileMethod deftparent;    void *jpegtables;           /* ->"New" JPEG tables, if we synthesized any */    uint32 is_WANG,    /* <=> Wang Imaging for Microsoft Windows output file? */           jpegtables_length;   /* Length of "new" JPEG tables, if they exist */    tsize_t bytesperline;          /* No. of decompressed Bytes per scan line */    int jpegquality,                             /* Compression quality level */        jpegtablesmode,                          /* What to put in JPEGTables */        samplesperclump,        scancount;                           /* No. of scan lines accumulated */    J_COLOR_SPACE photometric;          /* IJG JPEG Library's photometry code */    unsigned char h_sampling,                          /* Luminance sampling factors */           v_sampling,           jpegcolormode;           /* Who performs RGB <-> YCbCr conversion? */			/* JPEGCOLORMODE_RAW <=> TIFF Library or its client */			/* JPEGCOLORMODE_RGB <=> JPEG Library               */    /* These fields are added to support TIFFGetField */    uint16 jpegproc;    uint32 jpegifoffset;    uint32 jpegifbytecount;    uint32 jpegrestartinterval;    void* jpeglosslesspredictors;    uint16 jpeglosslesspredictors_length;    void* jpegpointtransform;    uint32 jpegpointtransform_length;    void* jpegqtables;    uint32 jpegqtables_length;    void* jpegdctables;    uint32 jpegdctables_length;    void* jpegactables;    uint32 jpegactables_length;  } OJPEGState;#define OJState(tif)((OJPEGState*)(tif)->tif_data)static const TIFFFieldInfo ojpegFieldInfo[]=/* JPEG-specific TIFF-record tags */  { /* This is the current JPEG-in-TIFF metadata-encapsulation tag, and its    treatment in this file is idiosyncratic.  It should never appear in a    "source" image conforming to the TIFF Version 6.0 specification, so we    arrange to report an error if it appears.  But in order to support possible    future conversion of "old" JPEG-in-TIFF encapsulations to "new" ones, we    might wish to synthesize an equivalent value to be returned by the TIFF    Library's "getfield" method.  So, this table tells the TIFF Library to pass    these records to us in order to filter them below. */    {      TIFFTAG_JPEGTABLES            ,TIFF_VARIABLE2,TIFF_VARIABLE2,      TIFF_UNDEFINED,FIELD_JPEGTABLES            ,FALSE,TRUE ,"JPEGTables"    }, /* These tags are defined by the TIFF Version 6.0 specification and are now    obsolete.  This module reads them from an old "source" image, but it never    writes them to a new "destination" image. */    {      TIFFTAG_JPEGPROC              ,1            ,1            ,      TIFF_SHORT    ,FIELD_JPEGPROC              ,FALSE,FALSE,"JPEGProc"    },    {      TIFFTAG_JPEGIFOFFSET          ,1            ,1            ,      TIFF_LONG     ,FIELD_JPEGIFOFFSET          ,FALSE,FALSE,"JPEGInterchangeFormat"    },    {      TIFFTAG_JPEGIFBYTECOUNT       ,1            ,1            ,      TIFF_LONG     ,FIELD_JPEGIFBYTECOUNT       ,FALSE,FALSE,"JPEGInterchangeFormatLength"    },    {      TIFFTAG_JPEGRESTARTINTERVAL   ,1            ,1            ,      TIFF_SHORT    ,FIELD_JPEGRESTARTINTERVAL   ,FALSE,FALSE,"JPEGRestartInterval"    },    {      TIFFTAG_JPEGLOSSLESSPREDICTORS,TIFF_VARIABLE,TIFF_VARIABLE,      TIFF_SHORT    ,FIELD_JPEGLOSSLESSPREDICTORS,FALSE,TRUE ,"JPEGLosslessPredictors"    },    {      TIFFTAG_JPEGPOINTTRANSFORM    ,TIFF_VARIABLE,TIFF_VARIABLE,      TIFF_SHORT    ,FIELD_JPEGPOINTTRANSFORM    ,FALSE,TRUE ,"JPEGPointTransforms"    },    {      TIFFTAG_JPEGQTABLES           ,TIFF_VARIABLE,TIFF_VARIABLE,      TIFF_LONG     ,FIELD_JPEGQTABLES           ,FALSE,TRUE ,"JPEGQTables"    },    {      TIFFTAG_JPEGDCTABLES          ,TIFF_VARIABLE,TIFF_VARIABLE,      TIFF_LONG     ,FIELD_JPEGDCTABLES          ,FALSE,TRUE ,"JPEGDCTables"    },    {      TIFFTAG_JPEGACTABLES          ,TIFF_VARIABLE,TIFF_VARIABLE,      TIFF_LONG     ,FIELD_JPEGACTABLES          ,FALSE,TRUE ,"JPEGACTables"    },    {      TIFFTAG_WANG_PAGECONTROL      ,TIFF_VARIABLE,1            ,      TIFF_LONG     ,FIELD_WANG_PAGECONTROL      ,FALSE,FALSE,"WANG PageControl"    }, /* This is a pseudo tag intended for internal use only by the TIFF Library and    its clients, which should never appear in an input/output image file.  It    specifies whether the TIFF Library (or its client) should do YCbCr <-> RGB    color-space conversion (JPEGCOLORMODE_RAW <=> 0) or whether we should ask    the JPEG Library to do it (JPEGCOLORMODE_RGB <=> 1). */    {      TIFFTAG_JPEGCOLORMODE         ,0            ,0            ,      TIFF_ANY      ,FIELD_PSEUDO                ,FALSE,FALSE,"JPEGColorMode"    }  };static const char JPEGLib_name[]={"JPEG Library"},                  bad_bps[]={"%u BitsPerSample not allowed for JPEG"},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -