From 0ddef9b2dbd7d61233350ccc7477fa46b2438385 Mon Sep 17 00:00:00 2001 From: Francois-Olivier Devaux Date: Fri, 26 Nov 2004 16:33:18 +0000 Subject: Modifications to increase modularity of jp2 coding/decoding --- codec/image_to_j2k.c | 38 +++++++++++++++++++++++++------------- codec/j2k_to_image.c | 24 +++++++++++++++++++++++- 2 files changed, 48 insertions(+), 14 deletions(-) (limited to 'codec') diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 922182bd..2a24f456 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -318,7 +318,8 @@ int main(int argc, char **argv) int ir = 0; int res_spec = 0; /* For various precinct sizes specification */ char sep; - char *outbuf; + char *j2k_codestream; + char *jp2_codestream; FILE *f; @@ -848,10 +849,11 @@ int main(int argc, char **argv) return 1; } } else { - outbuf = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2); /* Allocate memory for all tiles */ - cio_init(outbuf, cp.tdx * cp.tdy * cp.tw * cp.th * 2); + j2k_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2); + /* Allocate memory for all tiles */ + cio_init(j2k_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2); len = - j2k_encode(&img, &cp, outbuf, + j2k_encode(&img, &cp, j2k_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2, index); if (len == 0) { fprintf(stderr, "failed to encode image\n"); @@ -862,8 +864,8 @@ int main(int argc, char **argv) fprintf(stderr, "failed to open %s for writing\n", outfile); return 1; } - fwrite(outbuf, 1, len, f); - free(outbuf); + fwrite(j2k_codestream, 1, len, f); + free(j2k_codestream); fclose(f); } } else { /* JP2 format output */ @@ -873,30 +875,40 @@ int main(int argc, char **argv) jp2_struct->image = &img; /* Initialising the standard JP2 box content */ - /* If you wish to modify those boxes, you have to modify the jp2_struct content */ + /* If you wish to modify those boxes, you have to modify + the jp2_struct content */ if (jp2_init_stdjp2(jp2_struct, &img)) { fprintf(stderr, "Error with jp2 initialization"); return 1; }; if (cp.intermed_file == 1) { - /*For the moment, JP2 format does not use intermediary files for each tile */ + /*For the moment, JP2 format does not use intermediary + files for each tile */ cp.intermed_file = 0; } - outbuf = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2); - cio_init(outbuf, cp.tdx * cp.tdy * cp.tw * cp.th * 2); - len = jp2_encode(jp2_struct, &cp, outbuf, index); + j2k_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2); + jp2_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2); + + cio_init(j2k_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2); + len = j2k_encode(&img, &cp, j2k_codestream, + cp.tdx * cp.tdy * cp.tw * cp.th * 2, index); if (len == 0) { fprintf(stderr, "failed to encode image\n"); return 1; } + jp2_struct->j2k_codestream_len = len; + + cio_init(jp2_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2); + len = jp2_wrap_j2k(jp2_struct, j2k_codestream, jp2_codestream); f = fopen(outfile, "wb"); if (!f) { fprintf(stderr, "failed to open %s for writing\n", outfile); return 1; } - fwrite(outbuf, 1, len, f); - free(outbuf); + fwrite(jp2_codestream, 1, len, f); + free(jp2_codestream); + free(j2k_codestream); fclose(f); } diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c index f1534d53..ea4e52d0 100644 --- a/codec/j2k_to_image.c +++ b/codec/j2k_to_image.c @@ -25,12 +25,20 @@ * POSSIBILITY OF SUCH DAMAGE. */ + + //MEMORY LEAK + #ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include // Must be included first + #include + #endif + //MEM @@ -147,6 +155,7 @@ int main(int argc, char **argv) src_name--; S1 = *src_name; + /* J2K format */ if ((S1 == 'j' && S2 == '2' && S3 == 'k') || (S1 == 'J' && S2 == '2' && S3 == 'K') || (S1 == 'j' && S2 == '2' @@ -165,7 +174,12 @@ int main(int argc, char **argv) jp2_struct->image = &img; - if (jp2_decode(src, len, jp2_struct, &cp)) { + if (jp2_read_struct(src, jp2_struct, len)) { + fprintf(stderr, "j2k_to_image: failed to decode jp2 structure!\n"); + return 1; + } + + if (!j2k_decode(src + jp2_struct->j2k_codestream_offset, jp2_struct->j2k_codestream_len, &img, &cp)) { fprintf(stderr, "j2k_to_image: failed to decode image!\n"); return 1; } @@ -561,12 +575,20 @@ int main(int argc, char **argv) break; } + + j2k_dec_release(); + + //MEMORY LEAK + #ifdef _DEBUG + _CrtDumpMemoryLeaks(); + #endif + //MEM return 0; -- cgit v1.2.3