Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading SGI format image files

0 views
Skip to first unread message

Ben Cain

unread,
Oct 21, 1997, 3:00:00 AM10/21/97
to

Resent-Date: Tue, 21 Oct 1997 05:23:06 -0400 (EDT)
Date: Mon, 20 Oct 1997 02:21:00 GMT
Message-ID: <344AC0...@aegisrc.com>
Content-Type: multipart/mixed; boundary="------------167E2781446B"
Sender: xpert-...@opengroup.org
Resent-Message-ID: <"4UeFG4FemNH.A.N2G.DsGT0"@postman.opengroup.org>
X-Mailing-List: xpert:archive/latest/6291
X-Loop: xp...@opengroup.org
Precedence: list
Resent-Sender: xpert-...@opengroup.org

This is a multi-part message in MIME format.

--------------167E2781446B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

I'm developing an application that needs to be able to read SGI image
files in the following formats:

RGB (e.g. filename.rgb)
RGBA (e.g. filename.rgba)
LUMINANCE (e.g. filename.int)
LUMINANCE_ALPHA (e.g. filename.inta)

I tried using the SGI library '-limage' (image.h). But, it doesn't
seem to be properly reading image files other than RGB format. For
example, when I read an RGBA format file, all of the alpha components
are set to zero. Attached, you'll find an example program that uses
this library. As you'll notice in the program's snippet of output
below, -limage is able to recognize the number of channels for the
image files ... just not able to read the image data.

>> scanImage Texture/ash.rgba
Image (x size): 64
Image (y size): 128
Image (# channels): 4
Image pixel min: 0
Image pixel max: 255
This is a RGBA image.
row 0: 255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255
255 0|255 255 255 0|255 255 255 0|255 255 255 0|255 255 255 0|
...

Are there other libraries that I could be taking advantage of that
come with the SGI IDO distribution?

If not, is there free source code for doing this?

If not, would someone direct me to the file format documentation?

Thanks,

Benjamin R. Cain Ph: (205)876-4536/842-6912
Software Engineer Fax: (205)876-7165
AEgis Research Corp. http://www.aegisrc.com
Huntsville, AL bc...@aegisrc.com

--------------167E2781446B
Content-Type: text/plain; charset=us-ascii; name="scanImage.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="scanImage.cpp"

/*************************************************************************************
** Filename : scanImage.cpp
** UNCLASSIFIED
**
** Description : Reads an SGI image file and prints header information and
** pixel values.
**
** To compile: CC -o scanImage scanImage.cpp -limage
**
** Revision History:
** Date Name Description
** 10/19/97 B_Cain Initial Release
**
*************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <GL/image.h>

int main(int argc, char **argv)
{
IMAGE *image;
int i, j;
unsigned short *rbuf, *gbuf, *bbuf, *abuf;

/* Print usage message. */
if(argc < 2)
{
fprintf(stderr,"usage: readimage infile\n");
exit(1);
}

/* Open the image file. */
if( (image=iopen(argv[1],"r")) == NULL )
{
fprintf(stderr,"readimage: can't open input file %s",argv[1]);
exit(1);
}

/* Print a little info about the image. */
printf("Image x and y size in pixels: %d %d\n", image->xsize,image->ysize);
printf("Image zsize in channels: %d\n", image->zsize);
printf("Image pixel min and max: %d %d\n", image->min,image->max);

/* Allocate buffers for image data. */
rbuf = (unsigned short *)malloc(image->xsize*sizeof(short));
gbuf = (unsigned short *)malloc(image->xsize*sizeof(short));
bbuf = (unsigned short *)malloc(image->xsize*sizeof(short));
abuf = (unsigned short *)malloc(image->xsize*sizeof(short));

/* How man channels? */
switch(image->zsize)
{

case 1:
printf("This is a LUMINANCE image.\n");
for(j=0; j<image->ysize; j++)
{
getrow(image,rbuf,j,0);
printf("row %d: ",j);
for(i=0; i<image->xsize; i++)
printf("%d |",rbuf[i]);
printf("\n");
}
break;

case 2:
printf("This is a LUMINANCE-ALPHA image.\n");
for(j=0; j<image->ysize; j++)
{
getrow(image,rbuf,j,0);
getrow(image,gbuf,j,1);
printf("row %d: ",j);
for(i=0; i<image->xsize; i++)
printf("%d %d |",rbuf[i],gbuf[i]);
printf("\n");
}
break;

case 3:
printf("This is a RGB image.\n");
for(j=0; j<image->ysize; j++)
{
getrow(image,rbuf,j,0);
getrow(image,gbuf,j,1);
getrow(image,bbuf,j,2);
printf("row %d: ",j);
for(i=0; i<image->xsize; i++)
printf("%d %d %d |",rbuf[i],gbuf[i],bbuf[i]);
printf("\n");
}
break;

case 4:
printf("This is a RGBA image.\n");
for(j=0; j<image->ysize; j++)
{
getrow(image,rbuf,j,0);
getrow(image,gbuf,j,1);
getrow(image,bbuf,j,2);
printf("row %d: ",j);
for(i=0; i<image->xsize; i++)
printf("%d %d %d %d|",rbuf[i],gbuf[i],bbuf[i],abuf[i]);
printf("\n");
}
break;
}

return 0;
}

--------------167E2781446B--


~Phoenix~

unread,
Oct 23, 1997, 3:00:00 AM10/23/97
to

Resent-Date: Wed, 22 Oct 1997 22:11:59 -0400 (EDT)
Date: 22 Oct 1997 21:19:34 GMT
Message-ID: <62lql6$l...@catapult.gatech.edu>
Sender: xpert-...@opengroup.org
References: <344AC0...@aegisrc.com>, <344CD9...@aegisrc.com>
Resent-Message-ID: <"0FlPOOoO-oB.A.lGF.auqT0"@postman.opengroup.org>
X-Mailing-List: xpert:archive/latest/6330

X-Loop: xp...@opengroup.org
Precedence: list
Resent-Sender: xpert-...@opengroup.org

Ben Cain (bc...@aegisrc.com) wrote:
: Michael Beasley wrote:
: >
: > In article <344AC0...@aegisrc.com>, bc...@aegisrc.com says...
: > >
: > >Hello,


: > >
: > >I'm developing an application that needs to be able to read SGI image
: > >files in the following formats:
: > >
: > > RGB (e.g. filename.rgb)
: > > RGBA (e.g. filename.rgba)
: > > LUMINANCE (e.g. filename.int)
: > > LUMINANCE_ALPHA (e.g. filename.inta)
: > >
: > >I tried using the SGI library '-limage' (image.h). But, it doesn't
: > >seem to be properly reading image files other than RGB format. For
: > >example, when I read an RGBA format file, all of the alpha components
: > >are set to zero. Attached, you'll find an example program that uses
: > >this library. As you'll notice in the program's snippet of output
: > >below, -limage is able to recognize the number of channels for the
: > >image files ... just not able to read the image data.

: > >
: >
: > <<<SNIP>>>
: >
: > >
: > > case 4:


: > > printf("This is a RGBA image.\n");
: > > for(j=0; j<image->ysize; j++)
: > > {
: > > getrow(image,rbuf,j,0);
: > > getrow(image,gbuf,j,1);
: > > getrow(image,bbuf,j,2);

: >
: > getrow(image,abuf,j,3); // did you forget to read something
: > // before using it???
: >
: > > printf("row %d: ",j);


: > > for(i=0; i<image->xsize; i++)
: > > printf("%d %d %d %d|",rbuf[i],gbuf[i],bbuf[i],abuf[i]);
: > > printf("\n");
: > > }
: > > break;

: Thanks to those of you who pointed out the error in the example program.
: Unfortunately, the example program is a much shorter representation of
: where the library is actually used in my application. So, the error is
: only in the example program. I'm still having problems with the -limage
: library. The corrected example program is attached.

: Has anyone successfully used the library the way that I'm trying to use
: it? Someone has suggested using the -libgutil library. It might be
: that I'm having an indexing problem as I'm building the texture images.
: That's my hope.

Just an innocent question...
WHY are you using the iamge lib that SGI provides...
its slow as all getup!

In a couple speed-trials I found out that just blasting all the data
to disk was faster than using the image library...
even with rle.

Oh well.
--
Roberto Javier Peon
Georgia Institute of Technology, Atlanta Georgia, 30332
uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt3388b
Internet: gt3...@prism.gatech.edu


0 new messages