Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing an image as it's generated

Writing an image as it's generated

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    esdrasbeleza
    wrote on last edited by
    #1

    Hi,

    I'm doing some image processing using Qt. I have a data source that provides, from (0,0) to (width, height), the necessary data to write an image: the ordered pixels and their R,G,B values.

    My code currently uses libpng, that does the following tasks:

    1. Create a png file
    2. Write its header
    3. As each full line is received from my data source, it's appended to my output file
    4. Closes the file if there's no more data to be received.

    I want to remove libpng from my project and use only Qt, in order to avoid dependencies. But I'm unable to find a way, using something like a QImage, to write every image line as it's read. I tried to use QImage, but it stores image data in memory and only writes the image data when I call QImage::save(). If I call save() every time I read a new line, the process will be slow because all the lines before will be written again, right?

    So, is there some way to append a new line to an image file when I get the values for its pixels?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      You could just use a plain vanilla QFile, I suppose. But I would stop and ask why. Your scenario is strange, and I wonder if there's a better approach for what you're trying to accomplish, perhaps. What is the benefit to having the data saved as it's being created, rather that it being buffered first?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Removing libpng won't help you. Libpng is already linked into Qt itself by default, so you can use that version of it directly as well.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          esdrasbeleza
          wrote on last edited by
          #4

          @mlong, I just want to parallelize the task.

          @Andre, I know that Qt uses libpng, but I'd like to use QImage so I can use different output formats in a easier way, not only PNG files. And I know that Qt uses libpng and that libpng is linked into Qt, but there isn't a way to access the libpng functions (like png_write_row()) that are linked to Qt, there is?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rcari
            wrote on last edited by
            #5

            If you want to parallelize, you should just create your full QImage and then pass that to a thread that will do the writing, hence leaving your main thread available to process a new image.
            Your case is indeed strange and I can't see how you can expect a real performance gain in such a design.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved