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

📄 jdapimin.c

📁 jpeg编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * jdapimin.c * * Copyright (C) 1994-1998, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * * This file contains application interface code for the decompression half * of the JPEG library.  These are the "minimum" API routines that may be * needed in either the normal full-decompression case or the * transcoding-only case. * * Most of the routines intended to be called directly by an application * are in this file or in jdapistd.c.  But also see jcomapi.c for routines * shared by compression and decompression, and jdtrans.c for the transcoding * case. */#define JPEG_INTERNALS#include "jinclude.h"#include "jpeglib.h"#include "attributes.h"#if defined(HAVE_MMX_INTEL_MNEMONICS) || defined(HAVE_MMX_ATT_MNEMONICS)int MMXAvailable;int mmxsupport() ATTR_NOINLINE;#endif/* * Initialization of a JPEG decompression object. * The error manager must already be set up (in case memory manager fails). */GLOBAL(void)jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize){  int i;#if defined(HAVE_MMX_INTEL_MNEMONICS) || defined(HAVE_MMX_ATT_MNEMONICS)  static int cpuidDetected = 0;  if(!cpuidDetected)  {    MMXAvailable = mmxsupport();    cpuidDetected = 1;  }#endif  /* For debugging purposes, zero the whole master structure.   * But error manager pointer is already there, so save and restore it.   */  /* Guard against version mismatches between library and caller. */  cinfo->mem = NULL;		/* so jpeg_destroy knows mem mgr not called */  if (version != JPEG_LIB_VERSION)    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);  if (structsize != SIZEOF(struct jpeg_decompress_struct))    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 	     (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);  /* For debugging purposes, we zero the whole master structure.   * But the application has already set the err pointer, and may have set   * client_data, so we have to save and restore those fields.   * Note: if application hasn't set client_data, tools like Purify may   * complain here.   */  {    struct jpeg_error_mgr * err = cinfo->err;    void * client_data = cinfo->client_data; /* ignore Purify complaint here */    MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));    cinfo->err = err;    cinfo->client_data = client_data;  }  cinfo->is_decompressor = TRUE;  /* Initialize a memory manager instance for this object */  jinit_memory_mgr((j_common_ptr) cinfo);  /* Zero out pointers to permanent structures. */  cinfo->progress = NULL;  cinfo->src = NULL;  for (i = 0; i < NUM_QUANT_TBLS; i++)    cinfo->quant_tbl_ptrs[i] = NULL;  for (i = 0; i < NUM_HUFF_TBLS; i++) {    cinfo->dc_huff_tbl_ptrs[i] = NULL;    cinfo->ac_huff_tbl_ptrs[i] = NULL;  }  /* Initialize marker processor so application can override methods   * for COM, APPn markers before calling jpeg_read_header.   */  cinfo->marker_list = NULL;  jinit_marker_reader(cinfo);  /* And initialize the overall input controller. */  jinit_input_controller(cinfo);  /* OK, I'm ready */  cinfo->global_state = DSTATE_START;}/* * Destruction of a JPEG decompression object */GLOBAL(void)jpeg_destroy_decompress (j_decompress_ptr cinfo){  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */}/* * Abort processing of a JPEG decompression operation, * but don't destroy the object itself. */GLOBAL(void)jpeg_abort_decompress (j_decompress_ptr cinfo){  jpeg_abort((j_common_ptr) cinfo); /* use common routine */}/* * Set default decompression parameters. */LOCAL(void)default_decompress_parms (j_decompress_ptr cinfo){  /* Guess the input colorspace, and set output colorspace accordingly. */  /* (Wish JPEG committee had provided a real way to specify this...) */  /* Note application may override our guesses. */  switch (cinfo->num_components) {  case 1:    cinfo->jpeg_color_space = JCS_GRAYSCALE;    cinfo->out_color_space = JCS_GRAYSCALE;    break;      case 3:    if (cinfo->saw_JFIF_marker) {      cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */    } else if (cinfo->saw_Adobe_marker) {      switch (cinfo->Adobe_transform) {      case 0:	cinfo->jpeg_color_space = JCS_RGB;	break;      case 1:	cinfo->jpeg_color_space = JCS_YCbCr;	break;      default:	WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);	cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */	break;      }    } else {      /* Saw no special markers, try to guess from the component IDs */      int cid0 = cinfo->comp_info[0].component_id;      int cid1 = cinfo->comp_info[1].component_id;      int cid2 = cinfo->comp_info[2].component_id;      if (cid0 == 1 && cid1 == 2 && cid2 == 3)	cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */      else if (cid0 == 82 && cid1 == 71 && cid2 == 66)	cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */      else {	TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);	cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */      }    }    /* Always guess RGB is proper output colorspace. */    cinfo->out_color_space = JCS_RGB;    break;      case 4:    if (cinfo->saw_Adobe_marker) {      switch (cinfo->Adobe_transform) {      case 0:	cinfo->jpeg_color_space = JCS_CMYK;	break;      case 2:	cinfo->jpeg_color_space = JCS_YCCK;	break;      default:	WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);	cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */	break;      }    } else {      /* No special markers, assume straight CMYK. */      cinfo->jpeg_color_space = JCS_CMYK;    }    cinfo->out_color_space = JCS_CMYK;    break;      default:    cinfo->jpeg_color_space = JCS_UNKNOWN;    cinfo->out_color_space = JCS_UNKNOWN;    break;  }  /* Set defaults for other decompression parameters. */  cinfo->scale_num = 1;		/* 1:1 scaling */  cinfo->scale_denom = 1;  cinfo->output_gamma = 1.0;  cinfo->buffered_image = FALSE;  cinfo->raw_data_out = FALSE;  cinfo->dct_method = JDCT_DEFAULT;  cinfo->do_fancy_upsampling = TRUE;  cinfo->do_block_smoothing = TRUE;  cinfo->quantize_colors = FALSE;  /* We set these in case application only sets quantize_colors. */  cinfo->dither_mode = JDITHER_FS;#ifdef QUANT_2PASS_SUPPORTED  cinfo->two_pass_quantize = TRUE;#else  cinfo->two_pass_quantize = FALSE;#endif  cinfo->desired_number_of_colors = 256;  cinfo->colormap = NULL;  /* Initialize for no mode change in buffered-image mode. */  cinfo->enable_1pass_quant = FALSE;  cinfo->enable_external_quant = FALSE;  cinfo->enable_2pass_quant = FALSE;}/* * Decompression startup: read start of JPEG datastream to see what's there. * Need only initialize JPEG object and supply a data source before calling. * * This routine will read as far as the first SOS marker (ie, actual start of * compressed data), and will save all tables and parameters in the JPEG * object.  It will also initialize the decompression parameters to default * values, and finally return JPEG_HEADER_OK.  On return, the application may * adjust the decompression parameters and then call jpeg_start_decompress. * (Or, if the application only wanted to determine the image parameters, * the data need not be decompressed.  In that case, call jpeg_abort or * jpeg_destroy to release any temporary space.) * If an abbreviated (tables only) datastream is presented, the routine will * return JPEG_HEADER_TABLES_ONLY upon reaching EOI.  The application may then * re-use the JPEG object to read the abbreviated image datastream(s). * It is unnecessary (but OK) to call jpeg_abort in this case. * The JPEG_SUSPENDED return code only occurs if the data source module * requests suspension of the decompressor.  In this case the application * should load more source data and then re-call jpeg_read_header to resume * processing. * If a non-suspending data source is used and require_image is TRUE, then the * return code need not be inspected since only JPEG_HEADER_OK is possible. * * This routine is now just a front end to jpeg_consume_input, with some * extra error checking. */

⌨️ 快捷键说明

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