ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I'm a bit of a newbie when programming in linux, so please bear with me.
I have a collection of 5551 texture image files (.5551) [yes, I had never heard of them before myself]. Very little information is to be found on them, except that they are SGI's format, and I was able to find this short "from5551.c" program:
Code:
/*
* Compile with:
cc from5551.c -o from5551 -limage
*/
#include "gl/image.h"
#include "malloc.h"
unsigned short rbuf[8192];
unsigned short gbuf[8192];
unsigned short bbuf[8192];
unsigned short packed[8192];
/*
** Convert a 5551 image into rgb format
*/
main(argc,argv)
int argc;
char **argv;
{
IMAGE *image;
FILE *input;
int x, y, xsize, ysize;
int z, zsize;
ushort* img;
if( argc != 5 ) {
fprintf(stderr,
"usage: %s inimage.5551 outimage.rgb xsize ysize\n", argv[0]);
exit(1);
}
if((input=fopen(argv[1],"r")) == NULL ) {
fprintf(stderr,"%s: can't open input file %s\n", argv[0], argv[1]);
exit(1);
}
if ((image = iopen(argv[2], "w", 1, 3, atoi(argv[3]), atoi(argv[4]), 3)) == NULL) {
fprintf(stderr,"%s: can't open output file %s\n", argv[0], argv[2]);
exit(2);
}
xsize = atoi(argv[3]);
ysize = atoi(argv[4]);
zsize = 3;
img = (ushort*)malloc(2*xsize*ysize);
if (fread(img, 2, xsize*ysize, input) != xsize*ysize)
{
fprintf(stderr,"%s: couldn't read %d texels from file %s\n",
argv[0], xsize*ysize, argv[1]);
exit(1);
}
fclose(input);
for(y=0; y<ysize; y++)
{
for(x=0;x<xsize;x++)
{
/* [r:15..11][g:10..6][b:5..1][a:0] */
int r5 = (img[y*xsize + x]>>11)&31;
int g5 = (img[y*xsize + x]>>6)&31;
int b5 = (img[y*xsize + x]>>1)&31;
rbuf[x] = (r5<<3)|(r5>>2);
gbuf[x] = (g5<<3)|(g5>>2);
bbuf[x] = (b5<<3)|(b5>>2);
}
putrow(image,rbuf,y,0);
putrow(image,gbuf,y,1);
putrow(image,bbuf,y,2);
}
iclose(image);
exit(0);
}
Naturally, I can't get it to compile, and I believe the main reason is I don't have the file referenced by:
#include "gl/image.h"
From what I can gather, this is part of the OpenGL package, but I'm not certain what I need to get as the OpenGL websites seem very cryptic to me. I guess I just need a little direction on this. I'm using mandrake 10.0 official as a workstation.
Alternatively, if you know of a image manipulation program that handles these files that would be even easier.
That's not a standard OpenGL header, so it's probably one that should have been with the source code you found. (Note also that they use -limage to load some libimage library, not -lGL to load the libGL library...)
OpenGL has no standard functions for loading any image format. You generally have to write your own loader, or find a library that will read the image data into raw RGB data, and use that data with OpenGL.
I'm not familiar with that format myself, but my guess would be that it has something to do with the compressed texture format extensions supported by some video cards...
I just did a quick search on 5551 images and found that it is an image format that uses 2 bytes (16 bits) for each pixel. 5 bits for red, 5 bits for green, 5 bits for blue, and 1 bit for an alpha channel. It seems that it would be fairly trivial to convert this to raw RGB data.
I haven't seen anything indicating if there is any header data included with this image format, though....
Ok, I had a little time, so I took the code you posted, modified it a bit to use only standard C library functions, and added a bit to it. This will take a 5551 file and output it into an RGB file where each 3 bytes represent the RGB value of a single pixel. One thing I'm not sure of is the endian-ness that the code was originally written for. It looks like big-endian (Are SGI machines big-endian?) I added the ability to compile it for little-endian machines like Intel by using the -DLITTLE_ENDIAN define. This will swap the bytes of each ushort.
Maybe tonight if I get bored, I can see if I can write something for you to convert them to TGA files, as the TGA spec is fairly simple. It'd probably help if you'd want to send me a 5551 file as an example...
Wow... That's what I love about Linux--the users. You can post a question that you feel kind of stupid posting, and someone goes way out of their way to help you out. Many thanks.
Probably the smallest collection (4mb - 1.zip) would be ideal for testing, as the 200mb 4.zip extracts to about 1.5+ gigs... Although the application itself is pretty interesting as well.
Glad I could help. Image formats is just one of those things that I find interesting for some reason. I keep meaning to try and clean up a bunch of image loading/processing routines I've written into a more usable library, but never seem to get around to it.
I've got a TGA load/save function written up in a bunch of code somewhere, so it'll be fairly trivial to create an app to convert your images to TGA. Just gotta get the time to do it. I'll take a look at some of those files and see what I can put together for ya. And maybe add a 5551 image loading routine to my library.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.