wok annotate mupdf/stuff/use_openjpeg_1.5.patch @ rev 18472
ghostscript, libv4l, slitaz-base-files: fix installation (thanks llev)
ghostscript: fix package upgrades;
libv4l: check multiple preloads in case of upgrade, not add preload if installation not finished/fails;
slitaz-base-files: not to overwrite real sudo.
ghostscript: fix package upgrades;
libv4l: check multiple preloads in case of upgrade, not add preload if installation not finished/fails;
slitaz-base-files: not to overwrite real sudo.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Oct 05 01:10:26 2015 +0300 (2015-10-05) |
parents | |
children |
rev | line source |
---|---|
pascal@16622 | 1 commit a7341e98ef48d6041028b7294d1acc13665b04ba |
pascal@16622 | 2 Author: Quoc-Viet Nguyen <afelion@gmail.com> |
pascal@16622 | 3 Date: Fri Apr 18 23:48:29 2014 +1000 |
pascal@16622 | 4 |
pascal@16622 | 5 Use openjpeg 1.5 rather than 2.0 |
pascal@16622 | 6 --- |
pascal@16622 | 7 source/fitz/load-jpx.c | 104 +++++++++---------------------------------------- |
pascal@16622 | 8 1 file changed, 18 insertions(+), 86 deletions(-) |
pascal@16622 | 9 |
pascal@16622 | 10 diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c |
pascal@16622 | 11 index dfb89f4..d27b5de 100644 |
pascal@16622 | 12 --- a/source/fitz/load-jpx.c |
pascal@16622 | 13 +++ b/source/fitz/load-jpx.c |
pascal@16622 | 14 @@ -27,119 +27,51 @@ static void fz_opj_info_callback(const char *msg, void *client_data) |
pascal@16622 | 15 /* fz_warn("openjpeg info: %s", msg); */ |
pascal@16622 | 16 } |
pascal@16622 | 17 |
pascal@16622 | 18 -typedef struct stream_block_s |
pascal@16622 | 19 -{ |
pascal@16622 | 20 - unsigned char *data; |
pascal@16622 | 21 - int size; |
pascal@16622 | 22 - int pos; |
pascal@16622 | 23 -} stream_block; |
pascal@16622 | 24 - |
pascal@16622 | 25 -static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) |
pascal@16622 | 26 -{ |
pascal@16622 | 27 - stream_block *sb = (stream_block *)p_user_data; |
pascal@16622 | 28 - int len; |
pascal@16622 | 29 - |
pascal@16622 | 30 - len = sb->size - sb->pos; |
pascal@16622 | 31 - if (len < 0) |
pascal@16622 | 32 - len = 0; |
pascal@16622 | 33 - if (len == 0) |
pascal@16622 | 34 - return (OPJ_SIZE_T)-1; /* End of file! */ |
pascal@16622 | 35 - if ((OPJ_SIZE_T)len > p_nb_bytes) |
pascal@16622 | 36 - len = p_nb_bytes; |
pascal@16622 | 37 - memcpy(p_buffer, sb->data + sb->pos, len); |
pascal@16622 | 38 - sb->pos += len; |
pascal@16622 | 39 - return len; |
pascal@16622 | 40 -} |
pascal@16622 | 41 - |
pascal@16622 | 42 -static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data) |
pascal@16622 | 43 -{ |
pascal@16622 | 44 - stream_block *sb = (stream_block *)p_user_data; |
pascal@16622 | 45 - |
pascal@16622 | 46 - if (skip > sb->size - sb->pos) |
pascal@16622 | 47 - skip = sb->size - sb->pos; |
pascal@16622 | 48 - sb->pos += skip; |
pascal@16622 | 49 - return sb->pos; |
pascal@16622 | 50 -} |
pascal@16622 | 51 - |
pascal@16622 | 52 -static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data) |
pascal@16622 | 53 -{ |
pascal@16622 | 54 - stream_block *sb = (stream_block *)p_user_data; |
pascal@16622 | 55 - |
pascal@16622 | 56 - if (seek_pos > sb->size) |
pascal@16622 | 57 - return OPJ_FALSE; |
pascal@16622 | 58 - sb->pos = seek_pos; |
pascal@16622 | 59 - return OPJ_TRUE; |
pascal@16622 | 60 -} |
pascal@16622 | 61 - |
pascal@16622 | 62 fz_pixmap * |
pascal@16622 | 63 fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed) |
pascal@16622 | 64 { |
pascal@16622 | 65 fz_pixmap *img; |
pascal@16622 | 66 fz_colorspace *origcs; |
pascal@16622 | 67 + opj_event_mgr_t evtmgr; |
pascal@16622 | 68 opj_dparameters_t params; |
pascal@16622 | 69 - opj_codec_t *codec; |
pascal@16622 | 70 + opj_dinfo_t *codec; |
pascal@16622 | 71 opj_image_t *jpx; |
pascal@16622 | 72 - opj_stream_t *stream; |
pascal@16622 | 73 + opj_cio_t *stream; |
pascal@16622 | 74 fz_colorspace *colorspace; |
pascal@16622 | 75 unsigned char *p; |
pascal@16622 | 76 OPJ_CODEC_FORMAT format; |
pascal@16622 | 77 int a, n, w, h, depth, sgnd; |
pascal@16622 | 78 int x, y, k, v; |
pascal@16622 | 79 - stream_block sb; |
pascal@16622 | 80 |
pascal@16622 | 81 if (size < 2) |
pascal@16622 | 82 fz_throw(ctx, FZ_ERROR_GENERIC, "not enough data to determine image format"); |
pascal@16622 | 83 |
pascal@16622 | 84 /* Check for SOC marker -- if found we have a bare J2K stream */ |
pascal@16622 | 85 if (data[0] == 0xFF && data[1] == 0x4F) |
pascal@16622 | 86 - format = OPJ_CODEC_J2K; |
pascal@16622 | 87 + format = CODEC_J2K; |
pascal@16622 | 88 else |
pascal@16622 | 89 - format = OPJ_CODEC_JP2; |
pascal@16622 | 90 + format = CODEC_JP2; |
pascal@16622 | 91 + |
pascal@16622 | 92 + memset(&evtmgr, 0, sizeof(evtmgr)); |
pascal@16622 | 93 + evtmgr.error_handler = fz_opj_error_callback; |
pascal@16622 | 94 + evtmgr.warning_handler = fz_opj_warning_callback; |
pascal@16622 | 95 + evtmgr.info_handler = fz_opj_info_callback; |
pascal@16622 | 96 |
pascal@16622 | 97 opj_set_default_decoder_parameters(¶ms); |
pascal@16622 | 98 if (indexed) |
pascal@16622 | 99 params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; |
pascal@16622 | 100 |
pascal@16622 | 101 codec = opj_create_decompress(format); |
pascal@16622 | 102 - opj_set_info_handler(codec, fz_opj_info_callback, ctx); |
pascal@16622 | 103 - opj_set_warning_handler(codec, fz_opj_warning_callback, ctx); |
pascal@16622 | 104 - opj_set_error_handler(codec, fz_opj_error_callback, ctx); |
pascal@16622 | 105 - if (!opj_setup_decoder(codec, ¶ms)) |
pascal@16622 | 106 - { |
pascal@16622 | 107 - fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed"); |
pascal@16622 | 108 - } |
pascal@16622 | 109 - |
pascal@16622 | 110 - stream = opj_stream_default_create(OPJ_TRUE); |
pascal@16622 | 111 - sb.data = data; |
pascal@16622 | 112 - sb.pos = 0; |
pascal@16622 | 113 - sb.size = size; |
pascal@16622 | 114 + opj_set_event_mgr((opj_common_ptr)codec, &evtmgr, ctx); |
pascal@16622 | 115 + opj_setup_decoder(codec, ¶ms); |
pascal@16622 | 116 |
pascal@16622 | 117 - opj_stream_set_read_function(stream, fz_opj_stream_read); |
pascal@16622 | 118 - opj_stream_set_skip_function(stream, fz_opj_stream_skip); |
pascal@16622 | 119 - opj_stream_set_seek_function(stream, fz_opj_stream_seek); |
pascal@16622 | 120 - opj_stream_set_user_data(stream, &sb); |
pascal@16622 | 121 - /* Set the length to avoid an assert */ |
pascal@16622 | 122 - opj_stream_set_user_data_length(stream, size); |
pascal@16622 | 123 + stream = opj_cio_open((opj_common_ptr)codec, data, size); |
pascal@16622 | 124 |
pascal@16622 | 125 - if (!opj_read_header(stream, codec, &jpx)) |
pascal@16622 | 126 - { |
pascal@16622 | 127 - opj_stream_destroy(stream); |
pascal@16622 | 128 - opj_destroy_codec(codec); |
pascal@16622 | 129 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header"); |
pascal@16622 | 130 - } |
pascal@16622 | 131 - |
pascal@16622 | 132 - if (!opj_decode(codec, stream, jpx)) |
pascal@16622 | 133 - { |
pascal@16622 | 134 - opj_stream_destroy(stream); |
pascal@16622 | 135 - opj_destroy_codec(codec); |
pascal@16622 | 136 - opj_image_destroy(jpx); |
pascal@16622 | 137 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image"); |
pascal@16622 | 138 - } |
pascal@16622 | 139 + jpx = opj_decode(codec, stream); |
pascal@16622 | 140 |
pascal@16622 | 141 - opj_stream_destroy(stream); |
pascal@16622 | 142 - opj_destroy_codec(codec); |
pascal@16622 | 143 + opj_cio_close(stream); |
pascal@16622 | 144 + opj_destroy_decompress(codec); |
pascal@16622 | 145 |
pascal@16622 | 146 - /* jpx should never be NULL here, but check anyway */ |
pascal@16622 | 147 if (!jpx) |
pascal@16622 | 148 fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed"); |
pascal@16622 | 149 |
pascal@16622 | 150 @@ -173,8 +105,8 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs |
pascal@16622 | 151 depth = jpx->comps[0].prec; |
pascal@16622 | 152 sgnd = jpx->comps[0].sgnd; |
pascal@16622 | 153 |
pascal@16622 | 154 - if (jpx->color_space == OPJ_CLRSPC_SRGB && n == 4) { n = 3; a = 1; } |
pascal@16622 | 155 - else if (jpx->color_space == OPJ_CLRSPC_SYCC && n == 4) { n = 3; a = 1; } |
pascal@16622 | 156 + if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; } |
pascal@16622 | 157 + else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; } |
pascal@16622 | 158 else if (n == 2) { n = 1; a = 1; } |
pascal@16622 | 159 else if (n > 4) { n = 4; a = 1; } |
pascal@16622 | 160 else { a = 0; } |