Handle different JPEG colour component.

Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
yzrh 2022-12-25 01:26:05 +00:00
parent 9c1f1d0b75
commit 288b65a1fd
5 changed files with 37 additions and 24 deletions

View file

@ -3,6 +3,11 @@
* Support JPEG 2000 for HN. * Support JPEG 2000 for HN.
0.2.1 (2022-12-XX)
==================
* Handle different JPEG colour component.
0.2.0 (2022-12-22) 0.2.0 (2022-12-22)
================== ==================

View file

@ -492,7 +492,7 @@ cnki_pdf_hn(cnki_t **param)
int *dim = malloc(2 * ptr->image_length * sizeof(int)); int *dim = malloc(2 * ptr->image_length * sizeof(int));
int ret; int ret;
int wh[2]; int info[3];
if (dim == NULL) { if (dim == NULL) {
free(root_kid); free(root_kid);
@ -524,8 +524,8 @@ cnki_pdf_hn(cnki_t **param)
case JBIG: case JBIG:
ret = cnki_jbig(&bitmap, ret = cnki_jbig(&bitmap,
&bitmap_size, &bitmap_size,
&wh[0], &info[0],
&wh[1], &info[1],
ptr->image_data[i].image, ptr->image_data[i].image,
ptr->image_data[i].size); ptr->image_data[i].size);
@ -547,7 +547,7 @@ cnki_pdf_hn(cnki_t **param)
free(bitmap); free(bitmap);
snprintf(buf, 64, "/Width %d\n/Height %d\n", snprintf(buf, 64, "/Width %d\n/Height %d\n",
wh[0], wh[1]); info[0], info[1]);
strcat(dictionary, buf); strcat(dictionary, buf);
strcat(dictionary, "/ColorSpace /DeviceGray\n" strcat(dictionary, "/ColorSpace /DeviceGray\n"
@ -560,13 +560,14 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /FlateDecode\n"); strcat(dictionary, "/Filter /FlateDecode\n");
dim[i * 2] = wh[0]; dim[i * 2] = info[0];
dim[i * 2 + 1] = wh[1]; dim[i * 2 + 1] = info[1];
break; break;
case DCT_0: case DCT_0:
case DCT_1: case DCT_1:
ret = strinfo_jpeg_dim(&wh[0], ret = strinfo_jpeg_dim(&info[0],
&wh[1], &info[1],
&info[2],
ptr->image_data[i].image, ptr->image_data[i].image,
ptr->image_data[i].size); ptr->image_data[i].size);
@ -588,11 +589,17 @@ cnki_pdf_hn(cnki_t **param)
memcpy(stream, ptr->image_data[i].image, stream_size); memcpy(stream, ptr->image_data[i].image, stream_size);
snprintf(buf, 64, "/Width %d\n/Height %d\n", snprintf(buf, 64, "/Width %d\n/Height %d\n",
wh[0], wh[1]); info[0], info[1]);
strcat(dictionary, buf); strcat(dictionary, buf);
strcat(dictionary, "/ColorSpace /DeviceGray\n" if (info[2] == 1)
"/BitsPerComponent 8\n"); strcat(dictionary, "/ColorSpace /DeviceGray\n");
else if (info[2] == 3)
strcat(dictionary, "/ColorSpace /DeviceRGB\n");
else
strcat(dictionary, "/ColorSpace /DeviceCMYK\n");
strcat(dictionary, "/BitsPerComponent 8\n");
snprintf(buf, 64, "/Length %d\n", snprintf(buf, 64, "/Length %d\n",
stream_size); stream_size);
@ -600,14 +607,14 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /DCTDecode\n"); strcat(dictionary, "/Filter /DCTDecode\n");
dim[i * 2] = wh[0]; dim[i * 2] = info[0];
dim[i * 2 + 1] = wh[1]; dim[i * 2 + 1] = info[1];
break; break;
case JBIG2: case JBIG2:
ret = cnki_jbig2(&bitmap, ret = cnki_jbig2(&bitmap,
&bitmap_size, &bitmap_size,
&wh[0], &info[0],
&wh[1], &info[1],
ptr->image_data[i].image, ptr->image_data[i].image,
ptr->image_data[i].size); ptr->image_data[i].size);
@ -629,7 +636,7 @@ cnki_pdf_hn(cnki_t **param)
free(bitmap); free(bitmap);
snprintf(buf, 64, "/Width %d\n/Height %d\n", snprintf(buf, 64, "/Width %d\n/Height %d\n",
wh[0], wh[1]); info[0], info[1]);
strcat(dictionary, buf); strcat(dictionary, buf);
strcat(dictionary, "/ColorSpace /DeviceGray\n" strcat(dictionary, "/ColorSpace /DeviceGray\n"
@ -642,8 +649,8 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /FlateDecode\n"); strcat(dictionary, "/Filter /FlateDecode\n");
dim[i * 2] = wh[0]; dim[i * 2] = info[0];
dim[i * 2 + 1] = wh[1]; dim[i * 2 + 1] = info[1];
break; break;
case JPX: case JPX:
default: default:
@ -658,7 +665,7 @@ cnki_pdf_hn(cnki_t **param)
if (ret == 0) { if (ret == 0) {
if ((*param)->stat > 2) if ((*param)->stat > 2)
printf("%6d byte(s), width %4d, height %4d.\n", printf("%6d byte(s), width %4d, height %4d.\n",
stream_size, wh[0], wh[1]); stream_size, info[0], info[1]);
pdf_obj_append(&pdf, ids[i], pdf_obj_append(&pdf, ids[i],
NULL, dictionary, stream, stream_size); NULL, dictionary, stream, stream_size);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020-2021, yzrh <yzrh@noema.org> * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -9,7 +9,7 @@
#include <jpeglib.h> #include <jpeglib.h>
int int
strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height, strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height, int *jpeg_components,
const char * restrict data, int data_size) const char * restrict data, int data_size)
{ {
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
@ -27,6 +27,7 @@ strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height,
*jpeg_width = cinfo.output_width; *jpeg_width = cinfo.output_width;
*jpeg_height = cinfo.output_height; *jpeg_height = cinfo.output_height;
*jpeg_components = cinfo.output_components;
jpeg_destroy((struct jpeg_common_struct *) &cinfo); jpeg_destroy((struct jpeg_common_struct *) &cinfo);

View file

@ -1,8 +1,8 @@
/* /*
* Copyright (c) 2020-2021, yzrh <yzrh@noema.org> * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
int strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height, int strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height, int *jpeg_components,
const char * restrict data, int data_size); const char * restrict data, int data_size);

View file

@ -6,5 +6,5 @@
#define VERSION "0" #define VERSION "0"
#define RELEASE "2" #define RELEASE "2"
#define PATCH "0" #define PATCH "1"
#define EXTRA "" #define EXTRA ""