< prev index next >

modules/javafx.graphics/src/main/native-iio/libjpeg7/jcparam.c

Print this page

        

*** 1,10 **** /* * jcparam.c * * Copyright (C) 1991-1998, Thomas G. Lane. ! * Modified 2003-2008 by Guido Vollbeding. * 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 --- 1,10 ---- /* * jcparam.c * * Copyright (C) 1991-1998, Thomas G. Lane. ! * Modified 2003-2013 by Guido Vollbeding. * 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
*** 148,158 **** 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); --- 148,158 ---- 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 routines directly. */ { /* Convert user 0-100 rating to percentage scaling */ quality = jpeg_quality_scaling(quality);
*** 321,342 **** cinfo->num_scans = 0; /* Expect normal source image, not raw downsampled data */ cinfo->raw_data_in = FALSE; ! /* Use Huffman coding, not arithmetic coding, by default */ ! cinfo->arith_code = FALSE; /* By default, don't do extra passes to optimize entropy coding */ cinfo->optimize_coding = FALSE; - /* The standard Huffman tables are only valid for 8-bit data precision. - * If the precision is higher, force optimization on so that usable - * tables will be computed. This test can be removed if default tables - * are supplied that are valid for the desired precision. - */ - if (cinfo->data_precision > 8) - cinfo->optimize_coding = TRUE; /* By default, use the simpler non-cosited sampling alignment */ cinfo->CCIR601_sampling = FALSE; /* By default, apply fancy downsampling */ --- 321,341 ---- cinfo->num_scans = 0; /* Expect normal source image, not raw downsampled data */ cinfo->raw_data_in = FALSE; ! /* The standard Huffman tables are only valid for 8-bit data precision. ! * If the precision is higher, use arithmetic coding. ! * (Alternatively, using Huffman coding would be possible with forcing ! * optimization on so that usable tables will be computed, or by ! * supplying default tables that are valid for the desired precision.) ! * Otherwise, use Huffman coding by default. ! */ ! cinfo->arith_code = cinfo->data_precision > 8 ? TRUE : FALSE; /* By default, don't do extra passes to optimize entropy coding */ cinfo->optimize_coding = FALSE; /* By default, use the simpler non-cosited sampling alignment */ cinfo->CCIR601_sampling = FALSE; /* By default, apply fancy downsampling */
*** 358,374 **** --- 357,379 ---- * By default, the library emits JFIF version code 1.01. * An application that wants to emit JFIF 1.02 extension markers should set * JFIF_minor_version to 2. We could probably get away with just defaulting * to 1.02, but there may still be some decoders in use that will complain * about that; saying 1.01 should minimize compatibility problems. + * + * For wide gamut colorspaces (BG_RGB and BG_YCC), the major version will be + * overridden by jpeg_set_colorspace and set to 2. */ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ cinfo->JFIF_minor_version = 1; cinfo->density_unit = 0; /* Pixel size is unknown by default */ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ cinfo->Y_density = 1; + /* No color transform */ + cinfo->color_transform = JCT_NONE; + /* Choose JPEG colorspace based on input space, set defaults accordingly */ jpeg_default_colorspace(cinfo); }
*** 379,388 **** --- 384,396 ---- GLOBAL(void) jpeg_default_colorspace (j_compress_ptr cinfo) { switch (cinfo->in_color_space) { + case JCS_UNKNOWN: + jpeg_set_colorspace(cinfo, JCS_UNKNOWN); + break; case JCS_GRAYSCALE: jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); break; case JCS_RGB: jpeg_set_colorspace(cinfo, JCS_YCbCr);
*** 394,405 **** jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */ break; case JCS_YCCK: jpeg_set_colorspace(cinfo, JCS_YCCK); break; ! case JCS_UNKNOWN: ! jpeg_set_colorspace(cinfo, JCS_UNKNOWN); break; default: ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); } } --- 402,417 ---- jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */ break; case JCS_YCCK: jpeg_set_colorspace(cinfo, JCS_YCCK); break; ! case JCS_BG_RGB: ! /* No translation for now -- conversion to BG_YCC not yet supportet */ ! jpeg_set_colorspace(cinfo, JCS_BG_RGB); ! break; ! case JCS_BG_YCC: ! jpeg_set_colorspace(cinfo, JCS_BG_YCC); break; default: ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); } }
*** 436,466 **** cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */ cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ switch (colorspace) { case JCS_GRAYSCALE: cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->num_components = 1; /* JFIF specifies component ID 1 */ ! SET_COMP(0, 1, 1,1, 0, 0,0); break; case JCS_RGB: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ cinfo->num_components = 3; ! SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); ! SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); break; case JCS_YCbCr: cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->num_components = 3; /* JFIF specifies component IDs 1,2,3 */ /* We default to 2x2 subsamples of chrominance */ ! SET_COMP(0, 1, 2,2, 0, 0,0); ! SET_COMP(1, 2, 1,1, 1, 1,1); ! SET_COMP(2, 3, 1,1, 1, 1,1); break; case JCS_CMYK: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ cinfo->num_components = 4; SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0); --- 448,491 ---- cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */ cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ switch (colorspace) { + case JCS_UNKNOWN: + cinfo->num_components = cinfo->input_components; + if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + for (ci = 0; ci < cinfo->num_components; ci++) { + SET_COMP(ci, ci, 1,1, 0, 0,0); + } + break; case JCS_GRAYSCALE: cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->num_components = 1; /* JFIF specifies component ID 1 */ ! SET_COMP(0, 0x01, 1,1, 0, 0,0); break; case JCS_RGB: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ cinfo->num_components = 3; ! SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); ! SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); break; case JCS_YCbCr: cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->num_components = 3; /* JFIF specifies component IDs 1,2,3 */ /* We default to 2x2 subsamples of chrominance */ ! SET_COMP(0, 0x01, 2,2, 0, 0,0); ! SET_COMP(1, 0x02, 1,1, 1, 1,1); ! SET_COMP(2, 0x03, 1,1, 1, 1,1); break; case JCS_CMYK: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ cinfo->num_components = 4; SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
*** 469,491 **** SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); break; case JCS_YCCK: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ cinfo->num_components = 4; ! SET_COMP(0, 1, 2,2, 0, 0,0); ! SET_COMP(1, 2, 1,1, 1, 1,1); ! SET_COMP(2, 3, 1,1, 1, 1,1); ! SET_COMP(3, 4, 2,2, 0, 0,0); break; ! case JCS_UNKNOWN: ! cinfo->num_components = cinfo->input_components; ! if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) ! ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ! MAX_COMPONENTS); ! for (ci = 0; ci < cinfo->num_components; ci++) { ! SET_COMP(ci, ci, 1,1, 0, 0,0); ! } break; default: ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); } } --- 494,530 ---- SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); break; case JCS_YCCK: cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ cinfo->num_components = 4; ! SET_COMP(0, 0x01, 2,2, 0, 0,0); ! SET_COMP(1, 0x02, 1,1, 1, 1,1); ! SET_COMP(2, 0x03, 1,1, 1, 1,1); ! SET_COMP(3, 0x04, 2,2, 0, 0,0); break; ! case JCS_BG_RGB: ! cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ ! cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */ ! cinfo->num_components = 3; ! /* Add offset 0x20 to the normal R/G/B component IDs */ ! SET_COMP(0, 0x72 /* 'r' */, 1,1, 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); ! SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0); ! SET_COMP(2, 0x62 /* 'b' */, 1,1, 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, ! cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); ! break; ! case JCS_BG_YCC: ! cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ ! cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */ ! cinfo->num_components = 3; ! /* Add offset 0x20 to the normal Cb/Cr component IDs */ ! /* We default to 2x2 subsamples of chrominance */ ! SET_COMP(0, 0x01, 2,2, 0, 0,0); ! SET_COMP(1, 0x22, 1,1, 1, 1,1); ! SET_COMP(2, 0x23, 1,1, 1, 1,1); break; default: ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); } }
*** 565,576 **** /* Safety check to ensure start_compress not called yet. */ if (cinfo->global_state != CSTATE_START) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Figure space needed for script. Calculation must match code below! */ ! if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { ! /* Custom script for YCbCr color images. */ nscans = 10; } else { /* All-purpose script for other color spaces. */ if (ncomps > MAX_COMPS_IN_SCAN) nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ --- 604,617 ---- /* Safety check to ensure start_compress not called yet. */ if (cinfo->global_state != CSTATE_START) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Figure space needed for script. Calculation must match code below! */ ! if (ncomps == 3 && ! (cinfo->jpeg_color_space == JCS_YCbCr || ! cinfo->jpeg_color_space == JCS_BG_YCC)) { ! /* Custom script for YCC color images. */ nscans = 10; } else { /* All-purpose script for other color spaces. */ if (ncomps > MAX_COMPS_IN_SCAN) nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
*** 581,591 **** /* Allocate space for script. * We need to put it in the permanent pool in case the application performs * multiple compressions without changing the settings. To avoid a memory * leak if jpeg_simple_progression is called repeatedly for the same JPEG * object, we try to re-use previously allocated space, and we allocate ! * enough space to handle YCbCr even if initially asked for grayscale. */ if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { cinfo->script_space_size = MAX(nscans, 10); cinfo->script_space = (jpeg_scan_info *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, --- 622,632 ---- /* Allocate space for script. * We need to put it in the permanent pool in case the application performs * multiple compressions without changing the settings. To avoid a memory * leak if jpeg_simple_progression is called repeatedly for the same JPEG * object, we try to re-use previously allocated space, and we allocate ! * enough space to handle YCC even if initially asked for grayscale. */ if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { cinfo->script_space_size = MAX(nscans, 10); cinfo->script_space = (jpeg_scan_info *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
*** 593,604 **** } scanptr = cinfo->script_space; cinfo->scan_info = scanptr; cinfo->num_scans = nscans; ! if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { ! /* Custom script for YCbCr color images. */ /* Initial DC scan */ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); /* Initial AC scan: get some luma data out in a hurry */ scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); /* Chroma data is too small to be worth expending many scans on */ --- 634,647 ---- } scanptr = cinfo->script_space; cinfo->scan_info = scanptr; cinfo->num_scans = nscans; ! if (ncomps == 3 && ! (cinfo->jpeg_color_space == JCS_YCbCr || ! cinfo->jpeg_color_space == JCS_BG_YCC)) { ! /* Custom script for YCC color images. */ /* Initial DC scan */ scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); /* Initial AC scan: get some luma data out in a hurry */ scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); /* Chroma data is too small to be worth expending many scans on */
< prev index next >