Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Png images
Forum Updated to NodeBB v4.3 + New Features

Png images

Scheduled Pinned Locked Moved Mobile and Embedded
15 Posts 4 Posters 6.7k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    f.vanalmetelevic.com
    wrote on last edited by
    #1

    Hi,

    We have a Qt application for ARM-base board with a lot of small .png images (button backgrounds, icons,...).
    At startup, we get this message : "QImage: out of memory, returning null image". However, the application continues to start up and there seem no more problem after that.
    Moreover, most images are larger that they appear on screen, so they need to be rescaled at runtime by Qt.
    I suspect the number of images and the rescaling to be the cause of the problem. But, I'm not sure, because I don't know how png's are handled by Qt applications.
    We put all our png images in our project's .qrc file. I guess, they all end up, still in png format, in the executable. But what happens when launching the application ? Is Qt extracting all images at once or just those it needs at that time ? How are the images extracted : in compressed png format or in un-compressed full size (in terms of memory) format ? When it has to rescale an image, I guess it first has to uncompress the image before it can rescale it. So, at a certain time, the full size image (in terms of memory) will be present in memory. Correct ? Once scaled, will the original image be removed from memory ?

    Thanks in advance for help !

    Filip

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #2

      I'm not sure what's the problem, can you paste some code?

      Chuck

      1 Reply Last reply
      0
      • F Offline
        F Offline
        f.vanalmetelevic.com
        wrote on last edited by
        #3

        Hi Chuck,

        I don't know if there's really a problem... There's the message at startup, indicating that we are possibly running low in memory, but that's it...
        In fact, I'm just curious in how Qt is handling png's because :

        • it might not be the best solution to have lots of png's in an application with respect to memory consumption.
        • it might not be a good idea to let the application scale the images at runtime.

        Filip

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          What is the final size of your executable when you do use the resource system? How much RAM does your target device have?

          Do you get the same problem if you do not compile the images into your application using the resource system?

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chuck Gao
            wrote on last edited by
            #5

            [quote author="filip" date="1305896713"]Hi Chuck,

            I don't know if there's really a problem... There's the message at startup, indicating that we are possibly running low in memory, but that's it...
            In fact, I'm just curious in how Qt is handling png's because :

            • it might not be the best solution to have lots of png's in an application with respect to memory consumption.
            • it might not be a good idea to let the application scale the images at runtime.

            Filip[/quote]

            Yes, actually when you use Qt resource system(as you know .qrc) in your project, and the rcc(resource compiler)will turn it to cpp, and it's compiled in with your application. As ZapB asked, maybe it's too large for ARM-based board using.It's depend on your image size.

            But, if you want to load the image at run time, you can don't use qrc, or load qrc resource dynamically instead of compile it in.

            Chuck

            1 Reply Last reply
            0
            • F Offline
              F Offline
              f.vanalmetelevic.com
              wrote on last edited by
              #6

              The final size of the executable is 1198462 bytes.
              Target has 64 Mb of RAM.
              Not yet tested when not compiled in to application.
              Number of png's in qrc file : 170!

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #7

                If you are targeting a particular device it is pointless to rescale the images at runtime over and over again. Much better idea to rescale them once offline and use the rescaled images directly.

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chuck Gao
                  wrote on last edited by
                  #8

                  [quote author="ZapB" date="1305897728"]If you are targeting a particular device it is pointless to rescale the images at runtime over and over again. Much better idea to rescale them once offline and use the rescaled images directly.[/quote]

                  Agree. Different device, different resolution.

                  Chuck

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    f.vanalmetelevic.com
                    wrote on last edited by
                    #9

                    Just to be sure my reasoning is right :
                    One of the images is 25Kb in size. If I open that image, the size is 3289x1385 pixels. So, if we have to rescale that, the app has to load the original image in memory meaning consuming 3289x1385x3 = 13,66Mb of RAM (if I assume 24 bits per pixel). Right ?

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #10

                      Yes except it is more likely 4 bytes per pixel since it could well be using RGBA pixel format. What is your screen resolution on your device? I doubt it is anywhere near that image size is it?

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        f.vanalmetelevic.com
                        wrote on last edited by
                        #11

                        The screen resolution of the target is 800x480 !
                        Well, it's clear that this way of working is not a good choice at all... it looks like the application will need some rework...
                        Resizing the images once to their correct size will certainly resolve the "out of memory" problem...

                        Thanks !

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #12

                          The app should not need much reworking if it is already using the larger images. You just need to spend a little time in your favourite image editor rescaling the png's to more suitable sizes. Another bonus is that yoru app will load faster (since it will be smaller) and it will also display the images faster since there will be no slow software scaling to be performed.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            f.vanalmetelevic.com
                            wrote on last edited by
                            #13

                            Stupid remark of me...! Of course, app should normally not change one byte... only scale images.

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              ZapB
                              wrote on last edited by
                              #14

                              No worries - it's Friday afternoon. My brain has already departed for the weekend ;-)

                              Nokia Certified Qt Specialist
                              Interested in hearing about Qt related work

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                srikanth_trulyit
                                wrote on last edited by
                                #15
                                1. Imaging scaling is very expensive and memory constrained in low memory devices like handhelds.
                                2. Why don't you use svg instead of png. They scale to the target resolution and work like a charm in low memory targets.
                                3. If you still prefer to use png files, please scale it yourself and provide an image cache that resides on the disk rather than on RAM. If you downscale try doing a "cheat scale":http://labs.qt.nokia.com/2009/01/26/creating-thumbnail-preview/
                                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