Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Jpeg2000 Class Reference

Wrapper around OpenJPEG library, in C, for opening jpeg2000 files. More...

#include <Jpeg2000.h>

Collaboration diagram for Jpeg2000:
Collaboration graph

Public Member Functions

 Jpeg2000 ()
 Single constructor.
 
bool load (const QString &filename, QImage &image) const
 Load image from jpeg2000 file.
 
QStringList supportedImageWildcards () const
 List the supported jpeg2000 file extensions, for filtering import files.
 

Detailed Description

Wrapper around OpenJPEG library, in C, for opening jpeg2000 files.

Definition at line 26 of file Jpeg2000.h.

Constructor & Destructor Documentation

◆ Jpeg2000()

Jpeg2000::Jpeg2000 ( )

Single constructor.

Definition at line 21 of file Jpeg2000.cpp.

22{
23}

Member Function Documentation

◆ load()

bool Jpeg2000::load ( const QString & filename,
QImage & image ) const

Load image from jpeg2000 file.

Definition at line 192 of file Jpeg2000.cpp.

194{
195 LOG4CPP_INFO_S ((*mainCat)) << "Jpeg2000::load"
196 << " filename=" << filename.toLatin1().data();
197
198 if (invalidFileExtension (filename)) {
199 return false;
200 }
201
203 initializeParameters (parameters);
204
205 parameters.decod_format = inputFormat (filename.toLatin1().data());
206
208 if (!inStream) {
209 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load encountered error opening stream";
210 return false;
211 }
212
213 // Create decoder
214 opj_codec_t *inCodec = decode (parameters.decod_format);
215 if (!inCodec) {
216 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load encountered error creating decoding stream";
218 return false;
219 }
220
221 // Callbacks for local handling of errors
225
227 &parameters)) {
228 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load encountered error decoding stream";
231 return false;
232 }
233
234 // Read header and, if necessary, the JP2 boxes
235 opj_image_t *image;
237 inCodec,
238 &image)) {
239 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load encountered error reading header";
242 opj_image_destroy (image);
243 return false;
244 }
245
246 // Get the decoded image
247 if (!(opj_decode (inCodec,
248 inStream,
249 image) &&
251 inStream))) {
252 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load failed to decode image";
255 opj_image_destroy (image);
256 return false;
257 }
258
259 // Close the byte stream
261
262 applyImageTweaks (image);
263
264 // Transform into ppm image in memory
265 bool success = true;
267 buffer.open (QBuffer::WriteOnly);
268 if (imagetopnm (image,
269 buffer)) {
270 LOG4CPP_ERROR_S ((*mainCat)) << "Jpeg2000::load failed to generate new image";
271 success = false;
272
273 } else {
274
275 // Intermediate file for debugging
276// QFile file ("jpeg2000.ppm");
277// file.open (QIODevice::WriteOnly);
278// file.write (buffer.data());
279// file.close ();
280
281 // Create output
282 imageResult.loadFromData(buffer.data());
283
284 }
285
286 // Deallocate
287 if (inCodec) {
289 }
290 opj_image_destroy (image);
291
292 return success;
293}
const int INNER_RADIUS_MIN
void warningCallback(const char *msg, void *)
void infoCallback(const char *msg, void *)
void errorCallback(const char *msg, void *)
int imagetopnm(opj_image_t *image, QBuffer &buffer)
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12

◆ supportedImageWildcards()

QStringList Jpeg2000::supportedImageWildcards ( ) const

List the supported jpeg2000 file extensions, for filtering import files.

Definition at line 305 of file Jpeg2000.cpp.

306{
307 QStringList extensions = supportedFileExtensions();
309
310 QStringList::iterator itr;
311 for (itr = extensions.begin(); itr != extensions.end(); itr++) {
313 QString wildcard = QString ("*.%1").arg (extension);
315 }
316
317 return wildcards;
318}

The documentation for this class was generated from the following files: