* Fixed some memory leaks in the decoder (some are still present when multiple tiles!)
* POSSIBILITY OF SUCH DAMAGE.
*/
+//MEMORY LEAK
+#ifdef _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h> // Must be included first
+#include <crtdbg.h>
+#endif
+//MEM
+
#include <openjpeg.h>
#include <stdio.h>
#include <stdlib.h>
free(cp.tcps[tileno].tccps);
free(cp.tcps);
+
+ //MEMORY LEAK
+ #ifdef _DEBUG
+ _CrtDumpMemoryLeaks();
+ #endif
+ //MEM
+
return 0;
}
* POSSIBILITY OF SUCH DAMAGE.
*/
+//MEMORY LEAK
+#ifdef _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h> // Must be included first
+#include <crtdbg.h>
+#endif
+//MEM
+
#include <openjpeg.h>
int main(int argc, char **argv)
{
- FILE *f;
- char *src, *src_name;
- char *dest, S1, S2, S3;
+ FILE *f=NULL;
+ char *src=NULL, *src_name=NULL;
+ char *dest=NULL, S1, S2, S3;
int len;
j2k_image_t img;
int w, wr, wrr, h, hr, hrr, max;
int i, image_type = -1, compno, pad, j;
int adjust;
- jp2_struct_t *jp2_struct;
+ jp2_struct_t *jp2_struct=NULL;
if (argc < 3) {
fprintf(stderr,
break;
}
+ j2k_dec_release();
+
+ //MEMORY LEAK
+ #ifdef _DEBUG
+ _CrtDumpMemoryLeaks();
+ #endif
+ //MEM
+
return 0;
}
cio_init(src, len);
for (;;) {
+
j2k_dec_mstabent_t *e;
int id = cio_read(2);
if (id >> 8 != 0xff) {
if (e->handler) {
(*e->handler) ();
}
+
if (j2k_state == J2K_STATE_NEOC)
break; /* RAJOUTE */
}
return 0;
}
+void j2k_dec_release()
+{
+ int i=0;
+
+ //tcd_dec_release();
+
+ if (j2k_tile_len!=NULL) free(j2k_tile_len);
+ if (j2k_tile_data!=NULL) free(j2k_tile_data);
+ if (j2k_default_tcp.ppt_data!=NULL) free(j2k_default_tcp.ppt_data);
+ if (j2k_default_tcp.tccps!=NULL) free(j2k_default_tcp.tccps);
+ for (i=0;i<j2k_cp->tw*j2k_cp->th;i++) {
+ if (j2k_cp->tcps[i].ppt_data!=NULL) free(j2k_cp->tcps[i].ppt_data);
+ if (j2k_cp->tcps[i].tccps!=NULL) free(j2k_cp->tcps[i].tccps);
+ }
+ if (j2k_cp->ppm_data!=NULL) free(j2k_cp->ppm_data);
+ if (j2k_cp->tcps!=NULL) free(j2k_cp->tcps);
+ if (j2k_img->comps!=NULL) free(j2k_img->comps);
+ if (j2k_cp->tileno!=NULL) free(j2k_cp->tileno);
+}
+
#ifdef WIN32
#include <windows.h>
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp);
+void j2k_dec_release();//antonin
+
#endif
fprintf(stderr, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
+
for (compno = 0; compno < tile->numcomps; compno++) {
free(tcd_image.tiles[tileno].comps[compno].data);
}
return l;
}
+
+void tcd_dec_release()
+{
+ int tileno,compno,resno,bandno,precno;
+ for (tileno=0;tileno<tcd_image.tw*tcd_image.th;tileno++) {
+ tcd_tile_t tile=tcd_image.tiles[tileno];
+ for (compno=0;compno<tile.numcomps;compno++) {
+ tcd_tilecomp_t tilec=tile.comps[compno];
+ for (resno=0;resno<tilec.numresolutions;resno++) {
+ tcd_resolution_t res=tilec.resolutions[resno];
+ for (bandno=0;bandno<res.numbands;bandno++) {
+ tcd_band_t band=res.bands[bandno];
+ for (precno=0;precno<res.ph*res.pw;precno++) {
+ tcd_precinct_t prec=band.precincts[precno];
+ if (prec.cblks!=NULL) free(prec.cblks);
+ if (prec.imsbtree!=NULL) free(prec.imsbtree);
+ if (prec.incltree!=NULL) free(prec.incltree);
+ }
+ if (band.precincts!=NULL) free(band.precincts);
+ }
+ }
+ if (tilec.resolutions!=NULL) free(tilec.resolutions);
+ }
+ if (tile.comps!=NULL) free(tile.comps);
+ }
+ if (tcd_image.tiles!=NULL) free(tcd_image.tiles);
+}
*/
int tcd_decode_tile(unsigned char *src, int len, int tileno);
+void tcd_dec_release();
+
#endif