#include "prefix.h"
#include "sys_types.h"
#include "jpeglib.h"
#include "jmemsrc.h"
UInt32 JpegDecompressCallback( unsigned char* buf, UInt32 size );
struct jpeg_decompress_struct gJpegDecompressInfo;
struct jpeg_error_mgr gJpegErrorMgr;
//-----------------------------------------------------------------------------
// Name : Decode
// Parameters : jpeg file
// Return :
// Description :
//-----------------------------------------------------------------------------
BitmapType* CJpegDecoder::Decode( MemHandle JpegH )
{
JSAMPROW row_pointer[ 1 ];
UInt8* row;
UInt8* ustrDecompressedRow = ( UInt8* )MemPtrNew( 640 * 3 );
Int16 intX;
RGBColorType RGBColor;
// Create the error object
gJpegDecompressInfo.err = jpeg_std_error( &gJpegErrorMgr );
// Create the decompress object
jpeg_CreateDecompress( &gJpegDecompressInfo, JPEG_LIB_VERSION,
( size_t )sizeof(struct jpeg_decompress_struct ) );
// Specify the JPEG source call back
jpeg_mem_src( &gJpegDecompressInfo, JpegDecompressCallback );
UInt32 dwLength = MemHandleSize( JpegH );
gJpegDecompressInfo.src->next_input_byte = ( JOCTET*
)gJpegDecompressInfo.mem->alloc_large( (j_common_ptr) &gJpegDecompressInfo,
JPOOL_IMAGE, dwLength );
UInt8* arrData = ( UInt8* )MemHandleLock( JpegH );
memcpy( ( void* )gJpegDecompressInfo.src->next_input_byte, arrData, dwLength );
MemHandleUnlock( JpegH );
gJpegDecompressInfo.src->bytes_in_buffer = dwLength;
// Read the JPEG Header
jpeg_read_header( &gJpegDecompressInfo, true );
// Thoses settings are ste by default by jdlib_read_header but it
//is nice to see what we can change
gJpegDecompressInfo.out_color_space = JCS_RGB;
gJpegDecompressInfo.dct_method = JDCT_ISLOW;
gJpegDecompressInfo.do_fancy_upsampling = true;
gJpegDecompressInfo.do_block_smoothing = true;
gJpegDecompressInfo.scale_num = 1;
gJpegDecompressInfo.scale_denom = 1; // Permitted values are: 1, 2, 4
//and 8 for scales of: 1/1, 1/2,
//1/4 and 1/8
gJpegDecompressInfo.buffered_image = false;
jpeg_start_decompress( &gJpegDecompressInfo );
Boolean enableColorP = true;
UInt32 widthP = 160;
UInt32 heightP = 160;
UInt32 depthP = 16;
UInt16 error = 0;
BitmapType* retBitmap = BmpCreate( gJpegDecompressInfo.output_width - 1,
gJpegDecompressInfo.output_height - 1,
16, NULL, &error );
WinHandle wH = WinCreateBitmapWindow( retBitmap, &error );
WinHandle OldH = WinSetDrawWindow( wH );
widthP = gJpegDecompressInfo.output_width - 1;
heightP = gJpegDecompressInfo.output_height - 1;
Int16 intY1 = gJpegDecompressInfo.output_scanline ;
while( gJpegDecompressInfo.output_scanline
< gJpegDecompressInfo.output_height )
{
row_pointer[ 0 ] = ( unsigned char* )ustrDecompressedRow; //rowbuf
// Decompress an output line
jpeg_read_scanlines( &gJpegDecompressInfo, row_pointer, 1 );
row = ( UInt8* )row_pointer[ 0 ];
// Display the decompressed line (example only)
Int16 intX1 = 0;
for( intX = 0; intX < gJpegDecompressInfo.output_width; intX++ )
{
RGBColor.r = row[ intX * 3 ];
RGBColor.g = row[ intX * 3 + 1 ];
RGBColor.b = row[ intX * 3 + 2 ];
WinPushDrawState();
WinSetForeColorRGB( &RGBColor, NULL );
WinDrawPixel( intX1++, intY1 );
WinPopDrawState();
}
intY1++;
};
RectangleType rect;
rect.topLeft.x = 0;
rect.topLeft.y = 0;
rect.extent.x = widthP;
rect.extent.y = heightP;
MemPtrFree( ustrDecompressedRow );
WinDeleteWindow( wH, true );
WinSetDrawWindow( OldH );
jpeg_finish_decompress( &gJpegDecompressInfo );
jpeg_destroy_decompress( &gJpegDecompressInfo );
return retBitmap;
}
UInt32 JpegDecompressCallback( unsigned char* buf, UInt32 size )
{
return size;
}
the sources of jpeg decoder places on
Metrowerks\CodeWarrior\(CodeWarrior Examples)\Palm OS\Handspring SDK
Examples\Imaginator\Src
include next files to your project
jutil.c
jcomapi.c
jdapistd.c
jdcoefct.c
jdcolor.c
jdhuff.c
jddctmgr.c
jdinput.c
jdapimin.c
jdmainct.c
jerror.c
jdsample.c
jmemmgr.c
jdmaster.c
jdmerge.c
jdmarker.c
jdphuff.c
jdpostct.c
jdtrans.c
jfdctfst.c
jfdctint.c
jidctflt.c
jidctfst.c
jidctint.c
jidctred.c
jmempalm.c
jmemsrc.c
prefix.h
jconfig.h
jdct.h
jdhuff.h
jppalmPrv.h
jerror.h
jinclude.h
jmemsrc.h
jmemsys.h
jmorecfg.h
jpegint.h
jpeglib.h
jpeglib_old.h
jversion.h
ZC> Hello!
ZC> I try show JPG images in my application.
ZC> I used jpeglib, but I don't understand to how do I make a file streams
ZC> (JPEG).
ZC> In this page: http://www.nyctergatis.com/jpeglib/ say "Support for JPEG
ZC> data in memory, in file streams (a way to store data in Palm OS
ZC> databases with an API similar to file systems) and in VFS (the virtual
ZC> file system used by Palm OS for memory expansion modules) has been added
ZC> to make the use of the library as easy as possible for Palm OS
ZC> developers."
ZC> How do I make this class file?
ZC> I have a simple .JPG, How do I transform this file in file strams?
ZC> Thanks!
--
Best regards,
tut.by mailto:[EMAIL PROTECTED]
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/