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)

This commit is contained in:
Giuseppe Baruffa 2007-11-05 13:05:07 +00:00
parent 123a680669
commit 95d760a173
19 changed files with 1695 additions and 1098 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed
+ : added
November 5, 2007
*+ [GB] 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)
October 23, 2007
* [GB] Improved success for the linux build; OPJViewer shows all the COM contents

View File

@ -13,18 +13,18 @@ MODULES = $(OPJV_SRCS:.cpp=.o)
all: opjviewer lib
.cpp.o:
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -c $< -o $@
lib:
cd ../jpwl; make
cd ../jpwl; make
opjviewer: $(OPJV_SRCS) lib
$(CC) $(CFLAGS) -I .. $(OPJV_SRCS) -o OPJViewer -L ../jpwl -lopenjpeg_JPWL -lm -lstdc++ -ltiff $(shell wx-config-2.8 --libs)
clean:
rm -f OPJViewer *.o *.a
cd ../libopenjpeg; rm -f *.o
rm -f OPJViewer *.o *.a
cd ../libopenjpeg; rm -f *.o

View File

@ -111,6 +111,10 @@ SOURCE=.\source\imagmj2.cpp
# End Source File
# Begin Source File
SOURCE=.\source\OPJDialogs.cpp
# End Source File
# Begin Source File
SOURCE=.\source\OPJViewer.cpp
# End Source File
# Begin Source File

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -206,8 +206,11 @@ class OPJViewerApp: public wxApp
// encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
wxString m_cbsize, m_prsize, m_tsize, m_torigin;
bool m_enablecomm, m_enableidx, m_irreversible, m_enablesop, m_enableeph;
int m_resolutions;
bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop, m_enableeph;
bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm;
bool m_enablesegmark;
bool m_enablequality;
int m_resolutions, m_progression;
// some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker;
@ -404,6 +407,15 @@ class OPJFrame: public wxMDIParentFrame
void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event);
@ -475,6 +487,15 @@ enum {
OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO,
@ -638,14 +659,19 @@ public:
void OnEnableJPWL(wxCommandEvent& event);
void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/
#endif // USE_JPWL
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_irrevCheck, *m_sopCheck, *m_ephCheck;
wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck;
wxSpinCtrl *m_resolutionsCtrl;
@ -654,7 +680,9 @@ protected:
enum {
OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE,
@ -674,6 +702,7 @@ protected:
OPJENCO_ROISHIFT,
OPJENCO_IMORIG,
OPJENCO_TILORIG,
OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME,

View File

@ -1 +1 @@
wxT("242")
wxT("292")

View File

@ -231,6 +231,11 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
}
#define CINEMA_24_CS 1302083 /* Codestream length for 24fps */
#define CINEMA_48_CS 651041 /* Codestream length for 48fps */
#define COMP_24_CS 1041666 /* Maximum size per color component for 2K & 4K @ 24fps */
#define COMP_48_CS 520833 /* Maximum size per color component for 2K @ 48fps */
// save the j2k codestream
bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbose )
{
@ -267,7 +272,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
}
/* compression rates */
if (m_rates != wxT("")) {
if ((m_rates != wxT("")) && (!m_enablequality)) {
const char *s1 = m_rates.ToAscii();
wxLogMessage(wxT("rates %s"), s1);
while (sscanf(s1, "%f", &(parameters.tcp_rates[parameters.tcp_numlayers])) == 1) {
@ -284,7 +289,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
}
/* image quality, dB */
if (m_rates == wxT("")) {
if ((m_quality != wxT("")) && (m_enablequality)) {
const char *s2 = m_quality.ToAscii();
wxLogMessage(wxT("qualities %s"), s2);
while (sscanf(s2, "%f", &parameters.tcp_distoratio[parameters.tcp_numlayers]) == 1) {
@ -382,14 +387,103 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
if (m_enableeph)
parameters.csty |= 0x04;
/* multiple component transform */
if (m_multicomp)
parameters.tcp_mct = 1;
else
parameters.tcp_mct = 0;
/* mode switch */
parameters.mode = (m_enablebypass ? 1 : 0) + (m_enablereset ? 2 : 0)
+ (m_enablerestart ? 4 : 0) + (m_enablevsc ? 8 : 0)
+ (m_enableerterm ? 16 : 0) + (m_enablesegmark ? 32 : 0);
/* compression settings */
//parameters.tcp_numlayers = 1;
//parameters.tcp_rates[0] = 10.0;
//parameters.cp_disto_alloc = 1;
//parameters.irreversible = 1;
parameters.tcp_mct = 1;
/* progression order */
switch (m_progression) {
/* LRCP */
case 0:
parameters.prog_order = LRCP;
break;
/* RLCP */
case 1:
parameters.prog_order = RLCP;
break;
/* RPCL */
case 2:
parameters.prog_order = RPCL;
break;
/* PCRL */
case 3:
parameters.prog_order = PCRL;
break;
/* CPRL */
case 4:
parameters.prog_order = CPRL;
break;
/* DCI2K24 */
case 5:
parameters.cp_cinema = CINEMA2K_24;
parameters.cp_rsiz = CINEMA2K;
break;
/* DCI2K48 */
case 6:
parameters.cp_cinema = CINEMA2K_48;
parameters.cp_rsiz = CINEMA2K;
break;
/* DCI4K */
case 7:
parameters.cp_cinema = CINEMA4K_24;
parameters.cp_rsiz = CINEMA4K;
break;
default:
break;
}
/* check cinema */
if (parameters.cp_cinema) {
/* set up */
parameters.tile_size_on = false;
parameters.cp_tdx=1;
parameters.cp_tdy=1;
/*Tile part*/
parameters.tp_flag = 'C';
parameters.tp_on = 1;
/*Tile and Image shall be at (0,0)*/
parameters.cp_tx0 = 0;
parameters.cp_ty0 = 0;
parameters.image_offset_x0 = 0;
parameters.image_offset_y0 = 0;
/*Codeblock size= 32*32*/
parameters.cblockw_init = 32;
parameters.cblockh_init = 32;
parameters.csty |= 0x01;
/*The progression order shall be CPRL*/
parameters.prog_order = CPRL;
/* No ROI */
parameters.roi_compno = -1;
parameters.subsampling_dx = 1;
parameters.subsampling_dy = 1;
/* 9-7 transform */
parameters.irreversible = 1;
}
/* convert wx image into opj image */
cmptparm = (opj_image_cmptparm_t*) malloc(3 * sizeof(opj_image_cmptparm_t));
@ -429,6 +523,103 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
oimage->comps[2].data[i] = *(value++);
}
/* check cinema again */
if (parameters.cp_cinema) {
int i;
float temp_rate;
opj_poc_t *POC = NULL;
switch (parameters.cp_cinema) {
case CINEMA2K_24:
case CINEMA2K_48:
if (parameters.numresolution > 6) {
parameters.numresolution = 6;
}
if (!((oimage->comps[0].w == 2048) | (oimage->comps[0].h == 1080))) {
wxLogWarning(wxT("Image coordinates %d x %d is not 2K compliant. JPEG Digital Cinema Profile-3 "
"(2K profile) compliance requires that at least one of coordinates match 2048 x 1080"),
oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ;
}
break;
case CINEMA4K_24:
if (parameters.numresolution < 1) {
parameters.numresolution = 1;
} else if (parameters.numresolution > 7) {
parameters.numresolution = 7;
}
if (!((oimage->comps[0].w == 4096) | (oimage->comps[0].h == 2160))) {
wxLogWarning(wxT("Image coordinates %d x %d is not 4K compliant. JPEG Digital Cinema Profile-4"
"(4K profile) compliance requires that at least one of coordinates match 4096 x 2160"),
oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ;
}
parameters.POC[0].tile = 1;
parameters.POC[0].resno0 = 0;
parameters.POC[0].compno0 = 0;
parameters.POC[0].layno1 = 1;
parameters.POC[0].resno1 = parameters.numresolution - 1;
parameters.POC[0].compno1 = 3;
parameters.POC[0].prg1 = CPRL;
parameters.POC[1].tile = 1;
parameters.POC[1].resno0 = parameters.numresolution - 1;
parameters.POC[1].compno0 = 0;
parameters.POC[1].layno1 = 1;
parameters.POC[1].resno1 = parameters.numresolution;
parameters.POC[1].compno1 = 3;
parameters.POC[1].prg1 = CPRL;
parameters.numpocs = 2;
break;
}
switch (parameters.cp_cinema) {
case CINEMA2K_24:
case CINEMA4K_24:
for (i = 0 ; i < parameters.tcp_numlayers; i++) {
temp_rate = 0;
if (parameters.tcp_rates[i] == 0) {
parameters.tcp_rates[0] = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
temp_rate = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_24_CS ) {
parameters.tcp_rates[i]= ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else {
/* do nothing */
}
}
}
parameters.max_comp_size = COMP_24_CS;
break;
case CINEMA2K_48:
for (i = 0; i < parameters.tcp_numlayers; i++) {
temp_rate = 0 ;
if (parameters.tcp_rates[i] == 0) {
parameters.tcp_rates[0] = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
temp_rate =((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){
parameters.tcp_rates[0]= ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
/* do nothing */
}
}
}
parameters.max_comp_size = COMP_48_CS;
break;
}
parameters.cp_disto_alloc = 1;
}
/* get a J2K compressor handle */
opj_cinfo_t* cinfo = opj_create_compress(CODEC_J2K);
@ -480,7 +671,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
/* Write the index to disk */
if (*indexfilename) {
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
if (!bSuccess) {
wxLogError(wxT("Failed to output index file"));
}
}

View File

@ -82,8 +82,11 @@ public:
m_origin = wxT("0,0");
m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40");
m_enablequality = false;
m_multicomp = false;
m_irreversible = false;
m_resolutions = 6;
m_progression = 0;
m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT("");
@ -92,6 +95,12 @@ public:
m_resilience*/
m_enablesop = false;
m_enableeph = false;
m_enablereset = false;
m_enablesegmark = false;
m_enablevsc = false;
m_enablerestart = false;
m_enableerterm = false;
m_enablebypass = false;
/*m_roicompo
m_roiup
m_indexfname*/
@ -127,8 +136,11 @@ public:
wxString m_origin;
wxString m_rates;
wxString m_quality;
bool m_enablequality;
bool m_multicomp;
bool m_irreversible;
int m_resolutions;
int m_progression;
wxString m_cbsize;
wxString m_prsize;
wxString m_tsize;
@ -137,6 +149,12 @@ public:
m_resilience*/
bool m_enablesop;
bool m_enableeph;
bool m_enablebypass;
bool m_enableerterm;
bool m_enablerestart;
bool m_enablereset;
bool m_enablesegmark;
bool m_enablevsc;
/*m_roicompo
m_roiup
m_indexfname*/

View File

@ -639,10 +639,11 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
}
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno num_packs start_pos end_tph_pos end_pos\n");
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %11d %9d\n",
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
@ -824,6 +825,14 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
/* UniPG>> */
/* print the markers' list */
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index);

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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;
}

View File

@ -434,6 +434,15 @@ int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *
static void j2k_write_soc(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
cio_write(cio, J2K_MS_SOC, 2);
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
static void j2k_read_soc(opj_j2k_t *j2k) {
@ -1199,7 +1208,7 @@ static void j2k_read_ppm(opj_j2k_t *j2k) {
"JPWL: failed memory allocation during PPM marker parsing (pos. %x)\n",
cio_tell(cio));
if (!JPWL_ASSUME || JPWL_ASSUME) {
free(cp->ppm_data);
opj_free(cp->ppm_data);
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
return;
}
@ -1279,6 +1288,13 @@ static void j2k_write_sot(opj_j2k_t *j2k) {
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lsot */
cio_seek(cio, lenp + len);
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
static void j2k_read_sot(opj_j2k_t *j2k) {
@ -1436,6 +1452,12 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
if(cstr_info->tile[j2k->curtileno].packet[cstr_info->packno - 1].end_pos < cio_tell(cio))
cstr_info->tile[j2k->curtileno].packet[cstr_info->packno].start_pos = cio_tell(cio);
}
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_SOD, j2k->sod_start, 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
/* << INDEX */
@ -1557,6 +1579,13 @@ static void j2k_write_eoc(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
/* opj_event_msg(j2k->cinfo, "%.8x: EOC\n", cio_tell(cio) + j2k->pos_correction); */
cio_write(cio, J2K_MS_EOC, 2);
/* UniPG>> */
#ifdef USE_JPWL
/* update markers struct */
j2k_add_marker(j2k->cstr_info, J2K_MS_EOC, cio_tell(cio) - 2, 2);
#endif /* USE_JPWL */
/* <<UniPG */
}
static void j2k_read_eoc(opj_j2k_t *j2k) {
@ -2276,10 +2305,6 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
opj_tcd_t *tcd = NULL; /* TCD component */
/* UniPG>> */
int acc_pack_num = 0;
/* <<UniPG */
j2k->cio = cio;
j2k->image = image;
@ -2309,6 +2334,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
}
cstr_info->D_max = 0.0; /* ADD Marcela */
cstr_info->main_head_start = cio_tell(cio); /* position of SOC */
cstr_info->maxmarknum = 100;
cstr_info->marker = (opj_marker_info_t *) opj_malloc(cstr_info->maxmarknum * sizeof(opj_marker_info_t));
cstr_info->marknum = 0;
}
/* << INDEX */
@ -2359,6 +2387,10 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int pino;
int tilepartno=0;
/* UniPG>> */
int acc_pack_num = 0;
/* <<UniPG */
opj_tcp_t *tcp = &cp->tcps[tileno];
opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th);
@ -2418,6 +2450,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
if(cstr_info) {
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_pos =
cio_tell(cio) + j2k->pos_correction - 1;
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pack =
acc_pack_num;
cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_numpacks =
cstr_info->packno - acc_pack_num;
acc_pack_num = cstr_info->packno;

View File

@ -324,5 +324,6 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
opj_free(tile_info->tp);
}
opj_free(cstr_info->tile);
opj_free(cstr_info->marker);
}
}

View File

@ -606,6 +606,8 @@ typedef struct opj_tp_info {
int tp_end_header;
/** end position of tile part */
int tp_end_pos;
/** start packet of tile part */
int tp_start_pack;
/** number of packets of tile part */
int tp_numpacks;
} opj_tp_info_t;
@ -697,6 +699,8 @@ typedef struct opj_codestream_info {
int marknum;
/** list of markers */
opj_marker_info_t *marker;
/** actual size of markers array */
int maxmarknum;
/* <<UniPG */
/** main header position */
int main_head_start;

View File

@ -271,7 +271,7 @@ int main(int argc, char *argv[]) {
while(1)
{
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
sprintf(j2kfilename,"%05d.j2k",/*argv[1],*/snum + 7111);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { // Could not open a single codestream