summaryrefslogtreecommitdiff
path: root/jpwl
diff options
context:
space:
mode:
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>2007-11-05 13:05:07 +0000
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>2007-11-05 13:05:07 +0000
commit95d760a1735517347355ff875549d85ebbc72eb7 (patch)
treee1e1dfeca50f06b1161db44bd66ebd8780337f2e /jpwl
parent123a680669995d50f354dd0159c83e7803a70ef3 (diff)
Fixed a bug which prevented JPWL from working on multi-tiled images; added some more fields in the interface info structures (keep a list of markers, save start packet number for each tile)
Diffstat (limited to 'jpwl')
-rw-r--r--jpwl/LibOpenJPEG_JPWL.dsp4
-rwxr-xr-xjpwl/Makefile51
-rw-r--r--jpwl/jpwl.c62
-rw-r--r--jpwl/jpwl.h2
-rw-r--r--jpwl/jpwl_lib.c36
5 files changed, 103 insertions, 52 deletions
diff --git a/jpwl/LibOpenJPEG_JPWL.dsp b/jpwl/LibOpenJPEG_JPWL.dsp
index 73f4889e..e4167374 100644
--- a/jpwl/LibOpenJPEG_JPWL.dsp
+++ b/jpwl/LibOpenJPEG_JPWL.dsp
@@ -245,6 +245,10 @@ SOURCE=..\libopenjpeg\opj_includes.h
# End Source File
# Begin Source File
+SOURCE=..\libopenjpeg\opj_malloc.h
+# End Source File
+# Begin Source File
+
SOURCE=..\libopenjpeg\pi.h
# End Source File
# Begin Source File
diff --git a/jpwl/Makefile b/jpwl/Makefile
index 9dc17bff..4c4bb105 100755
--- a/jpwl/Makefile
+++ b/jpwl/Makefile
@@ -37,56 +37,47 @@ default: all
all: OpenJPEG_JPWL JPWL_image_to_j2k JPWL_j2k_to_image
dist: OpenJPEG_JPWL
- install -d dist
- install -m 644 $(STATICLIB) dist
- install -m 755 $(SHAREDLIB) dist
- ln -sf $(SHAREDLIB) dist/$(LIBNAME)
- install libopenjpeg/openjpeg.h dist
+ install -d dist
+ install -m 644 $(STATICLIB) dist
+ install -m 755 $(SHAREDLIB) dist
+ ln -sf $(SHAREDLIB) dist/$(LIBNAME)
+ install libopenjpeg/openjpeg.h dist
dos2unix:
- @$(DOS2UNIX) $(SRCS) $(INCLS)
+ @$(DOS2UNIX) $(SRCS) $(INCLS)
OpenJPEG_JPWL: $(STATICLIB) $(SHAREDLIB)
JPWL_codec: JPWL_j2k_to_image JPWL_image_to_j2k $(STATICLIB)
.c.o:
- $(CC) $(CFLAGS) -c $< -o $@
+ $(CC) $(CFLAGS) -c $< -o $@
$(STATICLIB): $(MODULES)
- $(AR) r $@ $(MODULES)
+ $(AR) r $@ $(MODULES)
$(SHAREDLIB): $(MODULES)
- $(CC) -s -shared -Wl,-soname,$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES)
+ $(CC) -s -shared -Wl,-soname,$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES)
JPWL_j2k_to_image: ../codec/j2k_to_image.c
- gcc $(CFLAGS) ../codec/convert.c ../codec/j2k_to_image.c -o JPWL_j2k_to_image -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff
+ gcc $(CFLAGS) ../codec/convert.c ../codec/j2k_to_image.c -o JPWL_j2k_to_image -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff
JPWL_image_to_j2k: ../codec/image_to_j2k.c
- gcc $(CFLAGS) ../codec/convert.c ../codec/image_to_j2k.c -o JPWL_image_to_j2k -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff
+ gcc $(CFLAGS) ../codec/convert.c ../codec/image_to_j2k.c -o JPWL_image_to_j2k -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff
install: OpenJPEG
- install -d '$(DESTDIR)$(INSTALL_LIBDIR)' '$(DESTDIR)$(INSTALL_INCLUDE)'
- install -m 644 -o root -g root $(STATICLIB) '$(DESTDIR)$(INSTALL_LIBDIR)'
- ranlib '$(DESTDIR)$(INSTALL_LIBDIR)/$(STATICLIB)'
- install -m 755 -o root -g root $(SHAREDLIB) '$(DESTDIR)$(INSTALL_LIBDIR)'
- ln -sf $(SHAREDLIB) '$(DESTDIR)$(INSTALL_LIBDIR)/$(LIBNAME)'
- install -m 644 -o root -g root libopenjpeg/openjpeg.h '$(DESTDIR)$(INSTALL_INCLUDE)'
- -ldconfig
+ install -d '$(DESTDIR)$(INSTALL_LIBDIR)' '$(DESTDIR)$(INSTALL_INCLUDE)'
+ install -m 644 -o root -g root $(STATICLIB) '$(DESTDIR)$(INSTALL_LIBDIR)'
+ ranlib '$(DESTDIR)$(INSTALL_LIBDIR)/$(STATICLIB)'
+ install -m 755 -o root -g root $(SHAREDLIB) '$(DESTDIR)$(INSTALL_LIBDIR)'
+ ln -sf $(SHAREDLIB) '$(DESTDIR)$(INSTALL_LIBDIR)/$(LIBNAME)'
+ install -m 644 -o root -g root libopenjpeg/openjpeg.h '$(DESTDIR)$(INSTALL_INCLUDE)'
+ -ldconfig
cleanlib:
- rm -rf core dist/ u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
+ rm -rf core dist/ u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
cleancodec:
- rm -f JPWL_j2k_to_image JPWL_image_to_j2k JPWL_j2k_to_image.o JPWL_image_to_j2k.o
+ rm -f JPWL_j2k_to_image JPWL_image_to_j2k JPWL_j2k_to_image.o JPWL_image_to_j2k.o
-clean: cleanlib cleancodec
-
-osx:
- make -f Makefile.osx
-
-osxinstall:
- make -f Makefile.osx install
-
-osxclean:
- make -f Makefile.osx clean
+clean: cleanlib cleancodec \ No newline at end of file
diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c
index 894e7d3f..5b424235 100644
--- a/jpwl/jpwl.c
+++ b/jpwl/jpwl.c
@@ -88,22 +88,25 @@ their relevant wishlist position
int jpwl_markcomp(const void *arg1, const void *arg2);
/** write an EPB MS to a buffer
+@param j2k J2K compressor handle
@param epbmark pointer to the EPB MS
@param buf pointer to the memory buffer
*/
-void jpwl_epb_write(jpwl_epb_ms_t *epbmark, unsigned char *buf);
+void jpwl_epb_write(opj_j2k_t *j2k, jpwl_epb_ms_t *epbmark, unsigned char *buf);
/** write an EPC MS to a buffer
+@param j2k J2K compressor handle
@param epcmark pointer to the EPC MS
@param buf pointer to the memory buffer
*/
-void jpwl_epc_write(jpwl_epc_ms_t *epcmark, unsigned char *buf);
+void jpwl_epc_write(opj_j2k_t *j2k, jpwl_epc_ms_t *epcmark, unsigned char *buf);
/** write an ESD MS to a buffer
+@param j2k J2K compressor handle
@param esdmark pointer to the ESD MS
@param buf pointer to the memory buffer
*/
-void jpwl_esd_write(jpwl_esd_ms_t *esdmark, unsigned char *buf);
+void jpwl_esd_write(opj_j2k_t *j2k, jpwl_esd_ms_t *esdmark, unsigned char *buf);
/*-----------------------------------------------------------------*/
@@ -157,6 +160,24 @@ void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
}
+void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
+
+ if (!cstr_info)
+ return;
+
+ /* expand the list? */
+ if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
+ cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F);
+ cstr_info->marker = opj_realloc(cstr_info->marker, cstr_info->maxmarknum);
+ }
+
+ /* add the marker */
+ cstr_info->marker[cstr_info->marknum].type = type;
+ cstr_info->marker[cstr_info->marknum].pos = pos;
+ cstr_info->marker[cstr_info->marknum].len = len;
+ cstr_info->marknum++;
+
+}
void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
@@ -170,7 +191,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
jpwl_epc_ms_t *epc_mark;
jpwl_esd_ms_t *esd_mark;
- /* find SOC + SIZ length */
+ /* find (SOC + SIZ) length */
/* I assume SIZ is always the first marker after SOC */
cio_seek(cio, soc_pos + 4);
socsiz_len = (unsigned short int) cio_read(cio, 2) + 4; /* add the 2 marks length itself */
@@ -544,7 +565,8 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
startpack = 0;
/* EPB MSs for UEP packet data protection in Tile Parts */
/****** for (packno = 0; packno < j2k->cstr_info->num; packno++) { */
- first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno - 1].tp_numpacks) : 0;
+ /*first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno - 1].tp_numpacks) : 0;*/
+ first_tp_pack = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pack;
last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks - 1;
for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks; packno++) {
@@ -706,7 +728,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
}
/* allocate a new buffer of proper size */
- if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) new_size * sizeof (unsigned char)))) {
+ if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) (new_size + soc_pos) * sizeof(unsigned char)))) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL codestream buffer\n");
exit(1);
};
@@ -736,15 +758,15 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
switch (jwmarker[mm].id) {
case J2K_MS_EPB:
- jpwl_epb_write(jwmarker[mm].epbmark, jpwl_buf);
+ jpwl_epb_write(j2k, jwmarker[mm].epbmark, jpwl_buf);
break;
case J2K_MS_EPC:
- jpwl_epc_write(jwmarker[mm].epcmark, jpwl_buf);
+ jpwl_epc_write(j2k, jwmarker[mm].epcmark, jpwl_buf);
break;
case J2K_MS_ESD:
- jpwl_esd_write(jwmarker[mm].esdmark, jpwl_buf);
+ jpwl_esd_write(j2k, jwmarker[mm].esdmark, jpwl_buf);
break;
case J2K_MS_RED:
@@ -755,6 +777,10 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
break;
};
+ /* we update the markers struct */
+ if (j2k->cstr_info)
+ j2k->cstr_info->marker[j2k->cstr_info->marknum - 1].pos = (jpwl_buf - orig_buf);
+
/* we set the marker dpos to the new position in the JPWL codestream */
jwmarker[mm].dpos = (double) (jpwl_buf - orig_buf);
@@ -863,14 +889,13 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
/* free original cio buffer and set it to the JPWL one */
opj_free(cio->buffer);
- /*cio->cinfo;*/ /* no change */
- /*cio->openmode;*/ /* no change */
- /*cio->buffer = jpwl_buf - new_size - soc_pos;*/
+ cio->cinfo = cio->cinfo; /* no change */
+ cio->openmode = cio->openmode; /* no change */
cio->buffer = orig_buf;
cio->length = new_size + soc_pos;
- cio->start = jpwl_buf - new_size - soc_pos;
- cio->end = jpwl_buf - 1;
- cio->bp = jpwl_buf - new_size - soc_pos;
+ cio->start = cio->buffer;
+ cio->end = cio->buffer + cio->length;
+ cio->bp = cio->buffer;
cio_seek(cio, soc_pos + new_size);
}
@@ -982,6 +1007,10 @@ void j2k_write_epc(opj_j2k_t *j2k) {
cio_write(cio, Pcrc, 2);
cio_seek(cio, Lepcp + Lepc);
+
+ /* marker struct update */
+ j2k_add_marker(j2k->cstr_info, J2K_MS_EPC, Lepcp - 2, Lepc + 2);
+
}
void j2k_read_epb(opj_j2k_t *j2k) {
@@ -1130,6 +1159,9 @@ void j2k_write_epb(opj_j2k_t *j2k) {
cio_write(cio, Lepb, 2); /* Lepb */
cio_seek(cio, Lepbp + Lepb);
+
+ /* marker struct update */
+ j2k_add_marker(j2k->cstr_info, J2K_MS_EPB, Lepbp - 2, Lepb + 2);
}
void j2k_read_esd(opj_j2k_t *j2k) {
diff --git a/jpwl/jpwl.h b/jpwl/jpwl.h
index 65edce77..a58f2882 100644
--- a/jpwl/jpwl.h
+++ b/jpwl/jpwl.h
@@ -334,6 +334,8 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esdmark, unsigned char *buf);
bool jpwl_epb_fill(opj_j2k_t *j2k, jpwl_epb_ms_t *epbmark, unsigned char *buf, unsigned char *post_buf);
+void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len);
+
/** corrects the data in the JPWL codestream
@param j2k J2K compressor handle
@return true if correction is performed correctly
diff --git a/jpwl/jpwl_lib.c b/jpwl/jpwl_lib.c
index 7839249c..5ee53603 100644
--- a/jpwl/jpwl_lib.c
+++ b/jpwl/jpwl_lib.c
@@ -295,7 +295,7 @@ jpwl_epb_ms_t *jpwl_epb_create(opj_j2k_t *j2k, bool latest, bool packed, int til
return epb;
}
-void jpwl_epb_write(jpwl_epb_ms_t *epb, unsigned char *buf) {
+void jpwl_epb_write(opj_j2k_t *j2k, jpwl_epb_ms_t *epb, unsigned char *buf) {
/* Marker */
*(buf++) = (unsigned char) (J2K_MS_EPB >> 8);
@@ -323,6 +323,10 @@ void jpwl_epb_write(jpwl_epb_ms_t *epb, unsigned char *buf) {
/* Data */
/*memcpy(buf, epb->data, (size_t) epb->Lepb - 11);*/
memset(buf, 0, (size_t) epb->Lepb - 11);
+
+ /* update markers struct */
+ j2k_add_marker(j2k->cstr_info, J2K_MS_EPB, -1, epb->Lepb + 2);
+
};
@@ -1145,7 +1149,7 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
return true;
}
-void jpwl_epc_write(jpwl_epc_ms_t *epc, unsigned char *buf) {
+void jpwl_epc_write(opj_j2k_t *j2k, jpwl_epc_ms_t *epc, unsigned char *buf) {
/* Marker */
*(buf++) = (unsigned char) (J2K_MS_EPC >> 8);
@@ -1171,6 +1175,10 @@ void jpwl_epc_write(jpwl_epc_ms_t *epc, unsigned char *buf) {
/* Data */
/*memcpy(buf, epc->data, (size_t) epc->Lepc - 9);*/
memset(buf, 0, (size_t) epc->Lepc - 9);
+
+ /* update markers struct */
+ j2k_add_marker(j2k->cstr_info, J2K_MS_EPC, -1, epc->Lepc + 2);
+
};
int jpwl_esds_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
@@ -1561,7 +1569,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
return true;
}
-void jpwl_esd_write(jpwl_esd_ms_t *esd, unsigned char *buf) {
+void jpwl_esd_write(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
/* Marker */
*(buf++) = (unsigned char) (J2K_MS_ESD >> 8);
@@ -1586,6 +1594,10 @@ void jpwl_esd_write(jpwl_esd_ms_t *esd, unsigned char *buf) {
else
memset(buf, 0xAA, (size_t) esd->Lesd - 5);
/*memcpy(buf, esd->data, (size_t) esd->Lesd - 5);*/
+
+ /* update markers struct */
+ j2k_add_marker(j2k->cstr_info, J2K_MS_ESD, -1, esd->Lesd + 2);
+
}
unsigned short int jpwl_double_to_pfp(double V, int bytes) {
@@ -1703,10 +1715,10 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
/* end_pos: increment with markers before the end of this tile */
/* code is disabled, since according to JPWL no markers can be beyond TPH */
- /*addlen = 0;
+ addlen = 0;
for (mm = 0; mm < jwmarker_num; mm++)
if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].end_pos)
- addlen += jwmarker[mm].len + 2;*/
+ addlen += jwmarker[mm].len + 2;
info->tile[tileno].end_pos += addlen;
/* navigate through all the tile parts */
@@ -1740,11 +1752,19 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
/* start_pos: increment with markers before the packet */
/* disabled for the same reason as before */
+ addlen = 0;
+ for (mm = 0; mm < jwmarker_num; mm++)
+ if (jwmarker[mm].pos <= (unsigned long int) info->tile[tileno].packet[packno].start_pos)
+ addlen += jwmarker[mm].len + 2;
+ info->tile[tileno].packet[packno].start_pos += addlen;
+
+ /* end_ph_pos: increment with markers before the packet */
+ /* disabled for the same reason as before */
/*addlen = 0;
for (mm = 0; mm < jwmarker_num; mm++)
- if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].packet[packno].start_pos)
+ if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].packet[packno].end_ph_pos)
addlen += jwmarker[mm].len + 2;*/
- info->tile[tileno].packet[packno].start_pos += addlen;
+ info->tile[tileno].packet[packno].end_ph_pos += addlen;
/* end_pos: increment if marker is before the end of packet */
/* disabled for the same reason as before */
@@ -1757,6 +1777,8 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
}
}
+ /* reorder the markers list */
+
return true;
}