]> git.saurik.com Git - wxWidgets.git/commitdiff
JPEG and PNG code taken out of image.cpp
authorJulian Smart <julian@anthemion.co.uk>
Tue, 6 Apr 1999 13:44:37 +0000 (13:44 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 6 Apr 1999 13:44:37 +0000 (13:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
samples/image/image.cpp
src/common/image.cpp
src/common/imagjpeg.cpp [new file with mode: 0644]
src/common/imagpng.cpp [new file with mode: 0644]
src/gtk.inc
src/gtk/makefile.unx
src/gtk1/makefile.unx
src/makeg95.env
src/makevc.env
src/motif.inc
src/motif/makefile.unx
src/msw/makefile.b32
src/msw/makefile.g95
src/msw/makefile.twn
src/msw/makefile.vc
src/msw/makefile.wat

index 7b17838bd525c529a2afa16b04103564669444ed..5f215657ad42391a238214237a3019548a20bfc7 100644 (file)
@@ -241,6 +241,14 @@ void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
 
 bool MyApp::OnInit()
 {
+#if wxUSE_LIBPNG
+  wxImage::AddHandler( new wxPNGHandler );
+#endif
+
+#if wxUSE_LIBJPEG
+  wxImage::AddHandler( new wxJPEGHandler );
+#endif
+
   wxFrame *frame = new MyFrame();
   frame->Show( TRUE );
 
index 151ba3b73e7d6406da08e775005c0ea00c7125f8..800e61fa597e862fc84c0a9fceab00719c48f4b9 100644 (file)
 #include "wx/debug.h"
 #include "wx/log.h"
 #include "wx/app.h"
-#if wxUSE_LIBPNG
-#include "../png/png.h"
-#endif
-#if wxUSE_LIBJPEG
-extern "C" {
-#include <jpeglib.h>
-}
-#endif
 #include "wx/filefn.h"
 #include "wx/wfstream.h"
 #include "wx/intl.h"
@@ -462,9 +454,6 @@ wxImageHandler *wxImage::FindHandler( long bitmapType )
 void wxImage::InitStandardHandlers()
 {
     AddHandler( new wxBMPHandler );
-#if wxUSE_LIBPNG
-    AddHandler( new wxPNGHandler );
-#endif
 }
 
 void wxImage::CleanUpHandlers()
@@ -500,490 +489,6 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE
 }
 #endif // wxUSE_STREAMS
 
-//-----------------------------------------------------------------------------
-// wxPNGHandler
-//-----------------------------------------------------------------------------
-
-#if wxUSE_LIBPNG
-
-#if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxPNGHandler,wxImageHandler)
-#endif
-
-
-#if wxUSE_STREAMS
-static void _PNG_stream_reader( png_structp png_ptr, png_bytep data, png_size_t length )
-{
-    ((wxInputStream*) png_get_io_ptr( png_ptr )) -> Read(data, length);
-}
-
-static void _PNG_stream_writer( png_structp png_ptr, png_bytep data, png_size_t length )
-{
-    ((wxOutputStream*) png_get_io_ptr( png_ptr )) -> Write(data, length);
-}
-
-bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream )
-{
-    // VZ: as this function uses setjmp() the only fool proof error handling
-    //     method is to use goto (setjmp is not really C++ dtors friendly...)
-    
-    unsigned char **lines = (unsigned char **) NULL;
-    unsigned int i;
-    png_infop info_ptr = (png_infop) NULL;
-    
-    image->Destroy();
-    
-    png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,
-        (voidp) NULL,
-        (png_error_ptr) NULL,
-        (png_error_ptr) NULL );
-    if (!png_ptr)
-        goto error;
-    
-    info_ptr = png_create_info_struct( png_ptr );
-    if (!info_ptr)
-        goto error;
-    
-    if (setjmp(png_ptr->jmpbuf))
-        goto error;
-    
-    if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
-        goto error;
-    
-    png_set_read_fn( png_ptr, &stream, _PNG_stream_reader);
-    
-    png_uint_32 width,height;
-    int bit_depth,color_type,interlace_type;
-    
-    png_read_info( png_ptr, info_ptr );
-    png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, (int*) NULL, (int*) NULL );
-    
-    if (color_type == PNG_COLOR_TYPE_PALETTE)
-        png_set_expand( png_ptr );
-    
-    png_set_strip_16( png_ptr );
-    png_set_packing( png_ptr );
-    if (png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS))
-        png_set_expand( png_ptr );
-    png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
-    
-    image->Create( width, height );
-    
-    if (!image->Ok())
-        goto error;
-    
-    lines = (unsigned char **)malloc( height * sizeof(unsigned char *) );
-    if (lines == NULL)
-        goto error;
-    
-    for (i = 0; i < height; i++)
-    {
-        if ((lines[i] = (unsigned char *)malloc(width * (sizeof(unsigned char) * 4))) == NULL)
-        {
-            for ( unsigned int n = 0; n < i; n++ )
-                free( lines[n] );
-            goto error;
-        }
-    }
-    
-    // loaded successfully!
-    {
-        int transp = 0;
-        png_read_image( png_ptr, lines );
-        png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
-        unsigned char *ptr = image->GetData();
-        if ((color_type == PNG_COLOR_TYPE_GRAY) ||
-            (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
-        {
-            for (unsigned int y = 0; y < height; y++)
-            {
-                unsigned char *ptr2 = lines[y];
-                for (unsigned int x = 0; x < width; x++)
-                {
-                    unsigned char r = *ptr2++;
-                    unsigned char a = *ptr2++;
-                    if (a < 128)
-                    {
-                        *ptr++ = 255;
-                        *ptr++ = 0;
-                        *ptr++ = 255;
-                        transp = 1;
-                    }
-                    else
-                    {
-                        *ptr++ = r;
-                        *ptr++ = r;
-                        *ptr++ = r;
-                    }
-                }
-            }
-        }
-        else
-        {
-            for (unsigned int y = 0; y < height; y++)
-            {
-                unsigned char *ptr2 = lines[y];
-                for (unsigned int x = 0; x < width; x++)
-                {
-                    unsigned char r = *ptr2++;
-                    unsigned char g = *ptr2++;
-                    unsigned char b = *ptr2++;
-                    unsigned char a = *ptr2++;
-                    if (a < 128)
-                    {
-                        *ptr++ = 255;
-                        *ptr++ = 0;
-                        *ptr++ = 255;
-                        transp = 1;
-                    }
-                    else
-                    {
-                        if ((r == 255) && (g == 0) && (b == 255)) r = 254;
-                        *ptr++ = r;
-                        *ptr++ = g;
-                        *ptr++ = b;
-                    }
-                }
-            }
-        }
-        
-        for ( unsigned int j = 0; j < height; j++ )
-            free( lines[j] );
-        free( lines );
-        
-        if (transp)
-        {
-            image->SetMaskColour( 255, 0, 255 );
-        }
-        else
-        {
-            image->SetMask( FALSE );
-        }
-    }
-    
-    return TRUE;
-    
-error:
-    wxLogError(_("Couldn't load a PNG image - probably file is corrupted."));
-    
-    if ( image->Ok() )
-    {
-        image->Destroy();
-    }
-    
-    if ( lines )
-    {
-        free( lines );
-    }
-    
-    if ( png_ptr )
-    {
-        if ( info_ptr )
-        {
-            png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
-            free(info_ptr);
-        }
-        else
-            png_destroy_read_struct( &png_ptr, (png_infopp) NULL, (png_infopp) NULL );
-    }
-    return FALSE;
-}
-
-
-bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
-{
-    {
-        png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-        if (!png_ptr)
-        {
-            return FALSE;
-        }
-        
-        png_infop info_ptr = png_create_info_struct(png_ptr);
-        if (info_ptr == NULL)
-        {
-            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
-            return FALSE;
-        }
-        
-        if (setjmp(png_ptr->jmpbuf))
-        {
-            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
-            return FALSE;
-        }
-        
-        png_set_write_fn( png_ptr, &stream, _PNG_stream_writer, NULL);
-        
-        png_set_IHDR( png_ptr, info_ptr, image->GetWidth(), image->GetHeight(), 8,
-            PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
-            PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-        
-        png_color_8 sig_bit;
-        sig_bit.red = 8;
-        sig_bit.green = 8;
-        sig_bit.blue = 8;
-        sig_bit.alpha = 8;
-        png_set_sBIT( png_ptr, info_ptr, &sig_bit );
-        png_write_info( png_ptr, info_ptr );
-        png_set_shift( png_ptr, &sig_bit );
-        png_set_packing( png_ptr );
-        
-        unsigned char *data = (unsigned char *)malloc( image->GetWidth()*4 );
-        if (!data)
-        {
-            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
-            return FALSE;
-        }
-        
-        for (int y = 0; y < image->GetHeight(); y++)
-        {
-            unsigned char *ptr = image->GetData() + (y * image->GetWidth() * 3);
-            for (int x = 0; x < image->GetWidth(); x++)
-            {
-                data[(x << 2) + 0] = *ptr++;
-                data[(x << 2) + 1] = *ptr++;
-                data[(x << 2) + 2] = *ptr++;
-                if ((data[(x << 2) + 0] == image->GetMaskRed()) &&
-                    (data[(x << 2) + 1] == image->GetMaskGreen()) &&
-                    (data[(x << 2) + 2] == image->GetMaskBlue()))
-                {
-                    data[(x << 2) + 3] = 0;
-                }
-                else
-                {
-                    data[(x << 2) + 3] = 255;
-                }
-            }
-            png_bytep row_ptr = data;
-            png_write_rows( png_ptr, &row_ptr, 1 );
-        }
-        
-        free(data);
-        png_write_end( png_ptr, info_ptr );
-        png_destroy_write_struct( &png_ptr, (png_infopp)&info_ptr );
-    }
-    return TRUE;
-}
-#endif // wxUSE_STREAMS
-
-#endif
-
-// wxUSE_LIBPNG
-
-
-//-----------------------------------------------------------------------------
-// wxJPEGHandler
-//-----------------------------------------------------------------------------
-
-#if wxUSE_LIBJPEG
-
-#if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler)
-#endif
-
-#if wxUSE_STREAMS
-
-
-//------------- JPEG Data Source Manager
-
-typedef struct {
-    struct jpeg_source_mgr pub;   /* public fields */
-    
-    JOCTET* buffer;               /* start of buffer */
-} my_source_mgr;
-
-typedef my_source_mgr * my_src_ptr;
-
-METHODDEF(void) my_init_source ( j_decompress_ptr cinfo )
-{
-}
-
-METHODDEF(boolean) my_fill_input_buffer ( j_decompress_ptr cinfo )
-{
-    return TRUE;
-}
-
-METHODDEF(void) my_skip_input_data ( j_decompress_ptr cinfo, long num_bytes )
-{
-    my_src_ptr src = (my_src_ptr) cinfo->src;
-    
-    src->pub.next_input_byte += (size_t) num_bytes;
-    src->pub.bytes_in_buffer -= (size_t) num_bytes;
-}
-
-METHODDEF(void) my_term_source ( j_decompress_ptr cinfo )
-{
-    my_src_ptr src = (my_src_ptr) cinfo->src;
-    
-    free (src->buffer);
-}
-
-void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
-{
-    my_src_ptr src;
-    
-    if (cinfo->src == NULL) {  /* first time for this JPEG object? */
-        cinfo->src = (struct jpeg_source_mgr *)
-            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
-            sizeof(my_source_mgr));
-        src = (my_src_ptr) cinfo->src;
-    }
-    src = (my_src_ptr) cinfo->src;
-    src->pub.bytes_in_buffer = infile.StreamSize(); /* forces fill_input_buffer on first read */
-    src->buffer = (JOCTET *) malloc (infile.StreamSize());
-    src->pub.next_input_byte = src->buffer; /* until buffer loaded */
-    infile.Read(src->buffer, infile.StreamSize());
-    
-    src->pub.init_source = my_init_source;
-    src->pub.fill_input_buffer = my_fill_input_buffer;
-    src->pub.skip_input_data = my_skip_input_data;
-    src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
-    src->pub.term_source = my_term_source;
-}
-
-
-
-bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream )
-{
-    struct jpeg_decompress_struct cinfo;
-    struct jpeg_error_mgr jerr;
-    JSAMPARRAY tempbuf;
-    unsigned char *ptr;
-    unsigned stride;
-    
-    image->Destroy();
-    cinfo.err = jpeg_std_error( &jerr );
-    jpeg_create_decompress( &cinfo );
-    jpeg_wxio_src( &cinfo, stream );
-    jpeg_read_header( &cinfo, TRUE );
-    cinfo.out_color_space = JCS_RGB;
-    jpeg_start_decompress( &cinfo );
-    
-    image->Create( cinfo.image_width, cinfo.image_height );
-    if (!image->Ok()) {
-        jpeg_finish_decompress( &cinfo );
-        jpeg_destroy_decompress( &cinfo );
-        return FALSE;
-    }
-    image->SetMask( FALSE );
-    ptr = image->GetData();
-    stride = cinfo.output_width * 3;
-    tempbuf = (*cinfo.mem->alloc_sarray)
-        ((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
-    
-    while ( cinfo.output_scanline < cinfo.output_height ) {
-        jpeg_read_scanlines( &cinfo, tempbuf, 1 );
-        memcpy( ptr, tempbuf[0], stride );
-        ptr += stride;
-    }
-    jpeg_finish_decompress( &cinfo );
-    jpeg_destroy_decompress( &cinfo );
-    return TRUE;
-}
-
-
-
-
-
-typedef struct {
-    struct jpeg_destination_mgr pub;
-    
-    wxOutputStream *stream;
-    JOCTET * buffer;
-} my_destination_mgr;
-
-typedef my_destination_mgr * my_dest_ptr;
-
-#define OUTPUT_BUF_SIZE  4096  /* choose an efficiently fwrite'able size */
-
-METHODDEF(void) init_destination (j_compress_ptr cinfo)
-{
-    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
-    
-    /* Allocate the output buffer --- it will be released when done with image */
-    dest->buffer = (JOCTET *)
-        (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-        OUTPUT_BUF_SIZE * sizeof(JOCTET));
-    dest->pub.next_output_byte = dest->buffer;
-    dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
-}
-
-METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo)
-{
-    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
-    
-    dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
-    dest->pub.next_output_byte = dest->buffer;
-    dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
-    return TRUE;
-}
-
-METHODDEF(void) term_destination (j_compress_ptr cinfo)
-{
-    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
-    size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
-    /* Write any data remaining in the buffer */
-    if (datacount > 0)
-        dest->stream->Write(dest->buffer, datacount);
-}
-
-GLOBAL(void) jpeg_wxio_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
-{
-    my_dest_ptr dest;
-    
-    if (cinfo->dest == NULL) { /* first time for this JPEG object? */
-        cinfo->dest = (struct jpeg_destination_mgr *)
-            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
-            sizeof(my_destination_mgr));
-    }
-    
-    dest = (my_dest_ptr) cinfo->dest;
-    dest->pub.init_destination = init_destination;
-    dest->pub.empty_output_buffer = empty_output_buffer;
-    dest->pub.term_destination = term_destination;
-    dest->stream = &outfile;
-}
-
-
-
-bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
-{
-    struct jpeg_compress_struct cinfo;
-    struct jpeg_error_mgr jerr;
-    JSAMPROW row_pointer[1];   /* pointer to JSAMPLE row[s] */
-    JSAMPLE *image_buffer;
-    int stride;                        /* physical row width in image buffer */
-    
-    cinfo.err = jpeg_std_error(&jerr);
-    jpeg_create_compress(&cinfo);
-    jpeg_wxio_dest(&cinfo, stream);
-    
-    cinfo.image_width = image->GetWidth();
-    cinfo.image_height = image->GetHeight();
-    cinfo.input_components = 3;
-    cinfo.in_color_space = JCS_RGB;
-    jpeg_set_defaults(&cinfo);
-    jpeg_start_compress(&cinfo, TRUE);
-    
-    stride = cinfo.image_width * 3;    /* JSAMPLEs per row in image_buffer */
-    image_buffer = image->GetData();
-    while (cinfo.next_scanline < cinfo.image_height) {
-        row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
-        jpeg_write_scanlines( &cinfo, row_pointer, 1 );
-    }
-    jpeg_finish_compress(&cinfo);
-    jpeg_destroy_compress(&cinfo);
-    
-    return TRUE;
-}
-#endif // wxUSE_STREAMS
-
-#endif
-
-// wxUSE_LIBJPEG
-
-
-
 //-----------------------------------------------------------------------------
 // wxBMPHandler
 //-----------------------------------------------------------------------------
diff --git a/src/common/imagjpeg.cpp b/src/common/imagjpeg.cpp
new file mode 100644 (file)
index 0000000..f36b632
--- /dev/null
@@ -0,0 +1,257 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        imagjpeg.cpp
+// Purpose:     wxImage JPEG handler
+// Author:      Robert Roebling
+// RCS-ID:      $Id$
+// Copyright:   (c) Robert Roebling
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "image.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#include "wx/image.h"
+#include "wx/bitmap.h"
+#include "wx/debug.h"
+#include "wx/log.h"
+#include "wx/app.h"
+#if wxUSE_LIBJPEG
+extern "C" {
+#include <jpeglib.h>
+}
+#endif
+#include "wx/filefn.h"
+#include "wx/wfstream.h"
+#include "wx/intl.h"
+#include "wx/module.h"
+
+// For memcpy
+#include <string.h>
+
+#ifdef __SALFORDC__
+#ifdef FAR
+#undef FAR
+#endif
+#endif
+
+#ifdef __WXMSW__
+#include <windows.h>
+#endif
+
+//-----------------------------------------------------------------------------
+// wxJPEGHandler
+//-----------------------------------------------------------------------------
+
+#if wxUSE_LIBJPEG
+
+#if !USE_SHARED_LIBRARIES
+IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler)
+#endif
+
+#if wxUSE_STREAMS
+
+
+//------------- JPEG Data Source Manager
+
+typedef struct {
+    struct jpeg_source_mgr pub;   /* public fields */
+    
+    JOCTET* buffer;               /* start of buffer */
+} my_source_mgr;
+
+typedef my_source_mgr * my_src_ptr;
+
+METHODDEF(void) my_init_source ( j_decompress_ptr cinfo )
+{
+}
+
+METHODDEF(boolean) my_fill_input_buffer ( j_decompress_ptr cinfo )
+{
+    return TRUE;
+}
+
+METHODDEF(void) my_skip_input_data ( j_decompress_ptr cinfo, long num_bytes )
+{
+    my_src_ptr src = (my_src_ptr) cinfo->src;
+    
+    src->pub.next_input_byte += (size_t) num_bytes;
+    src->pub.bytes_in_buffer -= (size_t) num_bytes;
+}
+
+METHODDEF(void) my_term_source ( j_decompress_ptr cinfo )
+{
+    my_src_ptr src = (my_src_ptr) cinfo->src;
+    
+    free (src->buffer);
+}
+
+void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile )
+{
+    my_src_ptr src;
+    
+    if (cinfo->src == NULL) {  /* first time for this JPEG object? */
+        cinfo->src = (struct jpeg_source_mgr *)
+            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+            sizeof(my_source_mgr));
+        src = (my_src_ptr) cinfo->src;
+    }
+    src = (my_src_ptr) cinfo->src;
+    src->pub.bytes_in_buffer = infile.StreamSize(); /* forces fill_input_buffer on first read */
+    src->buffer = (JOCTET *) malloc (infile.StreamSize());
+    src->pub.next_input_byte = src->buffer; /* until buffer loaded */
+    infile.Read(src->buffer, infile.StreamSize());
+    
+    src->pub.init_source = my_init_source;
+    src->pub.fill_input_buffer = my_fill_input_buffer;
+    src->pub.skip_input_data = my_skip_input_data;
+    src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
+    src->pub.term_source = my_term_source;
+}
+
+
+
+bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream )
+{
+    struct jpeg_decompress_struct cinfo;
+    struct jpeg_error_mgr jerr;
+    JSAMPARRAY tempbuf;
+    unsigned char *ptr;
+    unsigned stride;
+    
+    image->Destroy();
+    cinfo.err = jpeg_std_error( &jerr );
+    jpeg_create_decompress( &cinfo );
+    jpeg_wxio_src( &cinfo, stream );
+    jpeg_read_header( &cinfo, TRUE );
+    cinfo.out_color_space = JCS_RGB;
+    jpeg_start_decompress( &cinfo );
+    
+    image->Create( cinfo.image_width, cinfo.image_height );
+    if (!image->Ok()) {
+        jpeg_finish_decompress( &cinfo );
+        jpeg_destroy_decompress( &cinfo );
+        return FALSE;
+    }
+    image->SetMask( FALSE );
+    ptr = image->GetData();
+    stride = cinfo.output_width * 3;
+    tempbuf = (*cinfo.mem->alloc_sarray)
+        ((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
+    
+    while ( cinfo.output_scanline < cinfo.output_height ) {
+        jpeg_read_scanlines( &cinfo, tempbuf, 1 );
+        memcpy( ptr, tempbuf[0], stride );
+        ptr += stride;
+    }
+    jpeg_finish_decompress( &cinfo );
+    jpeg_destroy_decompress( &cinfo );
+    return TRUE;
+}
+
+
+
+
+
+typedef struct {
+    struct jpeg_destination_mgr pub;
+    
+    wxOutputStream *stream;
+    JOCTET * buffer;
+} my_destination_mgr;
+
+typedef my_destination_mgr * my_dest_ptr;
+
+#define OUTPUT_BUF_SIZE  4096  /* choose an efficiently fwrite'able size */
+
+METHODDEF(void) init_destination (j_compress_ptr cinfo)
+{
+    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+    
+    /* Allocate the output buffer --- it will be released when done with image */
+    dest->buffer = (JOCTET *)
+        (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+        OUTPUT_BUF_SIZE * sizeof(JOCTET));
+    dest->pub.next_output_byte = dest->buffer;
+    dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+}
+
+METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo)
+{
+    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+    
+    dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
+    dest->pub.next_output_byte = dest->buffer;
+    dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+    return TRUE;
+}
+
+METHODDEF(void) term_destination (j_compress_ptr cinfo)
+{
+    my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+    size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
+    /* Write any data remaining in the buffer */
+    if (datacount > 0)
+        dest->stream->Write(dest->buffer, datacount);
+}
+
+GLOBAL(void) jpeg_wxio_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
+{
+    my_dest_ptr dest;
+    
+    if (cinfo->dest == NULL) { /* first time for this JPEG object? */
+        cinfo->dest = (struct jpeg_destination_mgr *)
+            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+            sizeof(my_destination_mgr));
+    }
+    
+    dest = (my_dest_ptr) cinfo->dest;
+    dest->pub.init_destination = init_destination;
+    dest->pub.empty_output_buffer = empty_output_buffer;
+    dest->pub.term_destination = term_destination;
+    dest->stream = &outfile;
+}
+
+bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
+{
+    struct jpeg_compress_struct cinfo;
+    struct jpeg_error_mgr jerr;
+    JSAMPROW row_pointer[1];   /* pointer to JSAMPLE row[s] */
+    JSAMPLE *image_buffer;
+    int stride;                        /* physical row width in image buffer */
+    
+    cinfo.err = jpeg_std_error(&jerr);
+    jpeg_create_compress(&cinfo);
+    jpeg_wxio_dest(&cinfo, stream);
+    
+    cinfo.image_width = image->GetWidth();
+    cinfo.image_height = image->GetHeight();
+    cinfo.input_components = 3;
+    cinfo.in_color_space = JCS_RGB;
+    jpeg_set_defaults(&cinfo);
+    jpeg_start_compress(&cinfo, TRUE);
+    
+    stride = cinfo.image_width * 3;    /* JSAMPLEs per row in image_buffer */
+    image_buffer = image->GetData();
+    while (cinfo.next_scanline < cinfo.image_height) {
+        row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
+        jpeg_write_scanlines( &cinfo, row_pointer, 1 );
+    }
+    jpeg_finish_compress(&cinfo);
+    jpeg_destroy_compress(&cinfo);
+    
+    return TRUE;
+}
+#endif // wxUSE_STREAMS
+
+#endif
+
+// wxUSE_LIBJPEG
+
diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp
new file mode 100644 (file)
index 0000000..e200c00
--- /dev/null
@@ -0,0 +1,316 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        imagepng.cpp
+// Purpose:     wxImage PNG handler
+// Author:      Robert Roebling
+// RCS-ID:      $Id$
+// Copyright:   (c) Robert Roebling
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "image.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#include "wx/image.h"
+#include "wx/bitmap.h"
+#include "wx/debug.h"
+#include "wx/log.h"
+#include "wx/app.h"
+#if wxUSE_LIBPNG
+#include "../png/png.h"
+#endif
+#include "wx/filefn.h"
+#include "wx/wfstream.h"
+#include "wx/intl.h"
+#include "wx/module.h"
+
+// For memcpy
+#include <string.h>
+
+#ifdef __SALFORDC__
+#ifdef FAR
+#undef FAR
+#endif
+#endif
+
+#ifdef __WXMSW__
+#include <windows.h>
+#endif
+
+//-----------------------------------------------------------------------------
+// wxPNGHandler
+//-----------------------------------------------------------------------------
+
+#if wxUSE_LIBPNG
+
+#if !USE_SHARED_LIBRARIES
+IMPLEMENT_DYNAMIC_CLASS(wxPNGHandler,wxImageHandler)
+#endif
+
+
+#if wxUSE_STREAMS
+static void _PNG_stream_reader( png_structp png_ptr, png_bytep data, png_size_t length )
+{
+    ((wxInputStream*) png_get_io_ptr( png_ptr )) -> Read(data, length);
+}
+
+static void _PNG_stream_writer( png_structp png_ptr, png_bytep data, png_size_t length )
+{
+    ((wxOutputStream*) png_get_io_ptr( png_ptr )) -> Write(data, length);
+}
+
+bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream )
+{
+    // VZ: as this function uses setjmp() the only fool proof error handling
+    //     method is to use goto (setjmp is not really C++ dtors friendly...)
+    
+    unsigned char **lines = (unsigned char **) NULL;
+    unsigned int i;
+    png_infop info_ptr = (png_infop) NULL;
+    
+    image->Destroy();
+    
+    png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,
+        (voidp) NULL,
+        (png_error_ptr) NULL,
+        (png_error_ptr) NULL );
+    if (!png_ptr)
+        goto error;
+    
+    info_ptr = png_create_info_struct( png_ptr );
+    if (!info_ptr)
+        goto error;
+    
+    if (setjmp(png_ptr->jmpbuf))
+        goto error;
+    
+    if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+        goto error;
+    
+    png_set_read_fn( png_ptr, &stream, _PNG_stream_reader);
+    
+    png_uint_32 width,height;
+    int bit_depth,color_type,interlace_type;
+    
+    png_read_info( png_ptr, info_ptr );
+    png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, (int*) NULL, (int*) NULL );
+    
+    if (color_type == PNG_COLOR_TYPE_PALETTE)
+        png_set_expand( png_ptr );
+    
+    png_set_strip_16( png_ptr );
+    png_set_packing( png_ptr );
+    if (png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS))
+        png_set_expand( png_ptr );
+    png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
+    
+    image->Create( width, height );
+    
+    if (!image->Ok())
+        goto error;
+    
+    lines = (unsigned char **)malloc( height * sizeof(unsigned char *) );
+    if (lines == NULL)
+        goto error;
+    
+    for (i = 0; i < height; i++)
+    {
+        if ((lines[i] = (unsigned char *)malloc(width * (sizeof(unsigned char) * 4))) == NULL)
+        {
+            for ( unsigned int n = 0; n < i; n++ )
+                free( lines[n] );
+            goto error;
+        }
+    }
+    
+    // loaded successfully!
+    {
+        int transp = 0;
+        png_read_image( png_ptr, lines );
+        png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
+        unsigned char *ptr = image->GetData();
+        if ((color_type == PNG_COLOR_TYPE_GRAY) ||
+            (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
+        {
+            for (unsigned int y = 0; y < height; y++)
+            {
+                unsigned char *ptr2 = lines[y];
+                for (unsigned int x = 0; x < width; x++)
+                {
+                    unsigned char r = *ptr2++;
+                    unsigned char a = *ptr2++;
+                    if (a < 128)
+                    {
+                        *ptr++ = 255;
+                        *ptr++ = 0;
+                        *ptr++ = 255;
+                        transp = 1;
+                    }
+                    else
+                    {
+                        *ptr++ = r;
+                        *ptr++ = r;
+                        *ptr++ = r;
+                    }
+                }
+            }
+        }
+        else
+        {
+            for (unsigned int y = 0; y < height; y++)
+            {
+                unsigned char *ptr2 = lines[y];
+                for (unsigned int x = 0; x < width; x++)
+                {
+                    unsigned char r = *ptr2++;
+                    unsigned char g = *ptr2++;
+                    unsigned char b = *ptr2++;
+                    unsigned char a = *ptr2++;
+                    if (a < 128)
+                    {
+                        *ptr++ = 255;
+                        *ptr++ = 0;
+                        *ptr++ = 255;
+                        transp = 1;
+                    }
+                    else
+                    {
+                        if ((r == 255) && (g == 0) && (b == 255)) r = 254;
+                        *ptr++ = r;
+                        *ptr++ = g;
+                        *ptr++ = b;
+                    }
+                }
+            }
+        }
+        
+        for ( unsigned int j = 0; j < height; j++ )
+            free( lines[j] );
+        free( lines );
+        
+        if (transp)
+        {
+            image->SetMaskColour( 255, 0, 255 );
+        }
+        else
+        {
+            image->SetMask( FALSE );
+        }
+    }
+    
+    return TRUE;
+    
+error:
+    wxLogError(_("Couldn't load a PNG image - probably file is corrupted."));
+    
+    if ( image->Ok() )
+    {
+        image->Destroy();
+    }
+    
+    if ( lines )
+    {
+        free( lines );
+    }
+    
+    if ( png_ptr )
+    {
+        if ( info_ptr )
+        {
+            png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
+            free(info_ptr);
+        }
+        else
+            png_destroy_read_struct( &png_ptr, (png_infopp) NULL, (png_infopp) NULL );
+    }
+    return FALSE;
+}
+
+
+bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
+{
+    {
+        png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+        if (!png_ptr)
+        {
+            return FALSE;
+        }
+        
+        png_infop info_ptr = png_create_info_struct(png_ptr);
+        if (info_ptr == NULL)
+        {
+            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+            return FALSE;
+        }
+        
+        if (setjmp(png_ptr->jmpbuf))
+        {
+            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+            return FALSE;
+        }
+        
+        png_set_write_fn( png_ptr, &stream, _PNG_stream_writer, NULL);
+        
+        png_set_IHDR( png_ptr, info_ptr, image->GetWidth(), image->GetHeight(), 8,
+            PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
+            PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+        
+        png_color_8 sig_bit;
+        sig_bit.red = 8;
+        sig_bit.green = 8;
+        sig_bit.blue = 8;
+        sig_bit.alpha = 8;
+        png_set_sBIT( png_ptr, info_ptr, &sig_bit );
+        png_write_info( png_ptr, info_ptr );
+        png_set_shift( png_ptr, &sig_bit );
+        png_set_packing( png_ptr );
+        
+        unsigned char *data = (unsigned char *)malloc( image->GetWidth()*4 );
+        if (!data)
+        {
+            png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+            return FALSE;
+        }
+        
+        for (int y = 0; y < image->GetHeight(); y++)
+        {
+            unsigned char *ptr = image->GetData() + (y * image->GetWidth() * 3);
+            for (int x = 0; x < image->GetWidth(); x++)
+            {
+                data[(x << 2) + 0] = *ptr++;
+                data[(x << 2) + 1] = *ptr++;
+                data[(x << 2) + 2] = *ptr++;
+                if ((data[(x << 2) + 0] == image->GetMaskRed()) &&
+                    (data[(x << 2) + 1] == image->GetMaskGreen()) &&
+                    (data[(x << 2) + 2] == image->GetMaskBlue()))
+                {
+                    data[(x << 2) + 3] = 0;
+                }
+                else
+                {
+                    data[(x << 2) + 3] = 255;
+                }
+            }
+            png_bytep row_ptr = data;
+            png_write_rows( png_ptr, &row_ptr, 1 );
+        }
+        
+        free(data);
+        png_write_end( png_ptr, info_ptr );
+        png_destroy_write_struct( &png_ptr, (png_infopp)&info_ptr );
+    }
+    return TRUE;
+}
+#endif // wxUSE_STREAMS
+
+#endif
+
+// wxUSE_LIBPNG
+
index d609f6c4be9444f40c1414f09223f9ff7d4700d2..240068c9b549d752d0691d4d46afd08a4d7d07e6 100644 (file)
@@ -26,6 +26,8 @@ LIB_CPP_SRC=\
  common/helpbase.cpp \
  common/intl.cpp \
  common/image.cpp \
+ common/imagjpeg.cpp \
+ common/imagpng.cpp \
  common/ipcbase.cpp \
  common/layout.cpp \
  common/list.cpp \
index ae5fd90f3c15ffdcd677d32d2157e169dffea66d..ad4654c9e73f0c015c2704e7724db472721f0b4b 100644 (file)
@@ -30,6 +30,8 @@ LIB_CPP_SRC=\
  ../common/helpbase.cpp \
  ../common/intl.cpp \
  ../common/image.cpp \
+ ../common/imagjpeg.cpp \
+ ../common/imagpng.cpp \
  ../common/ipcbase.cpp \
  ../common/layout.cpp \
  ../common/list.cpp \
index ae5fd90f3c15ffdcd677d32d2157e169dffea66d..ad4654c9e73f0c015c2704e7724db472721f0b4b 100644 (file)
@@ -30,6 +30,8 @@ LIB_CPP_SRC=\
  ../common/helpbase.cpp \
  ../common/intl.cpp \
  ../common/image.cpp \
+ ../common/imagjpeg.cpp \
+ ../common/imagpng.cpp \
  ../common/ipcbase.cpp \
  ../common/layout.cpp \
  ../common/list.cpp \
index 0fb9dfacee28fa4be142d5f15d25a2acc8ce2697..34d927865f0a4024d0a78bf4cc5b9f0c1735bd55 100644 (file)
@@ -121,7 +121,7 @@ WXSRC=$(WXDIR)/src/msw
 WXINC=$(WXDIR)/include
 WXBASESRC=$(WXDIR)/src/common
 WXLIB=$(WXDIR)/lib/$(LIBPREFIX)wx.$(LIBSUFF)
-INC = -I$(WXINC) -I$(WXDIR)/src/png -I$(WXDIR)/include/wx/msw/gnuwin32 -I$(WXDIR)/src/zlib $(EXTRAINC) $(COMPPATHS)
+INC = -I$(WXINC) -I$(WXDIR)/src/png -I$(WXDIR)/src/jpeg -I$(WXDIR)/include/wx/msw/gnuwin32 -I$(WXDIR)/src/zlib $(EXTRAINC) $(COMPPATHS)
 RCLFLAGS=-cpp "cpp -lang-c++ -DWIN32 -D_WIN32 -DRCL_INVOKED -I$(WXWIN)\include"
 
 #LIBS = -lctl3d32 $(WXLIB) $(WINLIBS) $(COMPLIBS)
index 28a66ef729dd17b115af548806398ed84bb165e7..856f75bd8c65e60b1b1f89d3b62987bc0bc7e794 100644 (file)
@@ -132,7 +132,7 @@ D=$(D)DLL
 WXLIB=$(WXDIR)\lib\$(WXLIBNAME).lib
 
 INC=-I$(WXINC) -I$(WXDIR)/src/png -I$(WXDIR)/src/zlib -I$(WXDIR)/src/jpeg $(EXTRAINC)
-LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) $(WXDIR)\lib\winpng.lib $(WXDIR)\lib\zlib.lib $(WXDIR)\lib\xpm.lib
+LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) $(WXDIR)\lib\winpng.lib $(WXDIR)\lib\zlib.lib $(WXDIR)\lib\jpeg.lib $(WXDIR)\lib\xpm.lib
 
 MAKEPRECOMP=/YcWX/WXPREC.H
 OPTIONS=
@@ -188,3 +188,13 @@ LINKFLAGS=$(LINK_DEBUG_FLAGS) -machine:i386 -subsystem:windows,$(APPVER) -dll #
 
 DUMMYOBJ=$(WXDIR)\src\msw\$D\$(DUMMY).obj
 
+.c.obj:
+       cl @<<
+$(CPPFLAGS2) /Fo$@ /c $<
+<<
+
+.cpp.obj:
+       cl @<<
+$(CPPFLAGS2) /Fo$@ /c $<
+<<
+
index 9429866884946c27b4f4f8e1b95672978d9df214..56b9f3e56fc6af78f4195d4e385496737f89aca2 100644 (file)
@@ -25,6 +25,8 @@ LIB_CPP_SRC=\
  common/hash.cpp \
  common/helpbase.cpp \
  common/image.cpp \
+ common/imagjpeg.cpp \
+ common/imagpng.cpp \
  common/intl.cpp \
  common/ipcbase.cpp \
  common/layout.cpp \
index 84fb0d06bc84056ffbe1068e2a20e7eb4c3d64de..e8c8ab75322b814c758e67ff38726623679148ae 100644 (file)
@@ -31,6 +31,8 @@ LIB_CPP_SRC=\
  ../common/intl.cpp \
  ../common/ipcbase.cpp \
  ../common/image.cpp \
+ ../common/imagjpeg.cpp \
+ ../common/imagpng.cpp \
  ../common/layout.cpp \
  ../common/list.cpp \
  ../common/log.cpp \
index 76d1febd5c6211d18d806ab313699e18e2dc4d30..7c0b8760c5655ba979f2f7e55583bc802f7df604 100644 (file)
@@ -110,6 +110,8 @@ COMMONOBJS = \
   $(MSWDIR)\gdicmn.obj \
   $(MSWDIR)\helpbase.obj \
   $(MSWDIR)\image.obj \
+  $(MSWDIR)\imagpng.obj \
+  $(MSWDIR)\imagjpeg.obj \
   $(MSWDIR)\intl.obj \
   $(MSWDIR)\ipcbase.obj \
   $(MSWDIR)\log.obj \
@@ -504,6 +506,12 @@ $(MSWDIR)\gdicmn.obj:     $(COMMDIR)\gdicmn.$(SRCSUFF)
 
 $(MSWDIR)\image.obj:     $(COMMDIR)\image.$(SRCSUFF)
 
+$(MSWDIR)\imagpng.obj:     $(COMMDIR)\imagpng.$(SRCSUFF)
+
+$(MSWDIR)\imagjpeg.obj:     $(COMMDIR)\imagjpeg.$(SRCSUFF)
+
+$(MSWDIR)\image.obj:     $(COMMDIR)\image.$(SRCSUFF)
+
 $(MSWDIR)\intl.obj:     $(COMMDIR)\intl.$(SRCSUFF)
 
 $(MSWDIR)\ipcbase.obj:     $(COMMDIR)\ipcbase.$(SRCSUFF)
@@ -699,7 +707,7 @@ $(CFG): makefile.b32
 -WE
 -tWM
 
--I$(WXINC);$(BCCDIR)\include;$(WXDIR)/src/png;$(WXDIR)/src/zlib;$(WXDIR)/src/xpm
+-I$(WXINC);$(BCCDIR)\include;$(WXDIR)/src/png;$(WXDIR)/src/jpeg;$(WXDIR)/src/zlib;$(WXDIR)/src/xpm
 -I$(WXDIR)\include\wx\msw\gnuwin32
 
 -L$(BCCDIR)\lib
index 509a47543edd3953d3c5d8fea849e8e25c3d08d3..cb0f949c08321d1747906bab4d88982cb5aa9614 100644 (file)
@@ -89,6 +89,8 @@ COMMONOBJS = \
   $(COMMDIR)/gdicmn.$(OBJSUFF) \
   $(COMMDIR)/helpbase.$(OBJSUFF) \
   $(COMMDIR)/image.$(OBJSUFF) \
+  $(COMMDIR)/imagpng.$(OBJSUFF) \
+  $(COMMDIR)/imagjpeg.$(OBJSUFF) \
   $(COMMDIR)/intl.$(OBJSUFF) \
   $(COMMDIR)/ipcbase.$(OBJSUFF) \
   $(COMMDIR)/layout.$(OBJSUFF) \
index 069d86af37a75b17f699d414108b114d62e868c6..c9aed2a2cf640b38ba20d570eaa05e30fa1ea72f 100644 (file)
@@ -91,6 +91,8 @@ COMMONOBJS = \
   $(COMMDIR)/gdicmn.$(OBJSUFF) \
   $(COMMDIR)/helpbase.$(OBJSUFF) \
   $(COMMDIR)/image.$(OBJSUFF) \
+  $(COMMDIR)/imagpng.$(OBJSUFF) \
+  $(COMMDIR)/imagjpeg.$(OBJSUFF) \
   $(COMMDIR)/intl.$(OBJSUFF) \
   $(COMMDIR)/ipcbase.$(OBJSUFF) \
   $(COMMDIR)/layout.$(OBJSUFF) \
index d92ad76e67eb7f70a95adfe89582f02f6758e834..1f2ccebc1b6b432b05b99ed69bed11be5f15e189 100644 (file)
@@ -112,6 +112,8 @@ COMMONOBJS = \
   ..\common\$D\ftp.obj \
   ..\common\$D\gdicmn.obj \
   ..\common\$D\image.obj \
+  ..\common\$D\imagjpeg.obj \
+  ..\common\$D\imagpng.obj \
   ..\common\$D\intl.obj \
   ..\common\$D\ipcbase.obj \
   ..\common\$D\helpbase.obj \
index a3d1c73d8210434148032127733a0fcb7ff13119..436cd229eef4d12af7b6f67e4c443e19d0f0622f 100644 (file)
@@ -62,6 +62,8 @@ COMMONOBJS = cmndata.obj &
   framecmn.obj &
   gdicmn.obj &
   image.obj &
+  imagpng.obj &
+  imagjpeg.obj &
   intl.obj &
   ipcbase.obj &
   helpbase.obj &
@@ -558,6 +560,12 @@ gdicmn.obj:     $(COMMDIR)\gdicmn.cpp
 image.obj:     $(COMMDIR)\image.cpp
   *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
 
+imagpng.obj:     $(COMMDIR)\imagpng.cpp
+  *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+
+imagjpeg.obj:     $(COMMDIR)\imagjpeg.cpp
+  *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+
 intl.obj:     $(COMMDIR)\intl.cpp
   *$(CCC) $(CPPFLAGS) $(IFLAGS) $<