fprintf(stdout,"decomposition_levels\n");
fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
fprintf(stdout," [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
+ fprintf(stdout,"Main_header_start_position\n");
fprintf(stdout,"Main_header_end_position\n");
fprintf(stdout,"Codestream_size\n");
- fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
- fprintf(stdout,"Tile_1 '' '' '' '' '' ''\n");
+ fprintf(stdout,"\n");
+ fprintf(stdout,"INFO ON TILES\n");
+ fprintf(stdout,"tileno start_pos end_hd end_tile nbparts disto nbpix disto/nbpix\n");
+ fprintf(stdout,"Tile_0 start_pos end_Theader end_pos NumParts TotalDisto NumPix MaxMSE\n");
+ fprintf(stdout,"Tile_1 '' '' '' '' '' '' ''\n");
+ fprintf(stdout,"...\n");
+ fprintf(stdout,"Tile_Nt '' '' '' '' '' '' ''\n");
+ fprintf(stdout,"...\n");
+ fprintf(stdout,"TILE 0 DETAILS\n");
+ fprintf(stdout,"part_nb tileno num_packs start_pos end_tph_pos end_pos\n");
fprintf(stdout,"...\n");
- fprintf(stdout,"Tile_Nt '' '' '' '' '' ''\n");
+ fprintf(stdout,"Progression_string\n");
+ fprintf(stdout,"pack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n");
fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
fprintf(stdout,"...\n");
fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n");
/** @name Local static variables */\r
/*@{*/\r
\r
-/** position of markers to insert */\r
-static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; \r
-/** number of prepared markers */\r
+/** number of JPWL prepared markers */\r
static int jwmarker_num;\r
+/** properties of JPWL markers to insert */\r
+static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; \r
\r
/*@}*/\r
\r
\r
/*-----------------------------------------------------------------*/\r
\r
+void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
+\r
+ int mm;\r
+\r
+ /* let's reset some settings */\r
+\r
+ /* clear the existing markers */\r
+ for (mm = 0; mm < jwmarker_num; mm++) {\r
+\r
+ switch (jwmarker[mm].id) {\r
+\r
+ case J2K_MS_EPB:\r
+ free(jwmarker[mm].epbmark);\r
+ break;\r
+\r
+ case J2K_MS_EPC:\r
+ free(jwmarker[mm].epcmark);\r
+ break;\r
+\r
+ case J2K_MS_ESD:\r
+ free(jwmarker[mm].esdmark);\r
+ break;\r
+\r
+ case J2K_MS_RED:\r
+ free(jwmarker[mm].redmark);\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* clear the marker structure array */\r
+ memset(jwmarker, 0, sizeof(jpwl_marker_t) * JPWL_MAX_NO_MARKERS);\r
+\r
+ /* no more markers in the list */\r
+ jwmarker_num = 0;\r
+\r
+ /* let's begin creating a marker list, according to user wishes */\r
+ jpwl_prepare_marks(j2k, cio, image);\r
+\r
+ /* now we dump the JPWL markers on the codestream */\r
+ jpwl_dump_marks(j2k, cio, image);\r
+\r
+ /* do not know exactly what is this for,\r
+ but it gets called during index creation */\r
+ j2k->pos_correction = 0;\r
+\r
+}\r
+\r
+\r
void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
\r
unsigned short int socsiz_len = 0;\r
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
- jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready, yet */\r
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
- jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready */\r
/* Order JPWL markers according to their wishlist position */\r
qsort((void *) jwmarker, (size_t) jwmarker_num, sizeof (jpwl_marker_t), jpwl_markcomp);\r
\r
- /* compute markers total size */\r
+ /* compute markers total size */ \r
for (mm = 0; mm < jwmarker_num; mm++) {\r
/*printf("%x, %d, %.10f, %d long\n", jwmarker[mm].id, jwmarker[mm].pos,\r
jwmarker[mm].dpos, jwmarker[mm].len);*/\r
new_size += jwmarker[mm].len + 2;\r
}\r
\r
- /* allocate a temporary buffer of proper size */\r
+ /* allocate a new buffer of proper size */\r
if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) new_size * sizeof (unsigned char)))) {\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n");\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL codestream buffer\n");\r
exit(1);\r
};\r
\r
/* copy the jp2 part, if any */\r
- memcpy(jpwl_buf, cio->buffer, soc_pos);\r
-\r
orig_buf = jpwl_buf;\r
+ memcpy(jpwl_buf, cio->buffer, soc_pos);\r
+ jpwl_buf += soc_pos;\r
\r
/* cycle through markers */\r
orig_pos = soc_pos + 0; /* start from the beginning */\r
}\r
\r
/* finish remaining original codestream */\r
- memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos);\r
- jpwl_buf += soc_pos + old_size - orig_pos;\r
+ memcpy(jpwl_buf, cio_getbp(cio), old_size - (orig_pos - soc_pos));\r
+ jpwl_buf += old_size - (orig_pos - soc_pos);\r
cio_seek(cio, soc_pos + old_size);\r
\r
/*\r
opj_free(cio->buffer);\r
/*cio->cinfo;*/ /* no change */\r
/*cio->openmode;*/ /* no change */\r
- cio->buffer = jpwl_buf - new_size - soc_pos;\r
+ /*cio->buffer = jpwl_buf - new_size - soc_pos;*/\r
+ cio->buffer = orig_buf;\r
cio->length = new_size + soc_pos;\r
cio->start = jpwl_buf - new_size - soc_pos;\r
cio->end = jpwl_buf - 1;\r
bool data_ready;
} 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
*/
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
@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