[prev in list] [next in list] [prev in thread] [next in thread]
List: gtkmm
Subject: Re: Gdk::Pixbuf create_from_inline
From: Carl Nygard <cjnygard () fast ! net>
Date: 2004-11-24 19:11:20
Message-ID: 1101323480.31006.40.camel () traveler
[Download RAW message or body]
On Wed, 2004-11-24 at 12:14, Andy Ma wrote:
> Hello,
>
> Does anybody have any reference to an example of how to use Gdk::Pixbuf
> create_from_inline or
> Gdk::Pixmap create_from_data or create_from_xpm
>
> I'd like to test it and run a program with inline image data.
>
> If anybody has any examples, it's greatly appreciated.
>
Code initializes Pixbuf from raster image [0-255] via lookup table
(containing real colors) and mask table for setting alpha channel. Also
does rotations in 90deg increments.
void RasterObject::_InitializeImage()
{
Debug dbg(_dbg, "_InitializeImage");
StopWatch timer("Build Pixbuf");
int sz = _data->Size();
guint8* buf = new guint8[4*sz];
guint8* dst = buf;
const unsigned long* lut = _lut.GetLut();
const vector<int>& maskPix = _lut.Mask();
vector<char> mask(256, 255);
for(vector<int>::const_iterator it = maskPix.begin();
it != maskPix.end(); ++it){
mask[*it] = 0;
}
int startIdx, endIdx, rowDelta, colDelta;
int width, height;
dbg[1] << "Angle: " << _angle << endl;
if(roundf(_angle) == 0.0){
for(const unsigned char* src = _data->Buffer();
src != _data->Buffer()+sz; ++src){
*dst++ = (lut[*src] >> 16) & 0xff;
*dst++ = (lut[*src] >> 8) & 0xff;
*dst++ = (lut[*src]) & 0xff;
*dst++ = mask[*src];
}
width = _data->Width();
height = _data->Height();
}else {
if(roundf(_angle) == 270.0) { // 90deg counter-clockwise
startIdx = _data->Width()-1;
endIdx = -1;
rowDelta = -1;
colDelta = _data->Width();
height = _data->Width();
width = _data->Height();
}
if(roundf(_angle) == 180.0) { // upside down
startIdx = ( _data->Width() * _data->Height() ) - 1;
endIdx = -1;
rowDelta = -_data->Width();
colDelta = -1;
width = _data->Width();
height = _data->Height();
}
if(roundf(_angle) == 90.0) { // upside down
startIdx = _data->Width() * (_data->Height()-1);
endIdx = _data->Width() * _data->Height();
rowDelta = 1;
colDelta = -_data->Width();
height = _data->Width();
width = _data->Height();
}
for(int s = startIdx; s != endIdx; s += rowDelta){
for(int idx = s, count = 0; count < width; ++count, idx+=colDelta){
int val = _data->Buffer()[idx];
*dst++ = (lut[val] >> 16) & 0xff;
*dst++ = (lut[val] >> 8) & 0xff;
*dst++ = (lut[val]) & 0xff;
*dst++ = mask[val];
}
}
}
using SigC::slot;
using SigC::bind;
_pix = Gdk::Pixbuf::create_from_data(buf,
Gdk::COLORSPACE_RGB,
true, 8,
width, height, width*4,
slot(&LoaderDataDtor)
);
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic