Use Libbsc for TIFF images.

Workaround for packJPG limitation.
This commit is contained in:
Moinak Ghosh 2013-12-02 21:50:19 +05:30
parent 5a49252bb9
commit 958bdf7edc
2 changed files with 26 additions and 3 deletions

View file

@ -270,7 +270,7 @@ adapt_compress(void *src, uint64_t srclen, void *dst,
lz4_count++; lz4_count++;
} else if (adat->adapt_mode == 2 && PC_TYPE(btype) == TYPE_BINARY && } else if (adat->adapt_mode == 2 && PC_TYPE(btype) == TYPE_BINARY &&
PC_SUBTYPE(btype) != TYPE_BMP) { PC_SUBTYPE(btype) != TYPE_BMP && PC_SUBTYPE(btype) != TYPE_TIFF) {
rv = lzma_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->lzma_data); rv = lzma_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->lzma_data);
if (rv < 0) if (rv < 0)
return (rv); return (rv);
@ -278,7 +278,7 @@ adapt_compress(void *src, uint64_t srclen, void *dst,
lzma_count++; lzma_count++;
} else if (adat->adapt_mode == 1 && PC_TYPE(btype) == TYPE_BINARY && } else if (adat->adapt_mode == 1 && PC_TYPE(btype) == TYPE_BINARY &&
PC_SUBTYPE(btype) != TYPE_BMP) { PC_SUBTYPE(btype) != TYPE_BMP && PC_SUBTYPE(btype) != TYPE_TIFF) {
rv = bzip2_compress(src, srclen, dst, dstlen, level, chdr, btype, NULL); rv = bzip2_compress(src, srclen, dst, dstlen, level, chdr, btype, NULL);
if (rv < 0) if (rv < 0)
return (rv); return (rv);
@ -288,7 +288,8 @@ adapt_compress(void *src, uint64_t srclen, void *dst,
} else { } else {
#ifdef ENABLE_PC_LIBBSC #ifdef ENABLE_PC_LIBBSC
if (adat->bsc_data && (PC_SUBTYPE(btype) == TYPE_MARKUP || if (adat->bsc_data && (PC_SUBTYPE(btype) == TYPE_MARKUP ||
PC_SUBTYPE(btype) == TYPE_BMP || PC_SUBTYPE(btype) == TYPE_DNA_SEQ)) { PC_SUBTYPE(btype) == TYPE_BMP || PC_SUBTYPE(btype) == TYPE_DNA_SEQ ||
PC_SUBTYPE(btype) == TYPE_TIFF)) {
rv = libbsc_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->bsc_data); rv = libbsc_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->bsc_data);
if (rv < 0) if (rv < 0)
return (rv); return (rv);

View file

@ -31,6 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <utils.h>
#include <packjpglib.h> #include <packjpglib.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -62,11 +63,32 @@ typedef unsigned char uchar_t;
vice versa for output streams! */ vice versa for output streams! */
#define POLAROID_LE 0x64696f72616c6f50
size_t size_t
packjpg_filter_process(uchar_t *in_buf, size_t len, uchar_t **out_buf) packjpg_filter_process(uchar_t *in_buf, size_t len, uchar_t **out_buf)
{ {
unsigned int len1; unsigned int len1;
uchar_t *pos;
/*
* Workaround for packJPG limitation, not a bug per se. Images created with
* Polaroid cameras appear to have some weird huffman data in the middle which
* appears not to be interpreted by any image viewer/editor. This data gets
* stripped by packJPG.
* So the restored images will be visually correct, but, will be smaller than the
* original. So we need to look at the Exif Manufacturer tag for 'Polaroid' and
* skip those images. This should be within the first 512 bytes of the
* file (really...?) so we do a simple buffer scan without trying to parse Exif
* data.
*/
pos = (uchar_t *)memchr(in_buf, 'P', 512);
while (pos) {
if (LE64(U64_P(pos)) == POLAROID_LE)
return (0);
pos++;
pos = (uchar_t *)memchr(pos, 'P', 512);
}
pjglib_init_streams(in_buf, 1, len, *out_buf, 1); pjglib_init_streams(in_buf, 1, len, *out_buf, 1);
len1 = len; len1 = len;
if (!pjglib_convert_stream2mem(out_buf, &len1, NULL)) if (!pjglib_convert_stream2mem(out_buf, &len1, NULL))