aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-25 01:26:05 +0000
committeryzrh <yzrh@noema.org>2022-12-25 01:26:05 +0000
commit288b65a1fd6bcb1908a31c0a3e18ce7b6bf53a89 (patch)
tree03dc0909583f0ee8f9c60e0e629dfe67008995ae /src
parent9c1f1d0b75de0d2ed299842d3025941f3e681c16 (diff)
downloadmelon-288b65a1fd6bcb1908a31c0a3e18ce7b6bf53a89.tar.gz
melon-288b65a1fd6bcb1908a31c0a3e18ce7b6bf53a89.tar.zst
Handle different JPEG colour component.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r--src/cnki_pdf.c45
-rw-r--r--src/jpeg.c5
-rw-r--r--src/jpeg.h4
-rw-r--r--src/version.h2
4 files changed, 32 insertions, 24 deletions
diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c
index b59b7c6..c56a45f 100644
--- a/src/cnki_pdf.c
+++ b/src/cnki_pdf.c
@@ -492,7 +492,7 @@ cnki_pdf_hn(cnki_t **param)
int *dim = malloc(2 * ptr->image_length * sizeof(int));
int ret;
- int wh[2];
+ int info[3];
if (dim == NULL) {
free(root_kid);
@@ -524,8 +524,8 @@ cnki_pdf_hn(cnki_t **param)
case JBIG:
ret = cnki_jbig(&bitmap,
&bitmap_size,
- &wh[0],
- &wh[1],
+ &info[0],
+ &info[1],
ptr->image_data[i].image,
ptr->image_data[i].size);
@@ -547,7 +547,7 @@ cnki_pdf_hn(cnki_t **param)
free(bitmap);
snprintf(buf, 64, "/Width %d\n/Height %d\n",
- wh[0], wh[1]);
+ info[0], info[1]);
strcat(dictionary, buf);
strcat(dictionary, "/ColorSpace /DeviceGray\n"
@@ -560,13 +560,14 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /FlateDecode\n");
- dim[i * 2] = wh[0];
- dim[i * 2 + 1] = wh[1];
+ dim[i * 2] = info[0];
+ dim[i * 2 + 1] = info[1];
break;
case DCT_0:
case DCT_1:
- ret = strinfo_jpeg_dim(&wh[0],
- &wh[1],
+ ret = strinfo_jpeg_dim(&info[0],
+ &info[1],
+ &info[2],
ptr->image_data[i].image,
ptr->image_data[i].size);
@@ -588,11 +589,17 @@ cnki_pdf_hn(cnki_t **param)
memcpy(stream, ptr->image_data[i].image, stream_size);
snprintf(buf, 64, "/Width %d\n/Height %d\n",
- wh[0], wh[1]);
+ info[0], info[1]);
strcat(dictionary, buf);
- strcat(dictionary, "/ColorSpace /DeviceGray\n"
- "/BitsPerComponent 8\n");
+ if (info[2] == 1)
+ 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",
stream_size);
@@ -600,14 +607,14 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /DCTDecode\n");
- dim[i * 2] = wh[0];
- dim[i * 2 + 1] = wh[1];
+ dim[i * 2] = info[0];
+ dim[i * 2 + 1] = info[1];
break;
case JBIG2:
ret = cnki_jbig2(&bitmap,
&bitmap_size,
- &wh[0],
- &wh[1],
+ &info[0],
+ &info[1],
ptr->image_data[i].image,
ptr->image_data[i].size);
@@ -629,7 +636,7 @@ cnki_pdf_hn(cnki_t **param)
free(bitmap);
snprintf(buf, 64, "/Width %d\n/Height %d\n",
- wh[0], wh[1]);
+ info[0], info[1]);
strcat(dictionary, buf);
strcat(dictionary, "/ColorSpace /DeviceGray\n"
@@ -642,8 +649,8 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/Filter /FlateDecode\n");
- dim[i * 2] = wh[0];
- dim[i * 2 + 1] = wh[1];
+ dim[i * 2] = info[0];
+ dim[i * 2 + 1] = info[1];
break;
case JPX:
default:
@@ -658,7 +665,7 @@ cnki_pdf_hn(cnki_t **param)
if (ret == 0) {
if ((*param)->stat > 2)
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],
NULL, dictionary, stream, stream_size);
diff --git a/src/jpeg.c b/src/jpeg.c
index 4ea4d7f..cdcae7b 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -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
*/
@@ -9,7 +9,7 @@
#include <jpeglib.h>
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)
{
struct jpeg_decompress_struct cinfo;
@@ -27,6 +27,7 @@ strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height,
*jpeg_width = cinfo.output_width;
*jpeg_height = cinfo.output_height;
+ *jpeg_components = cinfo.output_components;
jpeg_destroy((struct jpeg_common_struct *) &cinfo);
diff --git a/src/jpeg.h b/src/jpeg.h
index db35d94..1f5caa7 100644
--- a/src/jpeg.h
+++ b/src/jpeg.h
@@ -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
*/
-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);
diff --git a/src/version.h b/src/version.h
index 4e5cfa6..7c1ca3b 100644
--- a/src/version.h
+++ b/src/version.h
@@ -6,5 +6,5 @@
#define VERSION "0"
#define RELEASE "2"
-#define PATCH "0"
+#define PATCH "1"
#define EXTRA ""