Have you looked at Boost::GIL (Generic Image Library) originally developed by Adobe?
From: Diego Sánchez [mailto:dsd...@gmail.com]
Sent: Thursday, December 05, 2013 3:00 PM
To: grap...@isocpp.org
Subject: [graphics] Low level graphics
Hi,
Even if this group is about a GUI Lite for C++, I believe this is the best place to present an idea about having a low level infrastructure for dealing with images.
.
I find it is best to separate a Color from a Pixel.
A Pixel has a particular format for a particular device/hardware/platform/etc.
A Color is a color is a colour. A higher level concept independent of low level pixel stuff. And a Color can pass between pixel formats.
Tony
From: Alex B [mailto:deva...@gmail.com]
Sent: Thursday, December 05, 2013 4:26 PM
To: grap...@isocpp.org
--
You received this message because you are subscribed to the Google Groups "Graphics" group.
To unsubscribe from this group and stop receiving emails from it, send an email to graphics+u...@isocpp.org.
To post to this group, send email to grap...@isocpp.org.
Visit this group at
http://groups.google.com/a/isocpp.org/group/graphics/.
To view this discussion on the web visit
https://groups.google.com/a/isocpp.org/d/msgid/graphics/e6aea83a-8684-48bf-877e-d0fefc0396d3%40isocpp.org.
--
You received this message because you are subscribed to a topic in the Google Groups "Graphics" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/graphics/3-F4r_r_9mg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to graphics+u...@isocpp.org.
To post to this group, send email to grap...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/graphics/.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/graphics/11B5438424E807459A28BD01C92339BA756238ED%40XMB122CNC.rim.net.
I don't understand the difference you make between colors and pixels. What does a pixel contains appart from a color?In 3D graphics, we can think about depth values and such. But when you talk about "pixel formats", I don't see why it wouldn't apply to colors as well.
A pixel is typically a specific representation of a color. And it changes per platform or even per graphics card or per application or per problem-at-hand (I might need HDR floating point pixels here in the app, but only need black-and-white pixels there in the app).
Yet it is useful that a single app with a multitude of pixel formats, only has one Color type. Typically the Color type is the highest resolution one. It can serve as the interop between various formats, and between higher level constructs, like what color pen to draw with - the pen color doesn't need to know the underlying pixel format.
Now, in theory, you could have an any-pixel-format Image class with an iterator that dealt with Color values, but in reality the per-pixel conversion kills you.
You can get pretty far with templatized (on pixel format) image processing functions, that, in the default, non-specialized case, deals with Color values. But has specializations for all the important cases. ie
template<typename PixelFormat1, typename PixelFormat2>
composite_onto(PixelBuffer < PixelFormat1> bottomDest, PixelBuffer <PixelFormat2> topSource)
{
PixelFormat1::pixelPtr dst = ...;
PixelFormat2::pixelPtr src = ...;
for each pixel...
*dst = composite(*dst, *src);
}
Then specialize composite() for important combinations of formats - in particular (RGBA, RGBA).
The non-specialized composite() takes two Color values. This is the generic case. But that means some conversion probably takes place.
There are even ways to have multiple levels of conversion - ie RGB -> RGBA -> Color. So that the RGB format *only* supplies a RGB -> RGBA conversion, and doesn't worry about the Color conversion. (But you can't then use straight compiler-supplied overload resolution to get fine grained ordering. I actually forget how we got more custom ordering...)
You typically don't specialize at the single-pixel-function level. It is better to specialize at the 1D or 2D level. (ie 1D means for each scanline or run.)
But the single-pixel function is the fall back default.
So you can end up with a non-templatized Image class that contains a runtime pixelFormat member. You then switch(pixelFormat) at the image or scanline level, calling the templatized functions. It is OK to do a switch on pixel-format once per image or even once per line. Just not every pixel!
switch (pixelFormat)
{
case RGBA:
composite_onto<RGBA, RGBA>(image1->data(), image2->data());
etc
Or something like that. The details are fuzzy, sorry - I've worked on libraries like this 3 or 4 times now at various companies. But I've forgotten or blended together too many details. Overall, the design should work even better with C++11 I think.
(By the way, someone asked a while back if there were any image experts on the list. I didn't pipe up because I still don't consider myself an expert, but I've worked with pixels for about 20 years, mostly in film/tv graphics, including ~10 years at Adobe, which lives and dies over pixels. But I was also doing UI/threading/architecture/everything..., and leaving the very gritty pixel details to the asm guys. So I still won't call myself an expert...)
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/graphics/CALX6VwpiQKRE-N7%3DN8P%2BM-8uQz0ySnFVttbmCN1wvLMVkJjaqQ%40mail.gmail.com.
A pixel usually is composed of a color and an alpha, but you may want to add more channels to hold whatever info is needed for the task at hand. In 3D graphics is when "pixels" may hold things like Z value, G channels; and texels ( texture pixels ) contain a lot of info about the surface (normal maps, specularity, ... ). So an image may contain much more info than mere colours.
My motivation here is that C++ would benefit from having an standard representation of images that's close to the lower levels. It would provide a common ground for interoperability; and my experience is that it is much easier to interface a library that uses raw values than those that provide "advanced" color classes for individual pixels. Also, C libraries tend to use raw buffers, which could be directly mapped into a container like the one I described.
Are all platforms 0xRRGGBBAA now? Including cell phones?
And doesn't Windows still have bitmaps starting at the bottom instead of the top?
From: Diego Sánchez [mailto:dsd...@gmail.com]
Sent: Monday, December 09, 2013 6:53 PM
To: grap...@isocpp.org
Cc: jason zink
Subject: Re: [graphics] Re: Low level graphics
Well, interfacing libraries (including what's being done by this group) is what motivated me in the first place. Almost every library/environment out there understands a buffer in the 0xRRGGBBAA format, with lines starting at the top left corner and providing for line stride. This specifically includes Cairo.
On looking to confirm what would be the best common ground, I've done a quick search on the websites of OpenGL, Cairo, Qt and Microsoft Windows and was surprised to find out that the packed pixel formats (RGB 565 and the like) are still widely supported. If memory serves well, last time I used one of those was some ten years ago on a Windows CE device. Can anyone provide examples of it's use nowadays?
Besides, are we sure it's 0xRRGGBBAA? As far as I'm aware the notion of RGBA (at least in the little endian world) is to have the red value being the lower byte, which in C++ code would translate to 0xAABBGGRR. Some platforms prefer BGRA, which in C++ notation (on little endian) would still be written as 0xAARRGGBB.
> Guarantee that the underlying bits and bytes conform to a sequence of pixels organized in row major order, starting at the upper left corner (providing for line strides).Let's not forget that a 2D array is not all that low-level, either.