[Interest] QImage::Format_Grayscale8 work working

Jason H jhihn at gmx.com
Fri Mar 16 13:08:41 CET 2018


> 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
> >
> 
>



More information about the Interest mailing list