Ok, here's a better version with the alphas {0, 1, 2, 4, 8, 16, 32, 64,
128, 255} for the same rgb values {64, 128, 192}.

~> ./catpx pixel10x1.png
0 0 0 0
0 0 0 1
0 127 127 2
63 127 191 4
63 127 191 8
63 127 191 16
63 127 191 32
63 127 191 64
63 127 191 128
64 128 192 255

There seems to be some pre-multiplication as long as alpha != 0.
But every single value should actually be "64 128 192 alpha".

Best.


#include <osgDB/ReadFile>
#include <osg/ref_ptr>
#include <iostream>
#include <cassert>

typedef unsigned char byte;

struct Pixel {
    byte c0;
    byte c1;
    byte c2;
    byte alpha;
};

typedef osg::ref_ptr<osg::Image> ImagePtr;


int main(int n, char** c) {
    if(n == 1) {
        std::cout << "Usage: " << c[0] << " image.png" << std::endl;
        return 0;
    }

    const ImagePtr img(osgDB::readImageFile(c[1]));

    if(img == 0) {
        std::cout << "Failed to load: " << c[1] << std::endl;
        return 1;
    }

    const GLenum pxf(img->getPixelFormat());

    if(not (pxf == GL_RGBA or pxf == GL_BGRA)) {
        std::cout << "Image must be RGBA or BGRA, found: "
                  << pxf << std::endl;
        return 1;
    }

    const Pixel* px(reinterpret_cast<const Pixel*>(img->data()));
    const unsigned N(img->s() * img->t());

    for(unsigned i(0); i != N; ++i, ++px)
        std::cout   << unsigned(px->c0) << ' '
                    << unsigned(px->c1) << ' '
                    << unsigned(px->c2) << ' '
                    << unsigned(px->alpha) << std::endl;

    return 0;
}

<<attachment: pixel10x1.png>>

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to