[Qt-interest] how to build a grayscale QImage
Stephen Chu
stephen at ju-ju.com
Mon Feb 22 17:23:10 CET 2010
In article <Pine.LNX.4.64.1002221114160.17226 at calcifer.valdyas.org>,
Boudewijn Rempt <boud at valdyas.org> wrote:
> On Mon, 22 Feb 2010, Dan Milburn wrote:
>
> > > But no QImage constructor take a data pointer and a color table together.
> > > Besides, how can i create a grayscale color table?
> > > should i set a for loop from 1 to 256 and set the current entry of color
> > > table with the current index of the loop?
> > > I get confused with the Format enum. It just supports mono(0-1) and 8bit
> > > indexed; why not a "grayscale" option to make things easier?
> > >
> > Hi,
> >
> > Not that I speak for Nokia, but they can't cover every possible image
> > format, and there probably isn't a great deal of demand for grayscale
> > images these days.
>
> You'd be surprised -- grayscale images are used a lot, for instance
> for masking. When working on krita, we ran into this issue only last week:
> we wanted to use QImage, but since you cannot paint on an indexed image,
> we had to cook up our own solution.
>
> >
> > Besides, generating a grayscale color table is really not difficult to do:
> >
> > QVector<QRgb> table( 256 );
> > for( int i = 0; i < 256; ++i )
> > {
> > table[i] = qRgb( i, i, i );
> > }
> >
> > None of the QImage constructors take this, but you can set it on the
> > image immediately afterwards.
>
> The big problem with indexed images is that you cannot use QPainter
> on them.
>
> Boudewijn
The lacking of grayscale image support is a big surprise to me, too.
Like you, I need painting onto a grayscale image and am still working on
how to overcome the problem.
I am also having problem with using an 8-bit image as a mask for drawing
operations. Qt seems to support only 1-bit region as clipping whereas I
need to use 8-bit alpha channel for arbitrary drawing.
--
Stephen Chu
More information about the Qt-interest-old
mailing list