aboutsummaryrefslogtreecommitdiffstats
path: root/src/zlib.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2020-12-31 22:36:28 +0000
committeryzrh <yzrh@noema.org>2021-01-03 03:01:28 +0000
commit1994f122cc29504862944cca1da1c5203c7e41eb (patch)
treed89e37c5f3443156116bd8476e0efc2d380acd55 /src/zlib.c
parentb20c6ad3ed930977990f3812b25b80d2ce282d79 (diff)
downloadmelon-1994f122cc29504862944cca1da1c5203c7e41eb.tar.gz
melon-1994f122cc29504862944cca1da1c5203c7e41eb.tar.zst
Decode JBIG and JPEG during HN conversion.
Diffstat (limited to 'src/zlib.c')
-rw-r--r--src/zlib.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/zlib.c b/src/zlib.c
index 49004b7..76f049e 100644
--- a/src/zlib.c
+++ b/src/zlib.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, yzrh <yzrh@noema.org>
+ * Copyright (c) 2020-2021, yzrh <yzrh@noema.org>
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -20,12 +20,34 @@ strinflate(char **dst, int dst_size,
unsigned long size = dst_size;
- uncompress((Bytef *) *dst, &size, (const Bytef *) src, src_size);
+ if (uncompress((Bytef *) *dst,
+ &size, (const Bytef *) src, src_size) != Z_OK) {
+ free(*dst);
+ return 1;
+ }
+
+ return 0;
+}
- if (size != dst_size) {
+int
+strdeflate(char **dst, int *dst_size,
+ const char * restrict src, int src_size)
+{
+ *dst_size = compressBound(src_size);
+ *dst = malloc(*dst_size);
+
+ if (*dst == NULL)
+ return 1;
+
+ unsigned long size = *dst_size;
+
+ if (compress((Bytef *) *dst, &size,
+ (const Bytef *) src, src_size) != Z_OK) {
free(*dst);
return 1;
}
+ *dst_size = size;
+
return 0;
}