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. Qpixmap scale to preserve the color mapping
Forum Updated to NodeBB v4.3 + New Features

Qpixmap scale to preserve the color mapping

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 2.4k 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.
  • H Offline
    H Offline
    heatblazer
    wrote on last edited by
    #1

    Hello, I am wondering, if I can preserve the color mapping of given .png file, while scaling a QPixmap, or QImage. Let`s say we have 1200x800 png file, then scale it to 1/2 by both WxH. The color is changed of the different pixels in the scaled image. So, can I preserve it?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      QPixmap doesn't provide such features, since it's optimized for screen display.
      QImage in contrast is made for raw image manipulation. Such as support for color tables.
      I can't give you an example right now, but you will have to go with QImage and make sure it has QImage::Format_Indexed8 in order to use QImage's colorTable methods. If i understood you correct.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • H Offline
        H Offline
        heatblazer
        wrote on last edited by
        #3

        Yes, kind of that. Lets say in a png with 1200x800 at pixel 100,100 its RGB 255,0,0, When I scale it to 800x600 can I preserve the pixel at let`s say 40,40, which was 100,100 to the same RGB?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          i don't understand what could be your use case.
          Scaling (down) means that you need to merge several pixels with most probably different colors down to 1 pixel. So which color the "new" pixel gets is decided by the used algorithm.

          A simple algorithm for your desired downscaling would be to calculate the scaling factor first. Then map the pixel values with the factor to your scaled image.

          But i am pretty sure the result look beyond acceptable :)
          In some case not even recognizable from the original.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • H Offline
            H Offline
            heatblazer
            wrote on last edited by
            #5

            So, I have to use SVG to derive different sized QImage-s :(

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              you still haven't said for what you need this requirement.
              Why is Qt's offered scaling not acceptable for you?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • H Offline
                H Offline
                heatblazer
                wrote on last edited by
                #7

                Let me show you this....
                https://www.flickr.com/photos/heatblazer/15927159799/

                Consider that I am creating custom QGraphicsEllipseItems, when I found my custom mapped collor by iterating trough the image as shown. There are small red pixels in each circle. When I found them, I put invisible, clickable QGraphicsEllipseItem. Kind of mapping items by color. But when I scale, the so-called "Marker color" is lost.

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

                  So, just identify the positions of the markers before scaling, and then recalculate what the positions would be after scaling?

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    well such an approach is very error prone .. .as you see :)
                    Why not checking programmatically? For example if you depend on analyzing the image data you can translate points (e.g. from mouse events) from your graphics item to the point in the image via the calculated scale factor.
                    So that your logic still operates on the original sized image.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      heatblazer
                      wrote on last edited by
                      #10

                      [quote author="Andre" date="1421844408"]So, just identify the positions of the markers before scaling, and then recalculate what the positions would be after scaling?[/quote]

                      That is, actually, a not bad idea...

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        heatblazer
                        wrote on last edited by
                        #11

                        [quote author="raven-worx" date="1421844500"]well such an approach is very error prone .. .as you see :)
                        Why not checking programmatically? For example if you depend on analyzing the image data you can translate points (e.g. from mouse events) from your graphics item to the point in the image via the calculated scale factor.
                        So that your logic still operates on the original sized image.[/quote]

                        Its more complicated than that. First, the items must be created before the mouse is clicked. Then they are connected with the game logic, they are connected with the graph logic too. The items are set before user knows it. It would be simple just to click and create item, but the code is already rolled that way and I dont have time to complete reverse engeneering it. So SVG scale? Any hints? I`d be grateful if you hint me abotu QSvgRenderer.

                        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