Visit Our UNIX and Linux User Community


How to Decode an image using openGL


 
Thread Tools Search this Thread
Top Forums Programming How to Decode an image using openGL
# 1  
Old 11-03-2009
Java How to Decode an image using openGL

Hi,

How to decode an image using openGL library libjpeg ..
which are the steps needed to do this using C language..
actually my work is to decode the image, store it on the buffer,
and place it on cube surface..

please guide me,,any answer will appreciated ..
# 2  
Old 11-03-2009
Here is one way of finding source code examples of how to use libjpeg to decode a JPEG image.
# 3  
Old 11-04-2009
Java how to display, after decoding an image in openGL

Hi,

Thank you so much for your help.. it helps me a lot..
as i am new to openGL. i dont know whether it is a basic question which i am asking know.
the question is :

The program jpeg_sample.c which is there in tar file is executing with out any error ..
i think decompression is done well ,,
but its not displaying any JPEG image after execution ...

Could you tell how to display jpeg image after decoding in openGL

and i am not getting from where it is taking an jpeg image in that code ..

Please guide me , any answer will appreciated..
# 4  
Old 11-04-2009
We cannot see the source code from here.
# 5  
Old 11-05-2009
Quote:
Could you tell how to display jpeg image after decoding in openGL
Given that you do not appear to much experience with the concept of textures in OpenGL, maybe you should use an image library such as DevIL.

Here is a tutorial on DevIL. It includes an example of how to load and display a JPEG using OpenGL.
# 6  
Old 11-05-2009
Java how to display, after decoding an image in openGL

Hi,

The source code is:

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


unsigned char *raw_image = NULL;

int width = 2000;
int height = 1300;
int bytes_per_pixel = 3;
int color_space = JCS_RGB;



int read_jpeg_file( char *filename )
{

struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;



JSAMPROW row_pointer[1];

FILE *infile = fopen( filename, "rb" );
unsigned long location = 0;
int i = 0;

if ( !infile )
{
printf("Error opening jpeg file %s\n!", filename );
return -1;
}

cinfo.err = jpeg_std_error( &jerr );

jpeg_create_decompress( &cinfo );

jpeg_stdio_src( &cinfo, infile );

jpeg_read_header( &cinfo, TRUE );


printf( "JPEG File Information: \n" );
printf( "Image width and height: %d pixels and %d pixels.\n", cinfo.image_width, cinfo.image_height );
printf( "Color components per pixel: %d.\n", cinfo.num_components );
printf( "Color space: %d.\n", cinfo.jpeg_color_space );


jpeg_start_decompress( &cinfo );


raw_image = (unsigned char*)malloc( cinfo.output_width*cinfo.output_height*cinfo.num_components );

row_pointer[0] = (unsigned char *)malloc( cinfo.output_width*cinfo.num_components );

while( cinfo.output_scanline < cinfo.image_height )
{
jpeg_read_scanlines( &cinfo, row_pointer, 1 );
for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
raw_image[location++] = row_pointer[0][i];
}

jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo );
free( row_pointer[0] );
fclose( infile );

return 1;
}


int write_jpeg_file( char *filename )
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;


JSAMPROW row_pointer[1];
FILE *outfile = fopen( filename, "wb" );

if ( !outfile )
{
printf("Error opening output jpeg file %s\n!", filename );
return -1;
}
cinfo.err = jpeg_std_error( &jerr );
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);


cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = bytes_per_pixel;
cinfo.in_color_space = color_space;

jpeg_set_defaults( &cinfo );

jpeg_start_compress( &cinfo, TRUE );

while( cinfo.next_scanline < cinfo.image_height )
{
row_pointer[0] = &raw_image[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
}

jpeg_finish_compress( &cinfo );
jpeg_destroy_compress( &cinfo );
fclose( outfile );

return 1;
}

int main()
{
char *infilename = "rro1.bmp", *outfilename = "rr.jpg";



if( read_jpeg_file( infilename ) > 0 )
{

if( write_jpeg_file( outfilename ) < 0 ) return -1;
}
else return -1;



return 0;
}



This code is working without any error message. but Displayed image is not decompressed .. Image is not a clear picture after decompressed ..
i need to display a decompressed JPEG image at the out put..

Please help me out with this problem,,,any answer will appreciated ..
# 7  
Old 11-11-2009
Java How to insert JPEGs on each side of the cylinder using openGL

Hi,

Sorry for late reply , i got the result of decompressed image, but now i need to insert images on Cylinder surfaces.

Please Help me out ...answer will appreciated ...

Previous Thread | Next Thread
Test Your Knowledge in Computers #695
Difficulty: Easy
The Cathedral and the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary (abbreviated CatB) is an essay, and later a book, written by Alfred Hitchcock on software engineering methods.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Difference between opengl es and directfb

i dont know in which forum to ask this question ..... :( . pardon me if it is not this forum i wanted to know difference between openGL ES and directfb as far i know directfb is alternative to x11 in linux for embedded devices. something like ... application | ... (1 Reply)
Discussion started by: alexzander18
1 Replies

2. Solaris

Solaris 8 and openGL

Hi everybody, Sorry to bother you one more time, but I have a problem with my Solaris 8 installation. Actually, Solaris works well, I can start X and access my desktop (CDE), but I'm having troubles using Cadds (a CAO software). Cadds works, but the 3D visualization is very slow compare to... (4 Replies)
Discussion started by: firstpost
4 Replies

3. Shell Programming and Scripting

matching image files to create one image

Hi, I have two sets of image files. Both sets have names A to Z but set 1 ends with .cdt.png and set 2 ends with .matrix.png. I want set 1 to match with set 2 if the names match (i.e. A.cdt.png will match with A.matrix.png) and with the convert image tool (program for images), it will merge the... (6 Replies)
Discussion started by: kylle345
6 Replies

4. Programming

How to install openGL packages?

Hi, Any one help me regarding how to install openGL packages to work in linux. And i installed some of the packages(gl,glu), but i don't know whether they are installed are not .. Which command is should use to check whether openGL is installed are not .. I am Thankful for any kind of... (3 Replies)
Discussion started by: Ravikishore
3 Replies

5. Programming

Draw a 3D cylinder using openGL.

Hi, please give me, how to code to draw 3D cylinder in openGL, that should be rotated in x-direction. waiting for your reply .. (2 Replies)
Discussion started by: Ravikishore
2 Replies

6. Ubuntu

How to draw cylinder using openGL

Hi Sir, i am new to openGL, i want to know how to draw cylinder using openGL code in C or C++.. And i have to insert bitmap images on cylinder.. How to do this .. please guide me ... Thanking You in advance .. (0 Replies)
Discussion started by: Ravikishore
0 Replies

7. Ubuntu

i am new to opengl , how to work opengl in ubuntu

Hi, i am new to opengl, how to work openGL in ubuntu ,, i am not getting which packages as to be install and how to install those packages. and how to work with small programs.. Please guide me ,,, it will appriceated ... (7 Replies)
Discussion started by: Ravikishore
7 Replies

8. AIX

Need to install opengl for GXT4500.

Hi, I try to install opengl bat it give a error that i need the opengl base level fileset 5.3.0.0 I use AIX 5.3 and my oslevel is now 5300-03. Where can i find the opengl files i need (5.3.0.0)? Thanks Peter. (1 Reply)
Discussion started by: xeonbb
1 Replies

9. UNIX for Advanced & Expert Users

Create an Ignite image on tape from Online IgniteUX image

Hi, (HP-UX 11.11) I need to create a tape image of an igniteUX image created on our igniteUX server. That is to say. I have a "Online" image of the igniteUX of the targeted system but I now need to copy it to a useable TAPE (igniteUX) image so i can build an other server from it that is not... (3 Replies)
Discussion started by: Andrek
3 Replies

10. Linux

Help with OpenGL in Fedora Core 4.

I'm pretty much new to this Linux stuff, I installed FC4 the other night to try it out. I'm having a slight problem when launching Quake 3, it's giving me the error GLimp_Init() - could not load OpenGL subsystem I've updated my video drivers to the latest version and went through fglrxconfig,... (3 Replies)
Discussion started by: Filth Pig
3 Replies

Featured Tech Videos