Add support for JPEG input in cjpeg
This commit is contained in:
@@ -247,7 +247,7 @@ set_property(TARGET tjbench-static PROPERTY COMPILE_FLAGS
|
||||
"-DBMP_SUPPORTED -DPPM_SUPPORTED")
|
||||
|
||||
add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c
|
||||
rdtarga.c)
|
||||
rdtarga.c rdjpeg.c)
|
||||
set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS
|
||||
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED -DUSE_SETMODE")
|
||||
target_link_libraries(cjpeg-static jpeg-static)
|
||||
|
||||
@@ -108,7 +108,7 @@ endif
|
||||
|
||||
|
||||
cjpeg_SOURCES = cdjpeg.h cderror.h cdjpeg.c cjpeg.c rdbmp.c rdgif.c \
|
||||
rdppm.c rdswitch.c rdtarga.c
|
||||
rdppm.c rdswitch.c rdtarga.c rdjpeg.c
|
||||
|
||||
cjpeg_LDADD = libjpeg.la
|
||||
|
||||
|
||||
7
cdjpeg.h
7
cdjpeg.h
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* mozjpeg Modifications:
|
||||
* Copyright (C) 2014, Mozilla Corporation.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains common declarations for the sample applications
|
||||
@@ -35,6 +37,9 @@ struct cjpeg_source_struct {
|
||||
|
||||
JSAMPARRAY buffer;
|
||||
JDIMENSION buffer_height;
|
||||
|
||||
// For reading JPEG
|
||||
JSAMPARRAY plane_pointer[4];
|
||||
};
|
||||
|
||||
|
||||
@@ -94,6 +99,7 @@ typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
|
||||
#ifdef NEED_SHORT_EXTERNAL_NAMES
|
||||
#define jinit_read_bmp jIRdBMP
|
||||
#define jinit_write_bmp jIWrBMP
|
||||
#define jinit_read_jpeg jIRdJPG
|
||||
#define jinit_read_gif jIRdGIF
|
||||
#define jinit_write_gif jIWrGIF
|
||||
#define jinit_read_ppm jIRdPPM
|
||||
@@ -122,6 +128,7 @@ EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
|
||||
boolean is_os2));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_jpeg JPP((j_compress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
|
||||
|
||||
10
cjpeg.c
10
cjpeg.c
@@ -80,7 +80,7 @@ static const char * const cdjpeg_message_table[] = {
|
||||
*/
|
||||
|
||||
static boolean is_targa; /* records user -targa switch */
|
||||
|
||||
static boolean is_jpeg;
|
||||
|
||||
LOCAL(cjpeg_source_ptr)
|
||||
select_file_type (j_compress_ptr cinfo, FILE * infile)
|
||||
@@ -121,6 +121,9 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
|
||||
case 0x00:
|
||||
return jinit_read_targa(cinfo);
|
||||
#endif
|
||||
case 0xff:
|
||||
is_jpeg = TRUE;
|
||||
return jinit_read_jpeg(cinfo);
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
|
||||
break;
|
||||
@@ -683,7 +686,10 @@ main (int argc, char **argv)
|
||||
/* Process data */
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
|
||||
(void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
|
||||
if (is_jpeg)
|
||||
(void) jpeg_write_raw_data(&cinfo, src_mgr->plane_pointer, num_scanlines);
|
||||
else
|
||||
(void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
|
||||
}
|
||||
|
||||
/* Finish compression and release memory */
|
||||
|
||||
115
rdjpeg.c
Normal file
115
rdjpeg.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* rdjpeg.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* mozjpeg Modifications:
|
||||
* Copyright (C) 2014, Mozilla Corporation.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
|
||||
#define NUM_ROWS 16
|
||||
|
||||
/* Private version of data source object */
|
||||
|
||||
typedef struct _jpeg_source_struct * jpeg_source_ptr;
|
||||
|
||||
typedef struct _jpeg_source_struct {
|
||||
struct cjpeg_source_struct pub; /* public fields */
|
||||
|
||||
j_compress_ptr cinfo; /* back link saves passing separate parm */
|
||||
|
||||
struct jpeg_decompress_struct dinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
} jpeg_source_struct;
|
||||
|
||||
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
get_rows (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
jpeg_source_ptr source = (jpeg_source_ptr) sinfo;
|
||||
|
||||
jpeg_read_raw_data(&source->dinfo, source->pub.plane_pointer, NUM_ROWS);
|
||||
|
||||
return NUM_ROWS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read the file header; return image size and component count.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_input_jpeg (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
int i;
|
||||
jpeg_source_ptr source = (jpeg_source_ptr) sinfo;
|
||||
|
||||
source->dinfo.err = jpeg_std_error(&source->jerr);
|
||||
jpeg_create_decompress(&source->dinfo);
|
||||
jpeg_stdio_src(&source->dinfo, source->pub.input_file);
|
||||
jpeg_read_header(&source->dinfo, TRUE);
|
||||
|
||||
source->dinfo.raw_data_out = TRUE;
|
||||
source->dinfo.do_fancy_upsampling = FALSE;
|
||||
|
||||
jpeg_start_decompress(&source->dinfo);
|
||||
|
||||
cinfo->in_color_space = source->dinfo.out_color_space;
|
||||
cinfo->input_components = source->dinfo.output_components;
|
||||
cinfo->data_precision = source->dinfo.data_precision;
|
||||
cinfo->image_width = source->dinfo.image_width;
|
||||
cinfo->image_height = source->dinfo.image_height;
|
||||
cinfo->raw_data_in = TRUE;
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
cinfo->do_fancy_upsampling = FALSE;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < cinfo->input_components; i++) {
|
||||
source->pub.plane_pointer[i] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) cinfo->image_width, (JDIMENSION) NUM_ROWS);
|
||||
}
|
||||
|
||||
source->pub.get_pixel_rows = get_rows;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up at the end of the file.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_input_jpeg (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
jpeg_source_ptr source = (jpeg_source_ptr) sinfo;
|
||||
|
||||
jpeg_finish_decompress(&source->dinfo);
|
||||
jpeg_destroy_decompress(&source->dinfo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The module selection routine for JPEG format input.
|
||||
*/
|
||||
|
||||
GLOBAL(cjpeg_source_ptr)
|
||||
jinit_read_jpeg (j_compress_ptr cinfo)
|
||||
{
|
||||
jpeg_source_ptr source;
|
||||
|
||||
/* Create module interface object */
|
||||
source = (jpeg_source_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(jpeg_source_struct));
|
||||
source->cinfo = cinfo; /* make back link for subroutines */
|
||||
/* Fill in method ptrs, except get_pixel_rows which start_input sets */
|
||||
source->pub.start_input = start_input_jpeg;
|
||||
source->pub.finish_input = finish_input_jpeg;
|
||||
|
||||
return (cjpeg_source_ptr) source;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ if(WITH_SIMD)
|
||||
endif()
|
||||
|
||||
add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdbmp.c ../rdgif.c ../rdppm.c
|
||||
../rdswitch.c ../rdtarga.c)
|
||||
../rdswitch.c ../rdtarga.c ../rdjpeg.c)
|
||||
set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS
|
||||
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED -DUSE_SETMODE")
|
||||
target_link_libraries(cjpeg jpeg)
|
||||
|
||||
Reference in New Issue
Block a user