Results 1 to 5 of 5

Thread: Creating a Qt custom image plugin for a format that resembles JPEG

  1. #1
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Creating a Qt custom image plugin for a format that resembles JPEG

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating a Qt custom image plugin for a format that resembles JPEG

    JPEG decoding in Qt is done via libjpeg. Qt doesn't decode JPEG data by itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Creating a Qt custom image plugin for a format that resembles JPEG

    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.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Creating a Qt custom image plugin for a format that resembles JPEG

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating a Qt custom image plugin for a format that resembles JPEG

    Quote Originally Posted by datek2517 View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Save pictures in JPEG format into QDataStream
    By Eos Pengwern in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2009, 13:14
  2. Replies: 11
    Last Post: 13th July 2009, 16:05
  3. Saving image in jpeg format failed
    By febil in forum Qt Programming
    Replies: 5
    Last Post: 23rd April 2009, 11:33
  4. Gif/Jpeg plugin
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 13th February 2008, 14:06
  5. JPEG Image isn't displayed!?
    By GodOfWar in forum Qt Programming
    Replies: 9
    Last Post: 16th April 2007, 15:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.