WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-03-2005, 12:53 PM
vmerget vmerget is offline
Member
 
Join Date: Mar 2005
Posts: 3
Checking the settings of the graphics card was the first thing
I checked. Unless I missed something, it's 32 bits. I also tried
a JPEG that I created in Photoshop -- an RGB image that
"just happened" to have R == G == B for all pixels --- and it
displayed a full range of greys. I looked very closely at the
screen, just to see if it were dithering 16 grays to create the
illusion of ~256 grays, and I don't believe it was.

I'll probably try creating the image as a true grayscale as an
experiment later, just to see if the result changes. I didn't
do so originally because I wanted the flexibility of being able
to write a colored image, even if the image was currently
greyscale. In particular, I might want to have a key that
adds some colored dots or squares at key points on the
mage. (Basically, the plugin enables you to dynamically
update the texture from a Python string containing a grayscale
or RGBA image in SGI format.

Here's the code that creates the image:

void InitImageGen(void *imagegen)
{
VizImageGenObj *self =
reinterpret_cast<VizImageGenObj*>(imagegen);

strcpy(self->version, "strtexture v1.0");
self->user[0] = 0;
self->dataSize = 0;


int imageWidth = nearbyPowerOf2(self->x);
int imageHeight = nearbyPowerOf2(self->y);
if (imageWidth <= 0 || imageHeight <= 0) {
imageWidth = 256;
imageHeight = 256;
}

osg::Image *image = new osg::Image;
image->setImage(imageWidth, imageHeight, 1, 4,
GL_RGBA, GL_UNSIGNED_BYTE,
new uchar[imageWidth * imageHeight * 4],
osg::Image::USE_NEW_DELETE);
clearImage(image);
self->image = image;
self->texture = new osg::Texture2D(image);
CommandImageGen(self);

self->status = 1;
}

And here's the shortest routine I use to write fill the image:

void clearImage(osg::Image *image, uchar red = 0,
uchar green = 0, uchar blue = 0,
uchar alpha = 255)
{
for (int ii = 0; ii < image->s(); ii++) {
for(int jj = 0; jj < image->t(); jj++) {
uchar *pixel = image->data(ii, jj);
pixel[0] = red;
pixel[1] = green;
pixel[2] = blue;
pixel[3] = alpha;
}
}
image->dirty();
}
__________________
-- Dan Merget
Reply With Quote
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:43 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC