[Interest] QImage::Format_Grayscale8 work working

Nikolai Tasev nikolai at nand.bg
Fri Mar 16 15:05:32 CET 2018


I just looked the source code of setPixel() for Grayscale8. It 
seems(there is a pixel converter, that needs more time to see in detail) 
that for Grayscale8 you are supposed to give a 32 bit not an index like 
in Indexed8. That is for white give FFFFFFFF, instead of 
000000FF(returned currently from qRed(), qBlue()...).

On 3/16/2018 3:52 PM, Nikolai Tasev wrote:
> I am not sure if there any difference in how the Indexed8 and 
> Grayscale8 are saved. It also depends on the
> file format. As far as I remember many formats always save as 32bits.
>
> First look at the pixel data as raw unsigned char values to see if the 
> conversion is correct, maybe the problem comes
> later when saving. Then you can also try with some small synthetic 
> images for specialized tests.
>
> Grayscale8 is a most recent development is there any chance that you 
> use a newer header and older library?
>
> On 3/16/2018 3:14 PM, Jason H wrote:
>> It returns black. All black. Hence the issue :-)
>> The original file is an 8MP 4:3 image as png it saves to ~10mb.
>> - as a Grayscale8 it saves as 8 KB-kilo. (should be 8,121,344)
>> - as Indexed8 it saves as 5.5mb
>>
>> I'd expect Greyscale8 to be about the same size on disk as Indexed8 
>> +/- color table.
>>
>>> Sent: Friday, March 16, 2018 at 8:38 AM
>>> From: "Nikolai Tasev" <nikolai at nand.bg>
>>> To: "Jason H" <jhihn at gmx.com>
>>> Cc: "Interestqt-project.org" <Interest at qt-project.org>
>>> Subject: Re: [Interest] QImage::Format_Grayscale8 work working
>>>
>>> What is not working for Grayscale? Looking at the code it will do
>>> different things when you are passing Qt::red, Qt::blue, Qt::green.
>>> It will not return a color image but a grayscale image of the
>>> corresponding channel.
>>>
>>> On 3/16/2018 2:08 PM, Jason H wrote:
>>>>> Sent: Friday, March 16, 2018 at 9:12 AM
>>>>> From: "Nikolai Tasev" <nikolai at nand.bg>
>>>>> To: "Jason H" <jhihn at gmx.com>, "Interestqt-project.org" 
>>>>> <Interest at qt-project.org>
>>>>> Subject: Re: [Interest] QImage::Format_Grayscale8 work working
>>>>>
>>>>>
>>>>> Format_Indexed8 and Format_Grayscale8 both have 8bit per pixel. The
>>>>> difference is that to convert from the 8bit pixel to RGB values
>>>>> (QImage::pixel() method)
>>>>> for Indexed8u you need to set the Palette for conversion and for
>>>>> Grayscale8 you don't (it just assumes that R=G=B=gray value)
>>>> I am aware of that.
>>>>
>>>>> Are you trying to extract a channel from a multichannel image and 
>>>>> put it
>>>>> into a grayscale image? The code seems unnecessary complex
>>>>> and inefficient for such a task. You just need to get the data 
>>>>> pointer
>>>>> and skip the uneeded channels and keep watch for the end of the row.
>>>> That assumes I be want to do the math for every Format. ARGB is 
>>>> easy, RGB888 is not, etc. Pixel() alerts need to not care. Yes, I 
>>>> could use scan lines, but then each format requires code. Which I 
>>>> haven't got time to write now.
>>>>
>>>> Anyway, I be still believe my code is correct, and it's still not 
>>>> working.
>>>>
>>>>> On 3/15/2018 10:21 PM, Jason H wrote:
>>>>>> Given the following functions, I should be able to create a 
>>>>>> non-all black image (assuming input is good)? The only success I 
>>>>>> have is using Indexed8
>>>>>>
>>>>>> QHash<QRgb, qint32 (*)(QRgb)> colorFuncs {
>>>>>>     { Qt::red,   qRed},
>>>>>>     { Qt::green, qGreen},
>>>>>>     { Qt::blue,  qBlue},
>>>>>>     { Qt::gray,  qGray},
>>>>>> };
>>>>>>
>>>>>> QImage color8(const QImage &image, int channel) { // Channel is 
>>>>>> one of Qt::red Qt::green Qt::blue or Qt::gray
>>>>>>     QImage out(image.width(), image.height(), 
>>>>>> QImage::Format_Indexed8);  // Change to Format_Grayscale8, and 
>>>>>> get nothing
>>>>>> // for indexed8
>>>>>>     QVector<QRgb> values;
>>>>>>     values.reserve(256);
>>>>>>     if (channel==Qt::gray) { for (int c=0; c<256; c++) 
>>>>>> values.append(qRgb(c,c,c)); }
>>>>>>     if (channel==Qt::red)  { for (int c=0; c<256; c++) 
>>>>>> values.append(qRgb(c,0,0)); }
>>>>>>     if (channel==Qt::green){ for (int c=0; c<256; c++) 
>>>>>> values.append(qRgb(0,c,0)); }
>>>>>>     if (channel==Qt::blue) { for (int c=0; c<256; c++) 
>>>>>> values.append(qRgb(0,0,c)); }
>>>>>>     out.setColorTable(values);
>>>>>> // end for indexed8
>>>>>>
>>>>>>     int (*colorFunc)(QRgb rgb) = colorFuncs[channel];
>>>>>>     for (int y=0; y < image.height(); y++) {
>>>>>>         for (int x=0; x < image.width(); x++) {
>>>>>>             out.setPixel(x,y, colorFunc(image.pixel(x,y)));
>>>>>>         }
>>>>>>     }
>>>>>>
>>>>>>     return out;
>>>>>> }
>>>>>>
>>>>>> I'm not familar with Qt and Grayscale8... Anyone know what is 
>>>>>> going wrong?
>>>>>> _______________________________________________
>>>>>> Interest mailing list
>>>>>> Interest at qt-project.org
>>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>>>
>>>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>




More information about the Interest mailing list