summaryrefslogtreecommitdiff
path: root/jpwl
diff options
context:
space:
mode:
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>2007-09-11 15:21:12 +0000
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>2007-09-11 15:21:12 +0000
commit1e705438e469890cabc3c3d1fa0b91ed45b454ff (patch)
tree70f53371d334c0dccdc5770a3b68a5d6db9a3664 /jpwl
parentd70a0415b910cc5a3550fea1d777ded84d4cdfa0 (diff)
JPWL encoding is finalized correctly into the JP2 file format; added an additional structure in opj_codestream_info, to keep a record of the written markers
Diffstat (limited to 'jpwl')
-rw-r--r--jpwl/JPWL_image_to_j2k.dsp3
-rw-r--r--jpwl/jpwl.c78
-rw-r--r--jpwl/jpwl.h13
3 files changed, 80 insertions, 14 deletions
diff --git a/jpwl/JPWL_image_to_j2k.dsp b/jpwl/JPWL_image_to_j2k.dsp
index f7c4e35c..52d5e9aa 100644
--- a/jpwl/JPWL_image_to_j2k.dsp
+++ b/jpwl/JPWL_image_to_j2k.dsp
@@ -42,7 +42,8 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FR /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FR /FD /c
+# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x80c /d "NDEBUG"
# ADD RSC /l 0x80c /d "NDEBUG"
BSC32=bscmake.exe
diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c
index 7a307839..894e7d3f 100644
--- a/jpwl/jpwl.c
+++ b/jpwl/jpwl.c
@@ -39,10 +39,10 @@
/** @name Local static variables */
/*@{*/
-/** position of markers to insert */
-static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS];
-/** number of prepared markers */
+/** number of JPWL prepared markers */
static int jwmarker_num;
+/** properties of JPWL markers to insert */
+static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS];
/*@}*/
@@ -107,6 +107,57 @@ void jpwl_esd_write(jpwl_esd_ms_t *esdmark, unsigned char *buf);
/*-----------------------------------------------------------------*/
+void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
+
+ int mm;
+
+ /* let's reset some settings */
+
+ /* clear the existing markers */
+ for (mm = 0; mm < jwmarker_num; mm++) {
+
+ switch (jwmarker[mm].id) {
+
+ case J2K_MS_EPB:
+ free(jwmarker[mm].epbmark);
+ break;
+
+ case J2K_MS_EPC:
+ free(jwmarker[mm].epcmark);
+ break;
+
+ case J2K_MS_ESD:
+ free(jwmarker[mm].esdmark);
+ break;
+
+ case J2K_MS_RED:
+ free(jwmarker[mm].redmark);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /* clear the marker structure array */
+ memset(jwmarker, 0, sizeof(jpwl_marker_t) * JPWL_MAX_NO_MARKERS);
+
+ /* no more markers in the list */
+ jwmarker_num = 0;
+
+ /* let's begin creating a marker list, according to user wishes */
+ jpwl_prepare_marks(j2k, cio, image);
+
+ /* now we dump the JPWL markers on the codestream */
+ jpwl_dump_marks(j2k, cio, image);
+
+ /* do not know exactly what is this for,
+ but it gets called during index creation */
+ j2k->pos_correction = 0;
+
+}
+
+
void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
unsigned short int socsiz_len = 0;
@@ -282,7 +333,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */
- jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */
jwmarker[jwmarker_num].len_ready = true; /* ready, yet */
@@ -458,7 +509,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */
- jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */
jwmarker[jwmarker_num].len_ready = true; /* ready */
@@ -647,23 +698,23 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
/* Order JPWL markers according to their wishlist position */
qsort((void *) jwmarker, (size_t) jwmarker_num, sizeof (jpwl_marker_t), jpwl_markcomp);
- /* compute markers total size */
+ /* compute markers total size */
for (mm = 0; mm < jwmarker_num; mm++) {
/*printf("%x, %d, %.10f, %d long\n", jwmarker[mm].id, jwmarker[mm].pos,
jwmarker[mm].dpos, jwmarker[mm].len);*/
new_size += jwmarker[mm].len + 2;
}
- /* allocate a temporary buffer of proper size */
+ /* allocate a new buffer of proper size */
if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) new_size * sizeof (unsigned char)))) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n");
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL codestream buffer\n");
exit(1);
};
/* copy the jp2 part, if any */
- memcpy(jpwl_buf, cio->buffer, soc_pos);
-
orig_buf = jpwl_buf;
+ memcpy(jpwl_buf, cio->buffer, soc_pos);
+ jpwl_buf += soc_pos;
/* cycle through markers */
orig_pos = soc_pos + 0; /* start from the beginning */
@@ -713,8 +764,8 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
}
/* finish remaining original codestream */
- memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos);
- jpwl_buf += soc_pos + old_size - orig_pos;
+ memcpy(jpwl_buf, cio_getbp(cio), old_size - (orig_pos - soc_pos));
+ jpwl_buf += old_size - (orig_pos - soc_pos);
cio_seek(cio, soc_pos + old_size);
/*
@@ -814,7 +865,8 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
opj_free(cio->buffer);
/*cio->cinfo;*/ /* no change */
/*cio->openmode;*/ /* no change */
- cio->buffer = jpwl_buf - new_size - soc_pos;
+ /*cio->buffer = jpwl_buf - new_size - soc_pos;*/
+ cio->buffer = orig_buf;
cio->length = new_size + soc_pos;
cio->start = jpwl_buf - new_size - soc_pos;
cio->end = jpwl_buf - 1;
diff --git a/jpwl/jpwl.h b/jpwl/jpwl.h
index a18c1480..65edce77 100644
--- a/jpwl/jpwl.h
+++ b/jpwl/jpwl.h
@@ -206,6 +206,14 @@ typedef struct jpwl_marker {
} jpwl_marker_t;
/**
+Encode according to JPWL specs
+@param j2k J2K handle
+@param cio codestream handle
+@param image image handle
+*/
+void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image);
+
+/**
Prepare the list of JPWL markers, after the Part 1 codestream
has been finalized (index struct is full)
@param j2k J2K handle
@@ -227,6 +235,7 @@ Read the EPC marker (Error Protection Capability)
@param j2k J2K handle
*/
void j2k_read_epc(opj_j2k_t *j2k);
+
/**
Write the EPC marker (Error Protection Capability), BUT the DL field is always set to 0
(this simplifies the management of EPBs and it is openly stated in the standard
@@ -235,21 +244,25 @@ are not yet implemented
@param j2k J2K handle
*/
void j2k_write_epc(opj_j2k_t *j2k);
+
/**
Read the EPB marker (Error Protection Block)
@param j2k J2K handle
*/
void j2k_read_epb(opj_j2k_t *j2k);
+
/**
Write the EPB marker (Error Protection Block)
@param j2k J2K handle
*/
void j2k_write_epb(opj_j2k_t *j2k);
+
/**
Read the ESD marker (Error Sensitivity Descriptor)
@param j2k J2K handle
*/
void j2k_read_esd(opj_j2k_t *j2k);
+
/**
Read the RED marker (Residual Error Descriptor)
@param j2k J2K handle