PDA

View Full Version : Creating a Qt custom image plugin for a format that resembles JPEG



datek2517
19th May 2011, 21:27
I should first mention that I'm pretty new to Qt. I need to write a custom image plugin for a special image format that uses a header format distinct from that of JPEG but which stores pixel data so that it looks like a JPEG image. I've looked at tutorials about how to subclass QImageIOPlugin and create a custom image plugin, but I'm unsure of the best way to go about writing the code to read the special header and then get the pixel data into a QImage.

Since JPEGs are already supported out of the box by Qt 4.7, would I be able to reuse some of the JPEG implementation? For example, would I be able to subclass the QJpegHandler already used by Qt and re-implement how the header is read? Or should I just write a custom image plugin from scratch and use the JPEG implementation as a guide?

Thanks a lot!

wysota
21st May 2011, 00:22
JPEG decoding in Qt is done via libjpeg. Qt doesn't decode JPEG data by itself.

datek2517
21st May 2011, 21:44
Thanks for the response. I understand that libjpeg is responsible for decoding the JPEG data and not QT, but I wish to use the same functionality that Qt's JPEG plugin implements in order to call libjpeg's functions and read the decoded image into a QImage. I'm wondering if I'd have to re-implement the same kind of behavior inside my own plugin (calling libjpeg as necessary, just for my own custom file format), or if I could somehow inherit the image reading functions of QJpegHandler and merely change how it reads the image header. Qt won't let me subclass any of the JPEG plugin classes directly.

I realize this is a bit of an odd request, and being new to Qt, I'm just really confused as to how this all fits together with plugins. It seems like I'd have to just create my new image plugin and handler and just follow along with how the JPEG plugin renders the image.

SixDegrees
21st May 2011, 21:59
Qt is just a framework, written in C++, that provides UI widgets and application tools. Under the hood, it's often calling a variety of external libraries to accomplish it's tasks. The jpeg plugin is no exception; it uses libjpeg to process files. The I/O framework simply provides a standardized API so file I/O is handled in a consistent manner for the entire variety of files Qt handles.

None of this is exposed to the end user, other than the top-level interface itself. How files get read and written is opaque.

You can, of course, read through the Qt source code if you're interested in how they implement a particular class. But attempting to use that code runs the risk of having the rug yanked out from under your file plugin if internal details change.

Presumably, there is either an existing library for handling the files you're trying to work with, or sufficient documentation to allow you to parse the header and retrieve the image data. It may be that you can pass that data along to libjpeg for further decoding if it is formatted properly; if not, you'll have to find another decoder or write one yourself.

wysota
22nd May 2011, 17:26
Thanks for the response. I understand that libjpeg is responsible for decoding the JPEG data and not QT, but I wish to use the same functionality that Qt's JPEG plugin implements in order to call libjpeg's functions and read the decoded image into a QImage. I'm wondering if I'd have to re-implement the same kind of behavior inside my own plugin (calling libjpeg as necessary, just for my own custom file format),
If your format is not JPEG, how do you expect libjpeg to process it?