Sponsored Content
Top Forums Programming How to Decode an image using openGL Post 302368578 by Ravikishore on Thursday 5th of November 2009 05:31:54 AM
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 ..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 10:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy