From 288b65a1fd6bcb1908a31c0a3e18ce7b6bf53a89 Mon Sep 17 00:00:00 2001 From: yzrh Date: Sun, 25 Dec 2022 01:26:05 +0000 Subject: Handle different JPEG colour component. Signed-off-by: yzrh --- src/cnki_pdf.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/cnki_pdf.c') 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); -- cgit v1.2.3