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

📄 tif_ojpeg.c

📁 一个国人自己实现图像库的程序(有参考价值)
💻 C
📖 第 1 页 / 共 5 页
字号:
TIFFojpeg_read_header(register OJPEGState *sp,boolean require_image)  {return CALLJPEG(sp,-1,jpeg_read_header(&sp->cinfo.d,require_image));}static intTIFFojpeg_read_raw_data(register OJPEGState *sp,JSAMPIMAGE data,int max_lines)  {    return      CALLJPEG(sp,-1,(int)jpeg_read_raw_data(&sp->cinfo.d,data,(JDIMENSION)max_lines));  }static intTIFFojpeg_read_scanlines(register OJPEGState *sp,JSAMPARRAY scanlines,                        int max_lines)  { return      CALLJPEG(sp,-1,(int)jpeg_read_scanlines(&sp->cinfo.d,scanlines,(JDIMENSION)max_lines));  }static intTIFFojpeg_start_decompress(register OJPEGState *sp)  {return CALLVJPEG(sp,jpeg_start_decompress(&sp->cinfo.d));}#ifdef never/* The following subroutines comprise a JPEG Library "destination" data manager   by directing compressed data from the JPEG Library to a TIFF Library output   buffer.*/static voidstd_init_destination(register j_compress_ptr cinfo){} /* "Dummy" stub */static booleanstd_empty_output_buffer(register j_compress_ptr cinfo)  {#   define sp ((OJPEGState *)cinfo)    register TIFF *tif = sp->tif;    tif->tif_rawcc = tif->tif_rawdatasize; /* Entire buffer has been filled */    TIFFFlushData1(tif);    sp->dest.next_output_byte = (JOCTET *)tif->tif_rawdata;    sp->dest.free_in_buffer = (size_t)tif->tif_rawdatasize;    return TRUE;#   undef sp  }static voidstd_term_destination(register j_compress_ptr cinfo)  {#   define sp ((OJPEGState *)cinfo)    register TIFF *tif = sp->tif; /* NB: The TIFF Library does the final buffer flush. */    tif->tif_rawcp = (tidata_t)sp->dest.next_output_byte;    tif->tif_rawcc = tif->tif_rawdatasize - (tsize_t)sp->dest.free_in_buffer;#   undef sp  }/*ARGSUSED*/ static voidTIFFojpeg_data_dest(register OJPEGState *sp,TIFF *tif)  {    sp->cinfo.c.dest = &sp->dest;    sp->dest.init_destination = std_init_destination;    sp->dest.empty_output_buffer = std_empty_output_buffer;    sp->dest.term_destination = std_term_destination;  }/* Alternate destination manager to output JPEGTables field: */static voidtables_init_destination(register j_compress_ptr cinfo)  {#   define sp ((OJPEGState *)cinfo) /* The "jpegtables_length" field is the allocated buffer size while building */    sp->dest.next_output_byte = (JOCTET *)sp->jpegtables;    sp->dest.free_in_buffer = (size_t)sp->jpegtables_length;#   undef sp  }static booleantables_empty_output_buffer(register j_compress_ptr cinfo)  { void *newbuf;#   define sp ((OJPEGState *)cinfo) /* The entire buffer has been filled, so enlarge it by 1000 bytes. */    if (!( newbuf = _TIFFrealloc( (tdata_t)sp->jpegtables                                , (tsize_t)(sp->jpegtables_length + 1000)                                )         )       ) ERREXIT1(cinfo,JERR_OUT_OF_MEMORY,100);    sp->dest.next_output_byte = (JOCTET *)newbuf + sp->jpegtables_length;    sp->dest.free_in_buffer = (size_t)1000;    sp->jpegtables = newbuf;    sp->jpegtables_length += 1000;    return TRUE;#   undef sp  }static voidtables_term_destination(register j_compress_ptr cinfo)  {#   define sp ((OJPEGState *)cinfo) /* Set tables length to no. of Bytes actually emitted. */    sp->jpegtables_length -= sp->dest.free_in_buffer;#   undef sp  }/*ARGSUSED*/ static intTIFFojpeg_tables_dest(register OJPEGState *sp, TIFF *tif)  { /* Allocate a working buffer for building tables.  The initial size is 1000    Bytes, which is usually adequate. */    if (sp->jpegtables) _TIFFfree(sp->jpegtables);    if (!(sp->jpegtables = (void*)                           _TIFFmalloc((tsize_t)(sp->jpegtables_length = 1000))         )       )      {        sp->jpegtables_length = 0;        TIFFError("TIFFojpeg_tables_dest",no_jtable_space);        return 0;      };    sp->cinfo.c.dest = &sp->dest;    sp->dest.init_destination = tables_init_destination;    sp->dest.empty_output_buffer = tables_empty_output_buffer;    sp->dest.term_destination = tables_term_destination;    return 1;  }#endif /* never *//* The following subroutines comprise a JPEG Library "source" data manager by   by directing compressed data to the JPEG Library from a TIFF Library input   buffer.*/static voidstd_init_source(register j_decompress_ptr cinfo)  {#   define sp ((OJPEGState *)cinfo)    register TIFF *tif = sp->tif;    if (sp->src.bytes_in_buffer == 0)      {        sp->src.next_input_byte = (const JOCTET *)tif->tif_rawdata;        sp->src.bytes_in_buffer = (size_t)tif->tif_rawcc;      };#   undef sp  }static booleanstd_fill_input_buffer(register j_decompress_ptr cinfo)  { static const JOCTET dummy_EOI[2]={0xFF,JPEG_EOI};#   define sp ((OJPEGState *)cinfo) /* Control should never get here, since an entire strip/tile is read into    memory before the decompressor is called; thus, data should have been    supplied by the "init_source" method.  ...But, sometimes things fail. */    WARNMS(cinfo,JWRN_JPEG_EOF);    sp->src.next_input_byte = dummy_EOI; /* Insert a fake EOI marker */    sp->src.bytes_in_buffer = sizeof dummy_EOI;    return TRUE;#   undef sp  }static voidstd_skip_input_data(register j_decompress_ptr cinfo,long num_bytes)  {#   define sp ((OJPEGState *)cinfo)    if (num_bytes > 0)      if (num_bytes > (long)sp->src.bytes_in_buffer) /* oops: buffer overrun */        (void)std_fill_input_buffer(cinfo);      else        {          sp->src.next_input_byte += (size_t)num_bytes;          sp->src.bytes_in_buffer -= (size_t)num_bytes;        }#   undef sp  }/*ARGSUSED*/ static voidstd_term_source(register j_decompress_ptr cinfo){} /* "Dummy" stub *//* Allocate temporary I/O buffers for downsampled data, using values computed in   "jpeg_start_{de}compress()".  We use the JPEG Library's allocator so that   buffers will be released automatically when done with a strip/tile.  This is   also a handy place to compute samplesperclump, bytesperline, etc.*/static intalloc_downsampled_buffers(TIFF *tif,jpeg_component_info *comp_info,                          int num_components)  { register OJPEGState *sp = OJState(tif);    sp->samplesperclump = 0;    if (num_components > 0)      { int ci = 0;        register jpeg_component_info *compptr = comp_info;        do          { JSAMPARRAY buf;            sp->samplesperclump +=              compptr->h_samp_factor * compptr->v_samp_factor;            if (!(buf = TIFFojpeg_alloc_sarray( sp                                              , JPOOL_IMAGE                                              , compptr->width_in_blocks*DCTSIZE                                              , compptr->v_samp_factor  *DCTSIZE                                              )                 )               ) return 0;            sp->ds_buffer[ci] = buf;          }        while (++compptr,++ci < num_components);      };    return 1;  }#ifdef never/* JPEG Encoding begins here. */static voidunsuppress_quant_table(register OJPEGState *sp,int tblno)  { register JQUANT_TBL *qtbl;    if (qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) qtbl->sent_table = FALSE;  }static voidunsuppress_huff_table(register OJPEGState *sp,register int tblno)  { register JHUFF_TBL *htbl;    if (   (htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno])        || (htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno])       ) htbl->sent_table = FALSE;  }static intprepare_JPEGTables(register TIFF *tif)  { register OJPEGState *sp = OJState(tif); /* Initialize quantization tables for the current quality setting, and mark for    output only the tables that we want.  Note that chrominance tables are    currently used only with YCbCr. */    if (   !TIFFojpeg_set_quality(sp,sp->jpegquality,FALSE);        || !TIFFojpeg_suppress_tables(sp,TRUE)       ) return 0;    if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)      {        unsuppress_quant_table(sp,0);        if (sp->photometric == PHOTOMETRIC_YCBCR) unsuppress_quant_table(sp,1);      }    if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF)      {        unsuppress_huff_table(sp,0);        if (sp->photometric == PHOTOMETRIC_YCBCR) unsuppress_huff_table(sp,1);      };    return TIFFojpeg_tables_dest(sp,tif) && TIFFojpeg_write_tables(sp);  }static intOJPEGSetupEncode(register TIFF *tif)  { static const char module[]={"OJPEGSetupEncode"};    register OJPEGState *sp = OJState(tif);#   define td (&tif->tif_dir) /* Verify miscellaneous parameters.  This will need work if the TIFF Library    ever supports different depths for different components, or if the JPEG    Library ever supports run-time depth selection.  Neither seems imminent. */    if (td->td_bitspersample != BITS_IN_JSAMPLE)      {        TIFFError(module,bad_bps,td->td_bitspersample);        return 0;      }; /* Initialize all JPEG parameters to default values.  Note that the JPEG    Library's "jpeg_set_defaults()" method needs legal values for the    "in_color_space" and "input_components" fields. */    sp->cinfo.c.in_color_space = JCS_UNKNOWN;    sp->cinfo.c.input_components = 1;    if (!TIFFojpeg_set_defaults(sp)) return 0;    switch (sp->photometric = td->td_photometric) /* set per-file parameters */      {        case PHOTOMETRIC_YCBCR:          sp->h_sampling = td->td_ycbcrsubsampling[0];          sp->v_sampling = td->td_ycbcrsubsampling[1];#         ifdef COLORIMETRY_SUPPORT       /* A ReferenceBlackWhite field MUST be present, since the default value          is inapproriate for YCbCr.  Fill in the proper value if application          didn't set it.       */          if (!TIFFFieldSet(tif,FIELD_REFBLACKWHITE))            { float refbw[6];              long top = 1L << td->td_bitspersample;              refbw[0] = 0;              refbw[1] = (float)(top-1L);              refbw[2] = (float)(top>>1);              refbw[3] = refbw[1];              refbw[4] = refbw[2];              refbw[5] = refbw[1];              TIFFSetField(tif,TIFFTAG_REFERENCEBLACKWHITE,refbw);            };#         endif /* COLORIMETRY_SUPPORT */          break;        case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */        case PHOTOMETRIC_MASK:          TIFFError(module,"PhotometricInterpretation %d not allowed for JPEG",            (int)sp->photometric);          return 0;     /* TIFF 6.0 forbids subsampling of all other color spaces */        default: sp->h_sampling = sp->v_sampling = 1;      };    sp->cinfo.c.data_precision = td->td_bitspersample;    if (isTiled(tif))      {        if (td->td_tilelength % (sp->v_sampling*DCTSIZE))          {

⌨️ 快捷键说明

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