?? jcparam.c
字號:
/* * jcparam.c * * Copyright (C) 1991-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 optional default-setting code for the JPEG compressor. * Applications do not have to use this file, but those that don't use it * must know a lot more about the innards of the JPEG code. */#define JPEG_INTERNALS#include "jinclude.h"#include "jpeglib.h"#define FIX1(X) (1L << 16) / (X) + 1JCS_YUV MCU_comb;/* * Quantization table setup routines */GLOBAL(void)jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)/* Define a quantization table equal to the basic_table times * a scale factor (given as a percentage). * If force_baseline is TRUE, the computed quantization table entries * are limited to 1..255 for JPEG baseline compatibility. */{ JQUANT_TBL ** qtblptr; int i,j; long temp; unsigned int *pqtbl; //pwhsu++ int invtemp; //pwhsu++ unsigned int qout; if (which_tbl==0){ //pwhsu++ pqtbl = qtbl0; }else if (which_tbl==1){ pqtbl = qtbl1; }else if (which_tbl==2){ pqtbl = qtbl2; }else if (which_tbl==3){ pqtbl = qtbl3; } /* Safety check to ensure start_compress not called yet. */ if (cinfo->global_state != CSTATE_START) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS) ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl); qtblptr = & cinfo->quant_tbl_ptrs[which_tbl]; if (*qtblptr == NULL) *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo); //for (i = 0; i < DCTSIZE2; i++) { for(i=0;i<8;i++){ for(j=0;j<8;j++){ //temp = ((long) basic_table[i] * scale_factor + 50L) / 100L; temp = ((long) basic_table[i+j*8] * scale_factor + 50L) / 100L; /* limit the values to the valid range */ if (temp <= 0L) temp = 1L; if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ if (force_baseline && temp > 255L) temp = 255L; /* limit to baseline range if requested */ (*qtblptr)->quantval[i] = (UINT16) temp; //pwhsu++:20031021 For internal quantization memory //rinfo.Inter_quant[which_tbl][i] = (UINT16) temp; rinfo.Inter_quant[which_tbl][i+j*8] = (UINT16) temp; //pwhsu++:20031021 //iqval and qval //pwhsu++:20040107 invtemp = FIX1((UINT16) temp); //pqtbl[i] = (unsigned int) ( ((invtemp & 0x1ffff)<<8) | (temp&0xff) ); //pqtbl[i*8+j] = (unsigned int) ( ((invtemp & 0x1ffff)<<8) | (temp&0xff) ); qout = (unsigned int) ( ((invtemp & 0x1ffff)<<8) | (temp&0xff) ); rinfo.QUTTBL[which_tbl][i*8+j] = qout; //pwhsu++:20040922/*#ifdef AHB_interface __asm{ STR qout, [pqtbl+(i*8+j)] }#else pqtbl[i*8+j] = qout;#endif*/ } } //} //end of DCTSIZE2 /* Initialize sent_table FALSE so table will be written to JPEG file. */ (*qtblptr)->sent_table = FALSE; }GLOBAL(void)jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, boolean force_baseline)/* Set or change the 'quality' (quantization) setting, using default tables * and a straight percentage-scaling quality scale. In most cases it's better * to use jpeg_set_quality (below); this entry point is provided for * applications that insist on a linear percentage scaling. */{ /* These are the sample quantization tables given in JPEG spec section K.1. * The spec says that the values given produce "good" quality, and * when divided by 2, "very good" quality. */ const unsigned int luma_qtbl_1[DCTSIZE2] = { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92, 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99 }; const unsigned int chroma_qtbl_1[DCTSIZE2] = { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 }; const unsigned int luma_qtbl_2[DCTSIZE2] = { 8, 5, 20, 25, 30, 27, 14, 25, 5, 12, 30, 29, 7, 11, 43, 27, 8, 6, 13, 6, 8, 40, 17, 32, 6, 9, 8, 7, 31, 12, 40, 60, 7, 12, 28, 9, 38, 52, 51, 60, 20, 34, 11, 51, 56, 43, 50, 56, 28, 18, 54, 46, 39, 36, 49, 50, 28, 34, 24, 32, 46, 47, 51, 49 }; const unsigned int chroma_qtbl_2[DCTSIZE2] = { 8, 9, 49, 49, 49, 49, 49, 49, 12, 49, 49, 49, 12, 49, 49, 49, 23, 9, 49, 13, 33, 49, 49, 49, 10, 33, 28, 23, 49, 49, 49, 49, 13, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 }; static const unsigned int *std_luminance_quant_tbl; static const unsigned int *std_chrominance_quant_tbl; if (qtbl_no==1){ std_luminance_quant_tbl = luma_qtbl_1; std_chrominance_quant_tbl = chroma_qtbl_1; }else{ std_luminance_quant_tbl = luma_qtbl_2; std_chrominance_quant_tbl = chroma_qtbl_2; } /* Set up two quantization tables using the specified scaling */ jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, scale_factor, force_baseline); jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, scale_factor, force_baseline);}GLOBAL(int)jpeg_quality_scaling (int quality)/* Convert a user-specified quality rating to a percentage scaling factor * for an underlying quantization table, using our recommended scaling curve. * The input 'quality' factor should be 0 (terrible) to 100 (very good). */{ /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */ if (quality <= 0) quality = 1; if (quality > 100) quality = 100; /* The basic table is used as-is (scaling 100) for a quality of 50. * Qualities 50..100 are converted to scaling percentage 200 - 2*Q; * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table * to make all the table entries 1 (hence, minimum quantization loss). * Qualities 1..50 are converted to scaling percentage 5000/Q. */ if (quality < 50) quality = 5000 / quality; else quality = 200 - quality*2; return quality;}GLOBAL(void)jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)/* Set or change the 'quality' (quantization) setting, using default tables. * This is the standard quality-adjusting entry point for typical user * interfaces; only those who want detailed control over quantization tables * would use the preceding three routines directly. */{ /* Convert user 0-100 rating to percentage scaling */ quality = jpeg_quality_scaling(quality); /* Set up standard quality tables */ jpeg_set_linear_quality(cinfo, quality, force_baseline);}/* * Huffman table setup routines */LOCAL(void)add_huff_table (j_compress_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)/* Define a Huffman table */{ int nsymbols, len;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -