LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2004, 09:21 AM   #1
martin426
LQ Newbie
 
Registered: Nov 2003
Posts: 4

Rep: Reputation: 0
Question regarding 5551 files and OpenGL(?)


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.

Thanks for any help!
 
Old 06-10-2004, 10:28 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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...


Last edited by deiussum; 06-10-2004 at 10:32 AM.
 
Old 06-10-2004, 10:39 AM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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....
 
Old 06-10-2004, 11:10 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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...

Anyway, here's the code:
Code:
/*
 * Compile with:
       gcc from5551.c -o from5551

       or

       gcc from5551.c -o from5551 -DLITTLE_ENDIAN
 */

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

/*
** Convert a 5551 image into rgb format
*/
main(argc,argv)
int argc;
char **argv;
{
    FILE *input;
    FILE *output;
    int x, y, xsize, ysize;
    unsigned short* img;
    unsigned char rgb[3];

    if( argc != 5 ) {
        fprintf(stderr,
                "usage: %s inimage.5551 outimage.rgb xsize ysize\n", argv[0]);
        exit(1);
    }
    if((input=fopen(argv[1],"rb")) == NULL ) {
        fprintf(stderr,"%s: can't open input file %s\n", argv[0], argv[1]);
        exit(1);
    }
    if ((output = fopen(argv[2], "wb")) == 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]);
    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);

    #ifdef LITTLE_ENDIAN
    for (y=0;y<ysize;y++)
    {
		for (x=0;x<xsize;x++)
		{
			img[y*xsize+x] = ((img[y*xsize+x] & 0xFF00) >> 8) |
							 ((img[y*xsize+x] & 0x00FF) << 8);
		}
	}
    #endif

    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;
            rgb[0] = (r5<<3)|(r5>>2);
            rgb[1] = (g5<<3)|(g5>>2);
            rgb[2] = (b5<<3)|(b5>>2);

            fwrite(rgb, 3, 1, output);
        }
    }
    fclose(output);

    return 0;
}

Last edited by deiussum; 06-10-2004 at 11:11 AM.
 
Old 06-10-2004, 02:19 PM   #5
martin426
LQ Newbie
 
Registered: Nov 2003
Posts: 4

Original Poster
Rep: Reputation: 0
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.

The images I'm hoping to work with can be found here: http://www.andesengineering.com/BlueMarbleViewer/

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.
 
Old 06-11-2004, 08:13 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zoom 5551 x4 internet over usb attila_66 Linux - Networking 1 10-26-2005 11:02 AM
OpenGL Header Files daclam Linux - Software 2 08-07-2004 10:01 PM
load dxf files opengl adhara Programming 1 05-12-2004 07:11 AM
Zoom Telephonics ADSL 5551 with Linux star2a Linux - Networking 0 10-08-2003 10:52 AM
openGL files for Linux rhicks Linux - Software 0 06-23-2002 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration