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. Problems with image colortable from latin1 file

Problems with image colortable from latin1 file

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k 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.
  • X Offline
    X Offline
    xxxOllixxx
    wrote on last edited by
    #1

    Hello,

    I wrote some Raw-Image-Reader and most of it works. But I still cant figure out how to set the colortable correctly. So first of all here is my code example:

    QFile file(":/new/1.raw"); //open file dialog
    if(file.open(QIODevice::ReadOnly)){qDebug("File opened");}
    else{qDebug("File not opened");}

    QByteArray ba=file.readAll(); //read file into bytearray

    QImage image(512,256,QImage::Format_Indexed8); //setup the blank image for pixel transfer later

    QVector<QRgb> colorTable; //setup the 8 bit grayscale colortable
    for(int i=0;i<256;i++) colorTable.push_back(qRgb(i,i,i));
    image.setColorTable(colorTable);

    image.fill(0); //just displaying a blank image here
    QPixmap pix1(QPixmap::fromImage(image));
    ui->label->setPixmap(pix1);

    int j=0; //image manipulation procedure
    for(int y=0;y<image.height();y++){
    for(int x=0;x<image.width();x++){image.setPixel(x,y,ba.at( j)+128); j++;}}
    // I add +128 because the image file give me values from -128...127

    QPixmap pix2(QPixmap::fromImage(image)); //display the file image on second pixmap here
    ui->label_4->setPixmap(pix2);

    So like I said most of it works, but it displays half of the image in a very dark colors and some other parts looking extremly bright. I'm pretty sure I did something wrong with the file itself, maybe it contains some special code. I thought it is just ascii, but my Geany-Editor encodes it with ISO-8859-1. So I guess I need to convert from Latin1 to ascii or something else.

    Here is a example from the beginning of the file:

    ÷=!<qÜáßåçëçìñîîìïñîòöñöø� �ÿúùüøýüûýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ùÿúôæêèçÜÙØ×ØÔÒÍÉÁÈÅÇËÈÃ� �ÄÂÁÂÂÅÈÍÏÑÈÇÅÇÍÑÓÓÏÒ×ÙÖÚ� �àâáâáäÜåçèíîîòóöÿÿûÿÿÿýû� �ÿÿÿÿÿÿÿÿÿÿÿÿÿ

    Hope someone got a hint for me to set the display correct, so that I could finish this stuff.

    Best reagrds,

    Olli

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

      Whats the supposed format of the image file?

      [quote author="xxxOllixxx" date="1386067526"]
      int j=0; //image manipulation procedure
      for(int y=0;y<image.height();y++){
      for(int x=0;x<image.width();x++){image.setPixel(x,y,ba.at( j)+128); j++;}}
      // I add +128 because the image file give me values from -128...127
      [/quote]
      Whats the exact purpose of this routine?!

      [quote author="xxxOllixxx" date="1386067526"]
      So like I said most of it works, but it displays half of the image in a very dark colors and some other parts looking extremly bright. I'm pretty sure I did something wrong with the file itself, maybe it contains some special code. I thought it is just ascii, but my Geany-Editor encodes it with ISO-8859-1. So I guess I need to convert from Latin1 to ascii or something else.
      [/quote]
      you don't need to worry about encodings. Since you are anyway interested in the binary data. The encodings are interesting for string representation (like when you open it in an text editor like you did).

      --- 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
      • X Offline
        X Offline
        xxxOllixxx
        wrote on last edited by
        #3

        The image file is a Raw-format, but it contains only pixels. The routine you remarked, is for setting the pixel data from the bytearray to a QImage...pixel by pixel.
        Sure I'm interested in the binary data, but where is still something wrong. The contour of the image is correct, the color of the pixel dosnt match. It is much to bright or much to dark.

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

          and the format of the raw image data is really equivalent to QImage::Format_Indexed8 ?

          --- 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
          • X Offline
            X Offline
            xxxOllixxx
            wrote on last edited by
            #5

            I'm not totally sure. But the image contains only values between -128...127 and the Format_Indexed8 is the only format with 8 Bit, so I just used it.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xxxOllixxx
              wrote on last edited by
              #6

              f.ex. Infranviewer can read the file... 8 bit grayscale...0 header bits

              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