Reformat src/bin/wx/OPJViewer/source/OPJThreads.cpp src/bin/wx/OPJViewer/source/imagjpeg2000.cpp wrapping/java/openjp2/JavaOpenJPEG.c

This commit is contained in:
Even Rouault 2017-07-26 21:04:01 +02:00
parent 94cc97c58a
commit 2be20ce7d9
3 changed files with 3660 additions and 3347 deletions

View File

@ -68,8 +68,7 @@ void OPJEncoThread::OnExit()
wxArrayThread& ethreads = wxGetApp().m_enco_threads; wxArrayThread& ethreads = wxGetApp().m_enco_threads;
ethreads.Remove(this); ethreads.Remove(this);
if (ethreads.IsEmpty() ) if (ethreads.IsEmpty()) {
{
// signal the main thread that there are no more threads left if it is // signal the main thread that there are no more threads left if it is
// waiting for us // waiting for us
if (wxGetApp().m_enco_waitingUntilAllDone) { if (wxGetApp().m_enco_waitingUntilAllDone) {
@ -91,7 +90,8 @@ void *OPJEncoThread::Entry()
WriteText(text); WriteText(text);
// set handler properties // set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000); wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_subsampling = wxGetApp().m_subsampling; jpeg2000handler->m_subsampling = wxGetApp().m_subsampling;
jpeg2000handler->m_origin = wxGetApp().m_origin; jpeg2000handler->m_origin = wxGetApp().m_origin;
jpeg2000handler->m_rates = wxGetApp().m_rates; jpeg2000handler->m_rates = wxGetApp().m_rates;
@ -114,19 +114,22 @@ void *OPJEncoThread::Entry()
jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm; jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm;
jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc; jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc;
jpeg2000handler->m_enableidx = wxGetApp().m_enableidx; jpeg2000handler->m_enableidx = wxGetApp().m_enableidx;
jpeg2000handler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index; jpeg2000handler->m_index = m_canvas->m_savename.GetPath(
wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;
jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm; jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm;
jpeg2000handler->m_comment = wxGetApp().m_comment; jpeg2000handler->m_comment = wxGetApp().m_comment;
jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc; jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc;
jpeg2000handler->m_poc = wxGetApp().m_poc; jpeg2000handler->m_poc = wxGetApp().m_poc;
// save the file // save the file
if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_JPEG2000)) { if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(),
(wxBitmapType) wxBITMAP_TYPE_JPEG2000)) {
WriteText(wxT("Can't save image")); WriteText(wxT("Can't save image"));
return NULL; return NULL;
} }
text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Enco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
return NULL; return NULL;
} }
@ -177,8 +180,7 @@ void OPJDecoThread::OnExit()
wxArrayThread& dthreads = wxGetApp().m_deco_threads; wxArrayThread& dthreads = wxGetApp().m_deco_threads;
dthreads.Remove(this); dthreads.Remove(this);
if (dthreads.IsEmpty() ) if (dthreads.IsEmpty()) {
{
// signal the main thread that there are no more threads left if it is // signal the main thread that there are no more threads left if it is
// waiting for us // waiting for us
if (wxGetApp().m_deco_waitingUntilAllDone) { if (wxGetApp().m_deco_waitingUntilAllDone) {
@ -211,7 +213,8 @@ void *OPJDecoThread::Entry()
WriteText(m_canvas->m_fname.GetFullPath()); WriteText(m_canvas->m_fname.GetFullPath());
// set handler properties // set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000); wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor; jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor;
jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers; jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jpeg2000handler->m_components = wxGetApp().m_components; jpeg2000handler->m_components = wxGetApp().m_components;
@ -223,7 +226,8 @@ void *OPJDecoThread::Entry()
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_MXF #ifdef USE_MXF
wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(wxBITMAP_TYPE_MXF); wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(
wxBITMAP_TYPE_MXF);
mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor; mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor;
mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers; mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
mxfffhandler->m_components = wxGetApp().m_components; mxfffhandler->m_components = wxGetApp().m_components;
@ -281,7 +285,8 @@ void *OPJDecoThread::Entry()
//m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0)); //m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0));
//text.Printf(wxT("Deco thread 0x%lx finished."), GetId()); //text.Printf(wxT("Deco thread 0x%lx finished."), GetId());
text.Printf(wxT("Deco thread %d finished"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Deco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
return NULL; return NULL;
@ -435,14 +440,16 @@ IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxGenericTreeCtrl)
IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl) IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl)
#endif #endif
OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe,
wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size, long style) const wxPoint& pos, const wxSize& size, long style)
: wxTreeCtrl(parent, id, pos, size, style) : wxTreeCtrl(parent, id, pos, size, style)
{ {
m_reverseSort = false; m_reverseSort = false;
m_fname = fname; m_fname = fname;
m_peektextCtrl = ((OPJFrame *) (parent->GetParent()->GetParent()))->m_textCtrlbrowse; m_peektextCtrl = ((OPJFrame *)(
parent->GetParent()->GetParent()))->m_textCtrlbrowse;
CreateImageList(); CreateImageList();
// Add some items to the tree // Add some items to the tree
@ -453,10 +460,11 @@ OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileNa
new OPJMarkerData(name)); new OPJMarkerData(name));
OPJParseThread *pthread = CreateParseThread(0x00, subframe); OPJParseThread *pthread = CreateParseThread(0x00, subframe);
if (pthread->Run() != wxTHREAD_NO_ERROR) if (pthread->Run() != wxTHREAD_NO_ERROR) {
wxLogMessage(wxT("Can't start parse thread!")); wxLogMessage(wxT("Can't start parse thread!"));
else } else {
wxLogMessage(wxT("New parse thread started.")); wxLogMessage(wxT("New parse thread started."));
}
m_childframe = subframe; m_childframe = subframe;
} }
@ -467,10 +475,11 @@ void OPJMarkerTree::CreateImageList(int size)
SetImageList(NULL); SetImageList(NULL);
return; return;
} }
if (size == 0) if (size == 0) {
size = m_imageSize; size = m_imageSize;
else } else {
m_imageSize = size; m_imageSize = size;
}
// Make an image list containing small icons // Make an image list containing small icons
wxImageList *images = new wxImageList(size, size, true); wxImageList *images = new wxImageList(size, size, true);
@ -594,11 +603,13 @@ void OPJParseThread::LoadFile(wxFileName fname)
} }
// this is the root node // this is the root node
if (this->m_parentid) if (this->m_parentid) {
m_tree->SetItemText(rootid, wxT("Codestream")); m_tree->SetItemText(rootid, wxT("Codestream"));
else } else
//m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length())); //m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length()));
{
m_tree->SetItemText(rootid, fname.GetFullName()); m_tree->SetItemText(rootid, fname.GetFullName());
}
// close the file // close the file
m_file.Close(); m_file.Close();
@ -738,19 +749,22 @@ void OPJMarkerTree::LogEvent(const wxChar *name, const wxTreeEvent& event)
{ {
wxTreeItemId item = event.GetItem(); wxTreeItemId item = event.GetItem();
wxString text; wxString text;
if ( item.IsOk() ) if (item.IsOk()) {
text << wxT('"') << GetItemText(item).c_str() << wxT('"'); text << wxT('"') << GetItemText(item).c_str() << wxT('"');
else } else {
text = wxT("invalid item"); text = wxT("invalid item");
}
wxLogMessage(wxT("%s(%s)"), name, text.c_str()); wxLogMessage(wxT("%s(%s)"), name, text.c_str());
} }
OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid, OPJChildFrame *subframe) OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid,
OPJChildFrame *subframe)
{ {
OPJParseThread *pthread = new OPJParseThread(this, parentid); OPJParseThread *pthread = new OPJParseThread(this, parentid);
if (pthread->Create() != wxTHREAD_NO_ERROR) if (pthread->Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("Can't create parse thread!")); wxLogError(wxT("Can't create parse thread!"));
}
wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect); wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect);
wxGetApp().m_parse_threads.Add(pthread); wxGetApp().m_parse_threads.Add(pthread);
@ -786,13 +800,15 @@ void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event)
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text; wxString text;
if (item.IsOk()) if (item.IsOk()) {
text << wxT('"') << GetItemText(item).c_str() << wxT('"'); text << wxT('"') << GetItemText(item).c_str() << wxT('"');
else } else {
text = wxT("invalid item"); text = wxT("invalid item");
}
if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) {
return; return;
}
wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"), wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(), text.c_str(), data->GetDesc1(), data->GetDesc2(),
@ -802,12 +818,13 @@ void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event)
wxTreeItemIdValue cookie; wxTreeItemIdValue cookie;
if (!GetFirstChild(item, cookie).IsOk()) { if (!GetFirstChild(item, cookie).IsOk()) {
OPJParseThread *pthread = CreateParseThread(item); OPJParseThread *pthread = CreateParseThread(item);
if (pthread->Run() != wxTHREAD_NO_ERROR) if (pthread->Run() != wxTHREAD_NO_ERROR) {
wxLogMessage(wxT("Can't start parse thread!")); wxLogMessage(wxT("Can't start parse thread!"));
else } else {
wxLogMessage(wxT("New parse thread started.")); wxLogMessage(wxT("New parse thread started."));
} }
} }
}
void OPJMarkerTree::OnSelChanged(wxTreeEvent& event) void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
{ {
@ -832,7 +849,8 @@ void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
fp->Seek(data->m_start, wxFromStart); fp->Seek(data->m_start, wxFromStart);
// read a bunch // read a bunch
int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines), data->m_length - data->m_start + 1); int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines),
data->m_length - data->m_start + 1);
if (data->m_desc == wxT("MARK (65380)")) { if (data->m_desc == wxT("MARK (65380)")) {
/*wxLogMessage(data->m_desc);*/ /*wxLogMessage(data->m_desc);*/
max_read = data->m_length - data->m_start + 1; max_read = data->m_length - data->m_start + 1;
@ -852,13 +870,15 @@ void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
// add hex browsing text // add hex browsing text
for (c = 0; c < bunch_linesize; c++) { for (c = 0; c < bunch_linesize; c++) {
if (!(c % 8)) if (!(c % 8)) {
text << wxT(" "); text << wxT(" ");
}
if (pos < max_read) { if (pos < max_read) {
text << wxString::Format(wxT("%02X "), buffer[pos]); text << wxString::Format(wxT("%02X "), buffer[pos]);
} else } else {
text << wxT(" "); text << wxT(" ");
}
pos++; pos++;
} }
@ -872,11 +892,13 @@ void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
(buffer[pre_pos] == '\t') || (buffer[pre_pos] == '\t') ||
(buffer[pre_pos] == '\0') || (buffer[pre_pos] == '\0') ||
(buffer[pre_pos] == 0x0D) || (buffer[pre_pos] == 0x0D) ||
(buffer[pre_pos] == 0x0B)) (buffer[pre_pos] == 0x0B)) {
buffer[pre_pos] = ' '; buffer[pre_pos] = ' ';
}
text << wxString::FromAscii((char) buffer[pre_pos]) << wxT("."); text << wxString::FromAscii((char) buffer[pre_pos]) << wxT(".");
} else } else {
text << wxT(" "); text << wxT(" ");
}
pre_pos++; pre_pos++;
} }
@ -1269,5 +1291,3 @@ void OPJMarkerData::ShowInfo(wxTreeCtrl *tree)
unsigned(tree->GetChildrenCount(GetId())), unsigned(tree->GetChildrenCount(GetId())),
unsigned(tree->GetChildrenCount(GetId(), false))); unsigned(tree->GetChildrenCount(GetId(), false)));
} }

View File

@ -92,8 +92,9 @@ int
jpeg2000familytype(unsigned char *hdr, int hdr_len) jpeg2000familytype(unsigned char *hdr, int hdr_len)
{ {
// check length // check length
if (hdr_len < 24) if (hdr_len < 24) {
return -1; return -1;
}
// check format // check format
if (hdr[0] == 0x00 && if (hdr[0] == 0x00 &&
@ -108,8 +109,9 @@ jpeg2000familytype(unsigned char *hdr, int hdr_len)
hdr[21] == 0x70 && hdr[21] == 0x70 &&
hdr[22] == 0x32) hdr[22] == 0x32)
// JP2 file format // JP2 file format
{
return JP2_CFMT; return JP2_CFMT;
else if (hdr[0] == 0x00 && } else if (hdr[0] == 0x00 &&
hdr[1] == 0x00 && hdr[1] == 0x00 &&
hdr[2] == 0x00 && hdr[2] == 0x00 &&
hdr[3] == 0x0C && hdr[3] == 0x0C &&
@ -122,14 +124,18 @@ jpeg2000familytype(unsigned char *hdr, int hdr_len)
hdr[22] == 0x70 && hdr[22] == 0x70 &&
hdr[23] == 0x32) hdr[23] == 0x32)
// MJ2 file format // MJ2 file format
{
return MJ2_CFMT; return MJ2_CFMT;
else if (hdr[0] == 0xFF && } else if (hdr[0] == 0xFF &&
hdr[1] == 0x4F) hdr[1] == 0x4F)
// J2K file format // J2K file format
{
return J2K_CFMT; return J2K_CFMT;
else } else
// unknown format // unknown format
{
return -1; return -1;
}
} }
@ -146,45 +152,54 @@ void printevent(const char *msg)
} }
/* sample error callback expecting a FILE* client object */ /* sample error callback expecting a FILE* client object */
void jpeg2000_error_callback(const char *msg, void *client_data) { void jpeg2000_error_callback(const char *msg, void *client_data)
{
char mess[MAX_MESSAGE_LEN + 20]; char mess[MAX_MESSAGE_LEN + 20];
int message_len = strlen(msg); int message_len = strlen(msg);
if (message_len > MAX_MESSAGE_LEN) if (message_len > MAX_MESSAGE_LEN) {
message_len = MAX_MESSAGE_LEN; message_len = MAX_MESSAGE_LEN;
}
if (msg[message_len - 1] == '\n') if (msg[message_len - 1] == '\n') {
message_len--; message_len--;
}
sprintf(mess, "[ERROR] %.*s", message_len, msg); sprintf(mess, "[ERROR] %.*s", message_len, msg);
printevent(mess); printevent(mess);
} }
/* sample warning callback expecting a FILE* client object */ /* sample warning callback expecting a FILE* client object */
void jpeg2000_warning_callback(const char *msg, void *client_data) { void jpeg2000_warning_callback(const char *msg, void *client_data)
{
char mess[MAX_MESSAGE_LEN + 20]; char mess[MAX_MESSAGE_LEN + 20];
int message_len = strlen(msg); int message_len = strlen(msg);
if (message_len > MAX_MESSAGE_LEN) if (message_len > MAX_MESSAGE_LEN) {
message_len = MAX_MESSAGE_LEN; message_len = MAX_MESSAGE_LEN;
}
if (msg[message_len - 1] == '\n') if (msg[message_len - 1] == '\n') {
message_len--; message_len--;
}
sprintf(mess, "[WARNING] %.*s", message_len, msg); sprintf(mess, "[WARNING] %.*s", message_len, msg);
printevent(mess); printevent(mess);
} }
/* sample debug callback expecting no client object */ /* sample debug callback expecting no client object */
void jpeg2000_info_callback(const char *msg, void *client_data) { void jpeg2000_info_callback(const char *msg, void *client_data)
{
char mess[MAX_MESSAGE_LEN + 20]; char mess[MAX_MESSAGE_LEN + 20];
int message_len = strlen(msg); int message_len = strlen(msg);
if (message_len > MAX_MESSAGE_LEN) if (message_len > MAX_MESSAGE_LEN) {
message_len = MAX_MESSAGE_LEN; message_len = MAX_MESSAGE_LEN;
}
if (msg[message_len - 1] == '\n') if (msg[message_len - 1] == '\n') {
message_len--; message_len--;
}
sprintf(mess, "[INFO] %.*s", message_len, msg); sprintf(mess, "[INFO] %.*s", message_len, msg);
printevent(mess); printevent(mess);
@ -300,180 +315,226 @@ struct jpeg2000boxdef {
}; };
/* the possible boxes */ /* the possible boxes */
struct jpeg2000boxdef jpeg2000box[] = struct jpeg2000boxdef jpeg2000box[] = {
{ /* sign */ {
/* sign */ {FILE_SIGN, FILE_SIGN,
/* short */ "placeholder for nothing", /* short */ "placeholder for nothing",
/* long */ "Nothing to say", /* long */ "Nothing to say",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {JP_SIGN, /* sign */ {
JP_SIGN,
/* short */ "JPEG 2000 Signature box", /* short */ "JPEG 2000 Signature box",
/* long */ "This box uniquely identifies the file as being part of the JPEG 2000 family of files", /* long */ "This box uniquely identifies the file as being part of the JPEG 2000 family of files",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {FTYP_SIGN, /* sign */ {
FTYP_SIGN,
/* short */ "File Type box", /* short */ "File Type box",
/* long */ "This box specifies file type, version and compatibility information, including specifying if this file " /* long */ "This box specifies file type, version and compatibility information, including specifying if this file "
"is a conforming JP2 file or if it can be read by a conforming JP2 reader", "is a conforming JP2 file or if it can be read by a conforming JP2 reader",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {JP2H_SIGN, /* sign */ {
JP2H_SIGN,
/* short */ "JP2 Header box", /* short */ "JP2 Header box",
/* long */ "This box contains a series of boxes that contain header-type information about the file", /* long */ "This box contains a series of boxes that contain header-type information about the file",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {IHDR_SIGN, /* sign */ {
IHDR_SIGN,
/* short */ "Image Header box", /* short */ "Image Header box",
/* long */ "This box specifies the size of the image and other related fields", /* long */ "This box specifies the size of the image and other related fields",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ JP2H_BOX}, /* ins */ JP2H_BOX
},
/* sign */ {COLR_SIGN, /* sign */ {
COLR_SIGN,
/* short */ "Colour Specification box", /* short */ "Colour Specification box",
/* long */ "This box specifies the colourspace of the image", /* long */ "This box specifies the colourspace of the image",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ JP2H_BOX}, /* ins */ JP2H_BOX
},
/* sign */ {JP2C_SIGN, /* sign */ {
JP2C_SIGN,
/* short */ "Contiguous Codestream box", /* short */ "Contiguous Codestream box",
/* long */ "This box contains the codestream as defined by Annex A", /* long */ "This box contains the codestream as defined by Annex A",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {JP2I_SIGN, /* sign */ {
JP2I_SIGN,
/* short */ "Intellectual Property box", /* short */ "Intellectual Property box",
/* long */ "This box contains intellectual property information about the image", /* long */ "This box contains intellectual property information about the image",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {XML_SIGN, /* sign */ {
XML_SIGN,
/* short */ "XML box", /* short */ "XML box",
/* long */ "This box provides a tool by which vendors can add XML formatted information to a JP2 file", /* long */ "This box provides a tool by which vendors can add XML formatted information to a JP2 file",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {UUID_SIGN, /* sign */ {
UUID_SIGN,
/* short */ "UUID box", /* short */ "UUID box",
/* long */ "This box provides a tool by which vendors can add additional information to a file " /* long */ "This box provides a tool by which vendors can add additional information to a file "
"without risking conflict with other vendors", "without risking conflict with other vendors",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {UINF_SIGN, /* sign */ {
UINF_SIGN,
/* short */ "UUID Info box", /* short */ "UUID Info box",
/* long */ "This box provides a tool by which a vendor may provide access to additional information associated with a UUID", /* long */ "This box provides a tool by which a vendor may provide access to additional information associated with a UUID",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {MOOV_SIGN, /* sign */ {
MOOV_SIGN,
/* short */ "Movie box", /* short */ "Movie box",
/* long */ "This box contains the media data. In video tracks, this box would contain JPEG2000 video frames", /* long */ "This box contains the media data. In video tracks, this box would contain JPEG2000 video frames",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {MVHD_SIGN, /* sign */ {
MVHD_SIGN,
/* short */ "Movie Header box", /* short */ "Movie Header box",
/* long */ "This box defines overall information which is media-independent, and relevant to the entire presentation " /* long */ "This box defines overall information which is media-independent, and relevant to the entire presentation "
"considered as a whole", "considered as a whole",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MOOV_BOX}, /* ins */ MOOV_BOX
},
/* sign */ {TRAK_SIGN, /* sign */ {
TRAK_SIGN,
/* short */ "Track box", /* short */ "Track box",
/* long */ "This is a container box for a single track of a presentation. A presentation may consist of one or more tracks", /* long */ "This is a container box for a single track of a presentation. A presentation may consist of one or more tracks",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MOOV_BOX}, /* ins */ MOOV_BOX
},
/* sign */ {TKHD_SIGN, /* sign */ {
TKHD_SIGN,
/* short */ "Track Header box", /* short */ "Track Header box",
/* long */ "This box specifies the characteristics of a single track. Exactly one Track Header Box is contained in a track", /* long */ "This box specifies the characteristics of a single track. Exactly one Track Header Box is contained in a track",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ TRAK_BOX}, /* ins */ TRAK_BOX
},
/* sign */ {MDIA_SIGN, /* sign */ {
MDIA_SIGN,
/* short */ "Media box", /* short */ "Media box",
/* long */ "The media declaration container contains all the objects which declare information about the media data " /* long */ "The media declaration container contains all the objects which declare information about the media data "
"within a track", "within a track",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ TRAK_BOX}, /* ins */ TRAK_BOX
},
/* sign */ {MINF_SIGN, /* sign */ {
MINF_SIGN,
/* short */ "Media Information box", /* short */ "Media Information box",
/* long */ "This box contains all the objects which declare characteristic information of the media in the track", /* long */ "This box contains all the objects which declare characteristic information of the media in the track",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MDIA_BOX}, /* ins */ MDIA_BOX
},
/* sign */ {STBL_SIGN, /* sign */ {
STBL_SIGN,
/* short */ "Sample Table box", /* short */ "Sample Table box",
/* long */ "The sample table contains all the time and data indexing of the media samples in a track", /* long */ "The sample table contains all the time and data indexing of the media samples in a track",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MINF_BOX}, /* ins */ MINF_BOX
},
/* sign */ {STSD_SIGN, /* sign */ {
STSD_SIGN,
/* short */ "Sample Description box", /* short */ "Sample Description box",
/* long */ "The sample description table gives detailed information about the coding type used, and any initialization " /* long */ "The sample description table gives detailed information about the coding type used, and any initialization "
"information needed for that coding", "information needed for that coding",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MINF_BOX}, /* ins */ MINF_BOX
},
/* sign */ {MJP2_SIGN, /* sign */ {
MJP2_SIGN,
/* short */ "MJP2 Sample Description box", /* short */ "MJP2 Sample Description box",
/* long */ "The MJP2 sample description table gives detailed information about the coding type used, and any initialization " /* long */ "The MJP2 sample description table gives detailed information about the coding type used, and any initialization "
"information needed for that coding", "information needed for that coding",
/* sbox */ 0, /* sbox */ 0,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ MINF_BOX}, /* ins */ MINF_BOX
},
/* sign */ {MDAT_SIGN, /* sign */ {
MDAT_SIGN,
/* short */ "Media Data box", /* short */ "Media Data box",
/* long */ "The meta-data for a presentation is stored in the single Movie Box which occurs at the top-level of a file", /* long */ "The meta-data for a presentation is stored in the single Movie Box which occurs at the top-level of a file",
/* sbox */ 1, /* sbox */ 1,
/* req */ {1, 1, 1}, /* req */ {1, 1, 1},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {ANY_SIGN, /* sign */ {
ANY_SIGN,
/* short */ "Any box", /* short */ "Any box",
/* long */ "All the existing boxes", /* long */ "All the existing boxes",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ FILE_BOX}, /* ins */ FILE_BOX
},
/* sign */ {UNK_SIGN, /* sign */ {
UNK_SIGN,
/* short */ "Unknown Type box", /* short */ "Unknown Type box",
/* long */ "The signature is not recognised to be that of an existing box", /* long */ "The signature is not recognised to be that of an existing box",
/* sbox */ 0, /* sbox */ 0,
/* req */ {0, 0, 0}, /* req */ {0, 0, 0},
/* ins */ ANY_BOX} /* ins */ ANY_BOX
}
}; };
/* declaration */ /* declaration */
int int
jpeg2000_box_handler_function(jpeg2000boxtype boxtype, wxInputStream& stream, unsigned long int filepoint, jpeg2000_box_handler_function(jpeg2000boxtype boxtype, wxInputStream& stream,
unsigned long int filepoint,
unsigned long int filelimit, int level, char *scansign, unsigned long int filelimit, int level, char *scansign,
unsigned long int *scanpoint); unsigned long int *scanpoint);
@ -487,7 +548,8 @@ typedef unsigned long long int8byte;
/* internal mini-search for a box signature */ /* internal mini-search for a box signature */
int int
jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint, unsigned long int filelimit, int level, jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint,
unsigned long int filelimit, int level,
char *scansign, unsigned long int *scanpoint) char *scansign, unsigned long int *scanpoint)
{ {
unsigned long int LBox = 0x00000000; unsigned long int LBox = 0x00000000;
@ -505,12 +567,14 @@ jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint, unsigned
while (!last_box) { while (!last_box) {
/* do not exceed file limit */ /* do not exceed file limit */
if (filepoint >= filelimit) if (filepoint >= filelimit) {
return (0); return (0);
}
/* seek on file */ /* seek on file */
if (stream.SeekI(filepoint, wxFromStart) == wxInvalidOffset) if (stream.SeekI(filepoint, wxFromStart) == wxInvalidOffset) {
return (-1); return (-1);
}
/* read the mandatory LBox, 4 bytes */ /* read the mandatory LBox, 4 bytes */
if (!stream.Read(fourbytes, 4)) { if (!stream.Read(fourbytes, 4)) {
@ -533,15 +597,17 @@ jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint, unsigned
memcpy(scansign, " ", 4); memcpy(scansign, " ", 4);
*scanpoint = filepoint; *scanpoint = filepoint;
return (0); return (0);
} else } else {
box_number++; box_number++;
}
}; };
/* determine the box type */ /* determine the box type */
for (box_type = JP_BOX; box_type < UNK_BOX; box_type++) for (box_type = JP_BOX; box_type < UNK_BOX; box_type++)
if (memcmp(TBox, jpeg2000box[box_type].value, 4) == 0) if (memcmp(TBox, jpeg2000box[box_type].value, 4) == 0) {
break; break;
}
/* read the optional XLBox, 8 bytes */ /* read the optional XLBox, 8 bytes */
if (LBox == 1) { if (LBox == 1) {
@ -560,7 +626,9 @@ jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint, unsigned
} else } else
{
box_length = LBox; box_length = LBox;
}
/* go deep in the box */ /* go deep in the box */
@ -570,7 +638,8 @@ jpeg2000_file_parse(wxInputStream& stream, unsigned long int filepoint, unsigned
/* if it's a superbox go inside it */ /* if it's a superbox go inside it */
if (jpeg2000box[box_type].sbox) if (jpeg2000box[box_type].sbox)
jpeg2000_file_parse(stream, (LBox == 1) ? (filepoint + 16) : (filepoint + 8), filepoint + box_length, jpeg2000_file_parse(stream, (LBox == 1) ? (filepoint + 16) : (filepoint + 8),
filepoint + box_length,
level, scansign, scanpoint); level, scansign, scanpoint);
/* increment box number and filepoint*/ /* increment box number and filepoint*/
@ -593,12 +662,14 @@ searchjpeg2000c(wxInputStream& stream, unsigned long int fsize, int number)
wxLogMessage(wxT("Searching jp2c box... ")); wxLogMessage(wxT("Searching jp2c box... "));
/* do the parsing */ /* do the parsing */
if (jpeg2000_file_parse(stream, 0, fsize, number, scansign, &scanpoint) < 0) if (jpeg2000_file_parse(stream, 0, fsize, number, scansign, &scanpoint) < 0) {
wxLogMessage(wxT("Unrecoverable error during JPEG 2000 box parsing: stopping")); wxLogMessage(
wxT("Unrecoverable error during JPEG 2000 box parsing: stopping"));
}
if (strcmp(scansign, " ")) if (strcmp(scansign, " ")) {
wxLogMessage(wxT("Box not found")); wxLogMessage(wxT("Box not found"));
else { } else {
wxLogMessage(wxString::Format(wxT("Box found at byte %d"), scanpoint)); wxLogMessage(wxString::Format(wxT("Box found at byte %d"), scanpoint));
@ -617,13 +688,16 @@ searchjpeg2000headerbox(wxInputStream& stream, unsigned long int fsize)
wxLogMessage(wxT("Searching jp2h box... ")); wxLogMessage(wxT("Searching jp2h box... "));
/* do the parsing */ /* do the parsing */
if (jpeg2000_file_parse(stream, 0, fsize, 0, scansign, &scanpoint) < 0) if (jpeg2000_file_parse(stream, 0, fsize, 0, scansign, &scanpoint) < 0) {
wxLogMessage(wxT("Unrecoverable error during JPEG 2000 box parsing: stopping")); wxLogMessage(
wxT("Unrecoverable error during JPEG 2000 box parsing: stopping"));
}
if (strcmp(scansign, " ")) if (strcmp(scansign, " ")) {
wxLogMessage(wxT("Box not found")); wxLogMessage(wxT("Box not found"));
else } else {
wxLogMessage(wxString::Format(wxT("Box found at byte %d"), scanpoint)); wxLogMessage(wxString::Format(wxT("Box found at byte %d"), scanpoint));
}
return (scanpoint); return (scanpoint);
} }
@ -633,7 +707,8 @@ searchjpeg2000headerbox(wxInputStream& stream, unsigned long int fsize)
/* Box handler function */ /* Box handler function */
int int
jpeg2000_box_handler_function(jpeg2000boxtype boxtype, wxInputStream& stream, unsigned long int filepoint, jpeg2000_box_handler_function(jpeg2000boxtype boxtype, wxInputStream& stream,
unsigned long int filepoint,
unsigned long int filelimit, int level, unsigned long int filelimit, int level,
char *scansign, unsigned long int *scanpoint) char *scansign, unsigned long int *scanpoint)
{ {
@ -641,12 +716,14 @@ jpeg2000_box_handler_function(jpeg2000boxtype boxtype, wxInputStream& stream, un
/* Sample Description box */ /* Sample Description box */
case (STSD_BOX): case (STSD_BOX):
jpeg2000_file_parse(stream, filepoint + 8, filelimit, level, scansign, scanpoint); jpeg2000_file_parse(stream, filepoint + 8, filelimit, level, scansign,
scanpoint);
break; break;
/* MJP2 Sample Description box */ /* MJP2 Sample Description box */
case (MJP2_BOX): case (MJP2_BOX):
jpeg2000_file_parse(stream, filepoint + 78, filelimit, level, scansign, scanpoint); jpeg2000_file_parse(stream, filepoint + 78, filelimit, level, scansign,
scanpoint);
break; break;
/* not yet implemented */ /* not yet implemented */
@ -671,7 +748,8 @@ unsigned char jpeg2000head[jpeg2000headSIZE] = {
///////////////////////////////////////////////// /////////////////////////////////////////////////
// load the jpeg2000 file format // load the jpeg2000 file format
bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index) bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream,
bool verbose, int index)
{ {
opj_dparameters_t parameters; /* decompression parameters */ opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -688,10 +766,12 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
image->Destroy(); image->Destroy();
/* read the beginning of the file to check the type */ /* read the beginning of the file to check the type */
if (!stream.Read(hdr, WXSIZEOF(hdr))) if (!stream.Read(hdr, WXSIZEOF(hdr))) {
return false; return false;
if ((jpfamform = jpeg2000familytype(hdr, WXSIZEOF(hdr))) < 0) }
if ((jpfamform = jpeg2000familytype(hdr, WXSIZEOF(hdr))) < 0) {
return false; return false;
}
stream.SeekI(0, wxFromStart); stream.SeekI(0, wxFromStart);
/* handle to a decompressor */ /* handle to a decompressor */
@ -712,10 +792,12 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
strncpy(parameters.outfile, "", sizeof(parameters.outfile) - 1); strncpy(parameters.outfile, "", sizeof(parameters.outfile) - 1);
parameters.decod_format = jpfamform; parameters.decod_format = jpfamform;
parameters.cod_format = BMP_DFMT; parameters.cod_format = BMP_DFMT;
if (m_reducefactor) if (m_reducefactor) {
parameters.cp_reduce = m_reducefactor; parameters.cp_reduce = m_reducefactor;
if (m_qualitylayers) }
if (m_qualitylayers) {
parameters.cp_layer = m_qualitylayers; parameters.cp_layer = m_qualitylayers;
}
/*if (n_components) /*if (n_components)
parameters. = n_components;*/ parameters. = n_components;*/
@ -727,12 +809,13 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* get a decoder handle */ /* get a decoder handle */
if (jpfamform == JP2_CFMT || jpfamform == MJ2_CFMT) if (jpfamform == JP2_CFMT || jpfamform == MJ2_CFMT) {
dinfo = opj_create_decompress(CODEC_JP2); dinfo = opj_create_decompress(CODEC_JP2);
else if (jpfamform == J2K_CFMT) } else if (jpfamform == J2K_CFMT) {
dinfo = opj_create_decompress(CODEC_J2K); dinfo = opj_create_decompress(CODEC_J2K);
else } else {
return false; return false;
}
/* find length of the stream */ /* find length of the stream */
stream.SeekI(0, wxFromEnd); stream.SeekI(0, wxFromEnd);
@ -773,8 +856,9 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
stream.SeekI(0, wxFromStart); stream.SeekI(0, wxFromStart);
src = (unsigned char *) malloc(file_length); src = (unsigned char *) malloc(file_length);
stream.Read(src, file_length); stream.Read(src, file_length);
} else } else {
return false; return false;
}
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
@ -783,11 +867,12 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
opj_setup_decoder(dinfo, &parameters); opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */ /* open a byte stream */
if (jpfamform == MJ2_CFMT) if (jpfamform == MJ2_CFMT) {
cio = opj_cio_open((opj_common_ptr)dinfo, src, jpeg2000headSIZE + jp2hboxlen + jp2cboxlen); cio = opj_cio_open((opj_common_ptr)dinfo, src,
else if (jpfamform == JP2_CFMT || jpfamform == J2K_CFMT) jpeg2000headSIZE + jp2hboxlen + jp2cboxlen);
} else if (jpfamform == JP2_CFMT || jpfamform == J2K_CFMT) {
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
else { } else {
free(src); free(src);
return false; return false;
} }
@ -820,20 +905,24 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
int c, tempcomps; int c, tempcomps;
// check components number // check components number
if (m_components > opjimage->numcomps) if (m_components > opjimage->numcomps) {
m_components = opjimage->numcomps; m_components = opjimage->numcomps;
}
// check image depth (only on the first one, for now) // check image depth (only on the first one, for now)
if (m_components) if (m_components) {
shiftbpp = opjimage->comps[m_components - 1].prec - 8; shiftbpp = opjimage->comps[m_components - 1].prec - 8;
else } else {
shiftbpp = opjimage->comps[0].prec - 8; shiftbpp = opjimage->comps[0].prec - 8;
}
// prepare image size // prepare image size
if (m_components) if (m_components) {
image->Create(opjimage->comps[m_components - 1].w, opjimage->comps[m_components - 1].h, true); image->Create(opjimage->comps[m_components - 1].w,
else opjimage->comps[m_components - 1].h, true);
} else {
image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true); image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true);
}
// access image raw data // access image raw data
image->SetMask(false); image->SetMask(false);
@ -849,12 +938,14 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
wxMutexGuiLeave(); wxMutexGuiLeave();
#endif /* __WXGTK__ */ #endif /* __WXGTK__ */
tempcomps = 1; tempcomps = 1;
} else } else {
tempcomps = opjimage->numcomps; tempcomps = opjimage->numcomps;
}
// workaround for subsampled components // workaround for subsampled components
for (c = 1; c < tempcomps; c++) { for (c = 1; c < tempcomps; c++) {
if ((opjimage->comps[c].w != opjimage->comps[c - 1].w) || (opjimage->comps[c].h != opjimage->comps[c - 1].h)) { if ((opjimage->comps[c].w != opjimage->comps[c - 1].w) ||
(opjimage->comps[c].h != opjimage->comps[c - 1].h)) {
tempcomps = 1; tempcomps = 1;
break; break;
} }
@ -869,8 +960,9 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
} }
// only one component selected // only one component selected
if (m_components) if (m_components) {
tempcomps = 1; tempcomps = 1;
}
// RGB color picture // RGB color picture
if (tempcomps == 3) { if (tempcomps == 3) {
@ -918,10 +1010,11 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
int row, col; int row, col;
int selcomp; int selcomp;
if (m_components) if (m_components) {
selcomp = m_components - 1; selcomp = m_components - 1;
else } else {
selcomp = 0; selcomp = 0;
}
int *y = opjimage->comps[selcomp].data; int *y = opjimage->comps[selcomp].data;
if (shiftbpp > 0) { if (shiftbpp > 0) {
@ -969,10 +1062,11 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
opj_image_destroy(opjimage); opj_image_destroy(opjimage);
free(src); free(src);
if (!image->Ok()) if (!image->Ok()) {
return false; return false;
else } else {
return true; return true;
}
} }
@ -982,7 +1076,8 @@ bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool ver
#define COMP_48_CS 520833 /* Maximum size per color component for 2K @ 48fps */ #define COMP_48_CS 520833 /* Maximum size per color component for 2K @ 48fps */
// save the j2k codestream // save the j2k codestream
bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbose ) bool wxJPEG2000Handler::SaveFile(wxImage *wimage, wxOutputStream& stream,
bool verbose)
{ {
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -1011,7 +1106,8 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
parameters.cp_cinema = OFF; parameters.cp_cinema = OFF;
/* subsampling */ /* subsampling */
if (sscanf(m_subsampling.ToAscii(), "%d,%d", &(parameters.subsampling_dx), &(parameters.subsampling_dy)) != 2) { if (sscanf(m_subsampling.ToAscii(), "%d,%d", &(parameters.subsampling_dx),
&(parameters.subsampling_dy)) != 2) {
wxLogError(wxT("Wrong sub-sampling encoder setting: dx,dy")); wxLogError(wxT("Wrong sub-sampling encoder setting: dx,dy"));
return false; return false;
} }
@ -1020,13 +1116,15 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
if ((m_rates != wxT("")) && (!m_enablequality)) { if ((m_rates != wxT("")) && (!m_enablequality)) {
const char *s1 = m_rates.ToAscii(); const char *s1 = m_rates.ToAscii();
wxLogMessage(wxT("rates %s"), s1); wxLogMessage(wxT("rates %s"), s1);
while (sscanf(s1, "%f", &(parameters.tcp_rates[parameters.tcp_numlayers])) == 1) { while (sscanf(s1, "%f", &(parameters.tcp_rates[parameters.tcp_numlayers])) ==
1) {
parameters.tcp_numlayers++; parameters.tcp_numlayers++;
while (*s1 && *s1 != ',') { while (*s1 && *s1 != ',') {
s1++; s1++;
} }
if (!*s1) if (!*s1) {
break; break;
}
s1++; s1++;
} }
wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers); wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers);
@ -1037,13 +1135,15 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
if ((m_quality != wxT("")) && (m_enablequality)) { if ((m_quality != wxT("")) && (m_enablequality)) {
const char *s2 = m_quality.ToAscii(); const char *s2 = m_quality.ToAscii();
wxLogMessage(wxT("qualities %s"), s2); wxLogMessage(wxT("qualities %s"), s2);
while (sscanf(s2, "%f", &parameters.tcp_distoratio[parameters.tcp_numlayers]) == 1) { while (sscanf(s2, "%f", &parameters.tcp_distoratio[parameters.tcp_numlayers]) ==
1) {
parameters.tcp_numlayers++; parameters.tcp_numlayers++;
while (*s2 && *s2 != ',') { while (*s2 && *s2 != ',') {
s2++; s2++;
} }
if (!*s2) if (!*s2) {
break; break;
}
s2++; s2++;
} }
wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers); wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers);
@ -1051,7 +1151,8 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
} }
/* image origin */ /* image origin */
if (sscanf(m_origin.ToAscii(), "%d,%d", &parameters.image_offset_x0, &parameters.image_offset_y0) != 2) { if (sscanf(m_origin.ToAscii(), "%d,%d", &parameters.image_offset_x0,
&parameters.image_offset_y0) != 2) {
wxLogError(wxT("bad coordinate of the image origin: x0,y0")); wxLogError(wxT("bad coordinate of the image origin: x0,y0"));
return false; return false;
} }
@ -1089,8 +1190,10 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
if (m_cbsize != wxT("")) { if (m_cbsize != wxT("")) {
int cblockw_init = 0, cblockh_init = 0; int cblockw_init = 0, cblockh_init = 0;
sscanf(m_cbsize.ToAscii(), "%d,%d", &cblockw_init, &cblockh_init); sscanf(m_cbsize.ToAscii(), "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) { if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 ||
wxLogError(wxT("!! Size of code_block error !! Restrictions:\n width*height<=4096\n 4<=width,height<= 1024")); cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
wxLogError(
wxT("!! Size of code_block error !! Restrictions:\n width*height<=4096\n 4<=width,height<= 1024"));
return false; return false;
} }
parameters.cblockw_init = cblockw_init; parameters.cblockw_init = cblockw_init;
@ -1104,7 +1207,8 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
char *s = (char *) m_prsize.c_str(); char *s = (char *) m_prsize.c_str();
do { do {
sep = 0; sep = 0;
sscanf(s, "[%d,%d]%c", &parameters.prcw_init[res_spec], &parameters.prch_init[res_spec], &sep); sscanf(s, "[%d,%d]%c", &parameters.prcw_init[res_spec],
&parameters.prch_init[res_spec], &sep);
parameters.csty |= 0x01; parameters.csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
@ -1119,24 +1223,28 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
} }
/* tile origin */ /* tile origin */
if (sscanf(m_torigin.ToAscii(), "%d,%d", &parameters.cp_tx0, &parameters.cp_ty0) != 2) { if (sscanf(m_torigin.ToAscii(), "%d,%d", &parameters.cp_tx0,
&parameters.cp_ty0) != 2) {
wxLogError(wxT("tile offset setting error: X0,Y0")); wxLogError(wxT("tile offset setting error: X0,Y0"));
return false; return false;
} }
/* use SOP */ /* use SOP */
if (m_enablesop) if (m_enablesop) {
parameters.csty |= 0x02; parameters.csty |= 0x02;
}
/* use EPH */ /* use EPH */
if (m_enableeph) if (m_enableeph) {
parameters.csty |= 0x04; parameters.csty |= 0x04;
}
/* multiple component transform */ /* multiple component transform */
if (m_multicomp) if (m_multicomp) {
parameters.tcp_mct = 1; parameters.tcp_mct = 1;
else } else {
parameters.tcp_mct = 0; parameters.tcp_mct = 0;
}
/* mode switch */ /* mode switch */
parameters.mode = (m_enablebypass ? 1 : 0) + (m_enablereset ? 2 : 0) parameters.mode = (m_enablebypass ? 1 : 0) + (m_enablereset ? 2 : 0)
@ -1248,8 +1356,9 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
/* create the image */ /* create the image */
oimage = opj_image_create(3, &cmptparm[0], CLRSPC_SRGB); oimage = opj_image_create(3, &cmptparm[0], CLRSPC_SRGB);
if (!oimage) { if (!oimage) {
if (cmptparm) if (cmptparm) {
free(cmptparm); free(cmptparm);
}
return false; return false;
} }
@ -1282,7 +1391,8 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
parameters.numresolution = 6; parameters.numresolution = 6;
} }
if (!((oimage->comps[0].w == 2048) | (oimage->comps[0].h == 1080))) { 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 " 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"), "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080"),
oimage->comps[0].w, oimage->comps[0].h); oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ; parameters.cp_rsiz = STD_RSIZ;
@ -1296,7 +1406,8 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
parameters.numresolution = 7; parameters.numresolution = 7;
} }
if (!((oimage->comps[0].w == 4096) | (oimage->comps[0].h == 2160))) { 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" 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"), "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160"),
oimage->comps[0].w, oimage->comps[0].h); oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ; parameters.cp_rsiz = STD_RSIZ;
@ -1325,13 +1436,16 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
for (i = 0 ; i < parameters.tcp_numlayers; i++) { for (i = 0 ; i < parameters.tcp_numlayers; i++) {
temp_rate = 0; temp_rate = 0;
if (parameters.tcp_rates[i] == 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)) / 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); (CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else { } else {
temp_rate = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) / 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); (parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_24_CS) { 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)) / 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); (CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else { } else {
/* do nothing */ /* do nothing */
@ -1345,13 +1459,16 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
for (i = 0; i < parameters.tcp_numlayers; i++) { for (i = 0; i < parameters.tcp_numlayers; i++) {
temp_rate = 0 ; temp_rate = 0 ;
if (parameters.tcp_rates[i] == 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)) / 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); (CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else { } else {
temp_rate =((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) / 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); (parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_48_CS) { 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)) / 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); (CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else { } else {
/* do nothing */ /* do nothing */
@ -1385,12 +1502,15 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
opj_cio_close(cio); opj_cio_close(cio);
opj_destroy_compress(cinfo); opj_destroy_compress(cinfo);
opj_image_destroy(oimage); opj_image_destroy(oimage);
if (cmptparm) if (cmptparm) {
free(cmptparm); free(cmptparm);
if(parameters.cp_comment) }
if (parameters.cp_comment) {
free(parameters.cp_comment); free(parameters.cp_comment);
if(parameters.cp_matrice) }
if (parameters.cp_matrice) {
free(parameters.cp_matrice); free(parameters.cp_matrice);
}
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
@ -1426,12 +1546,15 @@ bool wxJPEG2000Handler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool
/* free image data */ /* free image data */
opj_image_destroy(oimage); opj_image_destroy(oimage);
if (cmptparm) if (cmptparm) {
free(cmptparm); free(cmptparm);
if(parameters.cp_comment) }
if (parameters.cp_comment) {
free(parameters.cp_comment); free(parameters.cp_comment);
if(parameters.cp_matrice) }
if (parameters.cp_matrice) {
free(parameters.cp_matrice); free(parameters.cp_matrice);
}
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
@ -1456,14 +1579,17 @@ bool wxJPEG2000Handler::DoCanRead(wxInputStream& stream)
unsigned char hdr[24]; unsigned char hdr[24];
int jpfamform; int jpfamform;
if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) if (!stream.Read(hdr, WXSIZEOF(hdr))) {
return false; return false;
}
jpfamform = jpeg2000familytype(hdr, WXSIZEOF(hdr)); jpfamform = jpeg2000familytype(hdr, WXSIZEOF(hdr));
return ((jpfamform == JP2_CFMT) || (jpfamform == MJ2_CFMT) || (jpfamform == J2K_CFMT)); return ((jpfamform == JP2_CFMT) || (jpfamform == MJ2_CFMT) ||
(jpfamform == J2K_CFMT));
} }
#endif // wxUSE_STREAMS #endif // wxUSE_STREAMS
#endif // wxUSE_LIBOPENJPEG #endif // wxUSE_LIBOPENJPEG

File diff suppressed because it is too large Load Diff