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. How to load TGA file?
Forum Updated to NodeBB v4.3 + New Features

How to load TGA file?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 1.8k 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.
  • M Offline
    M Offline
    MT339M
    wrote on last edited by
    #1
    QPixmap *pixmap = new QPixmap(u8"C:\\Users\\mycom\\Downloads\\sample.tga");
    QLabel *label = new QLabel(this);
    
    label->setPixmap(*pixmap);
    label->resize(pixmap->width(), pixmap->height());
    label->move(0, 0);
    label->show();
    

    I tried to load a TGA file using QPixmap like above, but nothing is displayed.
    ICO files were not displayed either. BMP, PNG files were displayed well.

    qDebug() << QImageReader::supportedImageFormats();
    

    When I call a QImageReader::supportedImageFormats() method, I could get a string like.

    ("bmp", "cur", "gif", "icns", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")
    

    My plugin directory path is "C:\Qt\Qt5.14.2\5.14.2\msvc2017\plugins\imageformats" and there are qtga.dll and qtgad.dll.
    And I called a QApplication::addLibraryPath() method with the path as argument, but It's not working as well.

    Could you tell me why it doesn't work? Thanks.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Maybe the tga file has a format the plugin does not understand. Take a look if you can see something on stdout.

      btw: you're leaking *pixmap - no need to create it on the heap at all.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • M Offline
        M Offline
        MT339M
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Maybe the tga file has a format the plugin does not understand. Take a look if you can see something on stdout.

          btw: you're leaking *pixmap - no need to create it on the heap at all.

          M Offline
          M Offline
          MT339M
          wrote on last edited by MT339M
          #4

          @Christian-Ehrlicher

          Thank you for your quick answer. I can see a message 'C:\Qt\Qt5.14.2\5.14.2\msvc2017\plugins\imageformats\qtgad.dll' file is loaded on stdout. But there was no other information on stdout. I used a tga image on https://filesamples.com/formats/tga. I'm quite confused. 😂

          qDebug() << pixmap.width();
          qDebug() << pixmap.height();
          

          The above code outputs zero.
          I have tested with images on https://filesamples.com/categories/image. BMP, CUR, GIF, ICO, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, WBMP, WEBP, XBM and XPM file formats were all well displayed. (The previously tested ICO file was also well printed. The image was so small that I thought It is not printed.) But only the TGA file is not displayed. Would you mind testing with that file? Thanks.

          (Oh, thank you for your advice to make QPixmap object on stack.)

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            The plugin only supports 8, 16 or 24 bit color uncompressed tga files.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 1 Reply Last reply
            2
            • Christian EhrlicherC Christian Ehrlicher

              The plugin only supports 8, 16 or 24 bit color uncompressed tga files.

              M Offline
              M Offline
              MT339M
              wrote on last edited by
              #6

              @Christian-Ehrlicher

              Thank you for your reply :) The file's header is:

              00 00 02 00 00 00 00 00 00 00 00 00 80 02 AA 01 18 00

              I think it's a 24 bit color uncompressed tga file (0x02 and 0x18). Is there something I'm wrong with?

              Christian EhrlicherC 1 Reply Last reply
              0
              • M MT339M

                @Christian-Ehrlicher

                Thank you for your reply :) The file's header is:

                00 00 02 00 00 00 00 00 00 00 00 00 80 02 AA 01 18 00

                I think it's a 24 bit color uncompressed tga file (0x02 and 0x18). Is there something I'm wrong with?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @MT339M Looks fine, maybe some other unreadable stuff. Can you provide this tga file?, what does QImage::isNull() return?

                The size is 0x280/0x1aa = 640/426 with 24bpp, correct?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                M 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @MT339M Looks fine, maybe some other unreadable stuff. Can you provide this tga file?, what does QImage::isNull() return?

                  The size is 0x280/0x1aa = 640/426 with 24bpp, correct?

                  M Offline
                  M Offline
                  MT339M
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher

                  1. IsNull() method return true.
                  2. Yes, your interpretation of the header is right.

                  Oh, I'm sorry I thought you knew the image's URL. the image's URL is https://filesamples.com/samples/image/tga/sample_640×426.tga.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #9

                    It's no Truevision TGA' file as it seems ( https://en.wikipedia.org/wiki/Truevision_TGA#File_footer_(optional) ). The plugin checks for this existence and refuses to load it if it is not found.
                    Sadly the error message can not be moved up and is not printed to stdout through qWarning(). I will provide a patch for this.

                    /edit: https://codereview.qt-project.org/c/qt/qtimageformats/+/316182

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    M 1 Reply Last reply
                    3
                    • Christian EhrlicherC Christian Ehrlicher

                      It's no Truevision TGA' file as it seems ( https://en.wikipedia.org/wiki/Truevision_TGA#File_footer_(optional) ). The plugin checks for this existence and refuses to load it if it is not found.
                      Sadly the error message can not be moved up and is not printed to stdout through qWarning(). I will provide a patch for this.

                      /edit: https://codereview.qt-project.org/c/qt/qtimageformats/+/316182

                      M Offline
                      M Offline
                      MT339M
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher

                      Thank you. I think I have to find out the point where the error occurs in QT's source code. Thank you for the patch, too.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @MT339M said in How to load TGA file?:

                        I think I have to find out the point where the error occurs in QT's source code.

                        Why? It will not help you - the tga file has to be Truevision 2.0 compliant which is not according the plugin so..)

                        https://code.woboq.org/qt5/qtimageformats/src/plugins/imageformats/tga/qtgafile.cpp.html#184

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        M 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @MT339M said in How to load TGA file?:

                          I think I have to find out the point where the error occurs in QT's source code.

                          Why? It will not help you - the tga file has to be Truevision 2.0 compliant which is not according the plugin so..)

                          https://code.woboq.org/qt5/qtimageformats/src/plugins/imageformats/tga/qtgafile.cpp.html#184

                          M Offline
                          M Offline
                          MT339M
                          wrote on last edited by MT339M
                          #12

                          @Christian-Ehrlicher

                          I didn't mean to say that. I'm sorry I didn't speak very well. I tried to determine which part of the file did not meet the specification. I saw the part where it check the footer, so I attached the footer, and the problem was found.

                          Oh I got it. You already gave me a link related to footer. (I just recognized it as a tga document. I didn't recognize the anchor.) I had passed it. I checked it right now.

                          1 Reply Last reply
                          1

                          • Login

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