Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/epeg

Dir     : e17/libs/epeg/src/lib


Modified Files:
        Makefile.am epeg_main.c epeg_private.h 


Log Message:


dont need memopen stuff... anymroe.. patch from michal kowalczuk

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/epeg/src/lib/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- Makefile.am 2 Nov 2004 03:52:21 -0000       1.5
+++ Makefile.am 22 Aug 2005 07:58:35 -0000      1.6
@@ -11,7 +11,6 @@
 include_HEADERS      = Epeg.h
 libepeg_la_SOURCES  = \
 epeg_main.c \
-epeg_memfile.c \
 epeg_private.h
 
 libepeg_la_LIBADD       = @my_libs@
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/epeg/src/lib/epeg_main.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- epeg_main.c 28 Mar 2005 03:08:50 -0000      1.10
+++ epeg_main.c 22 Aug 2005 07:58:36 -0000      1.11
@@ -1,11 +1,12 @@
 #include "Epeg.h"
 #include "epeg_private.h"
+#include <jerror.h>
 
 static Epeg_Image   *_epeg_open_header         (Epeg_Image *im);
 static int           _epeg_decode              (Epeg_Image *im);
 static int           _epeg_scale               (Epeg_Image *im);
 static int           _epeg_decode_for_trim     (Epeg_Image *im);
-static int           _epeg_trim                                   (Epeg_Image 
*im);
+static int           _epeg_trim                (Epeg_Image *im);
 static int           _epeg_encode              (Epeg_Image *im);
 
 static void          _epeg_fatal_error_handler (j_common_ptr cinfo);
@@ -65,13 +66,19 @@
    Epeg_Image *im;
    
    im = calloc(1, sizeof(Epeg_Image));
-   im->in.f = _epeg_memfile_read_open(data, size);
-   if (!im->in.f)
+   
+   if (!im)
      {
        epeg_close(im);
        return NULL;
      }
+   
    im->out.quality = 75;
+   im->in.mem.data = (unsigned char **) data;
+   im->in.mem.size = size;
+   im->in.f = NULL;
+   im->in.w = 0;
+   im->in.h = 0;
    return _epeg_open_header(im);
 }
 
@@ -684,6 +691,7 @@
 {
    im->out.mem.data = data;
    im->out.mem.size = size;
+   im->out.file = NULL;
 }
 
 /**
@@ -737,18 +745,18 @@
 void
 epeg_close(Epeg_Image *im)
 {
-   if (im->pixels)             free(im->pixels);
-   if (im->lines)              free(im->lines);
-   if (im->in.file)            free(im->in.file);
-   if (im->in.f)               jpeg_destroy_decompress(&(im->in.jinfo));
-   if (im->in.f)               fclose(im->in.f);
-   if (im->in.comment)         free(im->in.comment);
-   if (im->in.thumb_info.uri)  free(im->in.thumb_info.uri);
-   if (im->in.thumb_info.mime) free(im->in.thumb_info.mime);
-   if (im->out.file)           free(im->out.file);
-   if (im->out.f)              jpeg_destroy_compress(&(im->out.jinfo));
-   if (im->out.f)              fclose(im->out.f);
-   if (im->out.comment)        free(im->out.comment);
+   if (im->pixels)                   free(im->pixels);
+   if (im->lines)                    free(im->lines);
+   if (im->in.file)                  free(im->in.file);
+   if (im->in.f || im->in.mem.data)  jpeg_destroy_decompress(&(im->in.jinfo));
+   if (im->in.f)                     fclose(im->in.f);
+   if (im->in.comment)               free(im->in.comment);
+   if (im->in.thumb_info.uri)        free(im->in.thumb_info.uri);
+   if (im->in.thumb_info.mime)       free(im->in.thumb_info.mime);
+   if (im->out.file)                 free(im->out.file);
+   if (im->in.f || im->in.mem.data)  jpeg_destroy_compress(&(im->out.jinfo));
+   if (im->out.f)                    fclose(im->out.f);
+   if (im->out.comment)              free(im->out.comment);
    free(im);
 }
 
@@ -756,6 +764,7 @@
 _epeg_open_header(Epeg_Image *im)
 {
    struct jpeg_marker_struct *m;
+   struct jpeg_source_mgr *src_mgr;
 
    im->in.jinfo.err = jpeg_std_error(&(im->jerr.pub));
    im->jerr.pub.error_exit = _epeg_fatal_error_handler;
@@ -771,7 +780,25 @@
    jpeg_create_decompress(&(im->in.jinfo));
    jpeg_save_markers(&(im->in.jinfo), JPEG_APP0 + 7, 1024);
    jpeg_save_markers(&(im->in.jinfo), JPEG_COM,      65535);
-   jpeg_stdio_src(&(im->in.jinfo), im->in.f);
+   if (im->in.f != NULL)
+     {
+       jpeg_stdio_src(&(im->in.jinfo), im->in.f);
+     }
+   else
+     {
+       /* Setup RAM source manager. */
+       src_mgr = calloc(1, sizeof(struct jpeg_source_mgr));
+       src_mgr->init_source = _jpeg_init_source;
+       src_mgr->fill_input_buffer = _jpeg_fill_input_buffer;
+       src_mgr->skip_input_data = _jpeg_skip_input_data;
+       src_mgr->resync_to_restart = jpeg_resync_to_restart;
+       src_mgr->term_source = _jpeg_term_source;
+       src_mgr->bytes_in_buffer = im->in.mem.size;
+       src_mgr->next_input_byte = (JOCTET *) im->in.mem.data;
+       
+       im->in.jinfo.src = src_mgr;
+     }
+
    jpeg_read_header(&(im->in.jinfo), TRUE);
    im->in.w = im->in.jinfo.image_width;
    im->in.h = im->in.jinfo.image_height;
@@ -780,7 +807,7 @@
    
    im->out.w = im->in.w;
    im->out.h = im->in.h;
-   
+
    im->color_space = ((im->in.color_space = im->in.jinfo.out_color_space) == 
JCS_GRAYSCALE) ? EPEG_GRAY8 : EPEG_RGB8;
    if (im->in.color_space == JCS_CMYK) im->color_space = EPEG_CMYK;
    
@@ -1050,17 +1077,22 @@
    void  *data = NULL;
    size_t size = 0;
 
+   struct jpeg_destination_mgr *dst_mgr;
+
    if (im->out.f) return 1;
    
    if (im->out.file)
-     im->out.f = fopen(im->out.file, "wb");
-   else
-     im->out.f = _epeg_memfile_write_open(&data, &size);
-   if (!im->out.f)
      {
-       im->error = 1;
-       return 1;
+       im->out.f = fopen(im->out.file, "wb");
+   
+       if (!im->out.f)
+         {
+               im->error = 1;
+               return 1;
+         }
      }
+   else
+       im->out.f = NULL;
    
    im->out.jinfo.err = jpeg_std_error(&(im->jerr.pub));
    im->jerr.pub.error_exit = _epeg_fatal_error_handler;
@@ -1068,7 +1100,19 @@
    if (setjmp(im->jerr.setjmp_buffer)) return 1;
    
    jpeg_create_compress(&(im->out.jinfo));
-   jpeg_stdio_dest(&(im->out.jinfo), im->out.f);
+   if (im->out.f)
+       jpeg_stdio_dest(&(im->out.jinfo), im->out.f);
+   else
+     {
+       /* Setup RAM destination manager */
+       dst_mgr = calloc(1, sizeof(struct jpeg_destination_mgr));
+       dst_mgr->init_destination = _jpeg_init_destination;
+       dst_mgr->empty_output_buffer = _jpeg_empty_output_buffer;
+       dst_mgr->term_destination = _jpeg_term_destination;
+       dst_mgr->free_in_buffer = *(im->out.mem.size);
+       dst_mgr->next_output_byte = (JOCTET *) *(im->out.mem.data);
+       im->out.jinfo.dest = dst_mgr;
+     }
    im->out.jinfo.image_width      = im->out.w;
    im->out.jinfo.image_height     = im->out.h;
    im->out.jinfo.input_components = im->in.jinfo.output_components;
@@ -1116,18 +1160,16 @@
    
    jpeg_finish_compress(&(im->out.jinfo));
    
-   if (im->in.f)                       
jpeg_destroy_decompress(&(im->in.jinfo));
+   if (im->in.f || im->in.mem.data != NULL)     
jpeg_destroy_decompress(&(im->in.jinfo));
    if ((im->in.f) && (im->in.file))    fclose(im->in.f);
-   if ((im->in.f) && (!im->in.file))   _epeg_memfile_read_close(im->in.f);
-   if (im->out.f)                      jpeg_destroy_compress(&(im->out.jinfo));
-   if ((im->out.f) && (im->out.file))  fclose(im->out.f);
-   if ((im->out.f) && (!im->out.file)) _epeg_memfile_write_close(im->out.f);
+   jpeg_destroy_compress(&(im->out.jinfo));
+   if ((im->out.f) && (im->out.file))  fclose(im->out.f); 
    im->in.f = NULL;
    im->out.f = NULL;
    
-   if (im->out.mem.data) *(im->out.mem.data) = data;
-   if (im->out.mem.size) *(im->out.mem.size) = size;
-       
+   if (!im->out.file)
+          *(im->out.mem.size) -= im->out.jinfo.dest->free_in_buffer;
+
    return 0;
 }
 
@@ -1140,3 +1182,46 @@
    longjmp(errmgr->setjmp_buffer, 1);
    return;
 }
+
+
+/* Source manager methods */
+METHODDEF(void) _jpeg_decompress_error_exit(j_common_ptr cinfo)
+{
+}
+
+
+METHODDEF(void) _jpeg_init_source(j_decompress_ptr cinfo)
+{
+}
+
+METHODDEF(boolean) _jpeg_fill_input_buffer(j_decompress_ptr cinfo)
+{
+}
+
+
+METHODDEF(void) _jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
+{
+       if(num_bytes > (long) (cinfo)->src->bytes_in_buffer)
+               ERREXIT(cinfo, 0);
+       
+       (cinfo)->src->next_input_byte += num_bytes;
+       (cinfo)->src->bytes_in_buffer -= num_bytes;
+}
+
+METHODDEF(void) _jpeg_term_source(j_decompress_ptr cinfo)
+{
+}
+
+
+/* Destination manager methods */
+METHODDEF(void) _jpeg_init_destination(j_compress_ptr cinfo)
+{
+}
+
+METHODDEF(boolean) _jpeg_empty_output_buffer (j_compress_ptr cinfo)
+{
+}
+
+METHODDEF(void) _jpeg_term_destination (j_compress_ptr cinfo)
+{
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/epeg/src/lib/epeg_private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- epeg_private.h      10 Jun 2004 06:39:59 -0000      1.3
+++ epeg_private.h      22 Aug 2005 07:58:36 -0000      1.4
@@ -1,7 +1,6 @@
 #ifndef _EPEG_PRIVATE_H
 #define _EPEG_PRIVATE_H
 
-#define _GNU_SOURCE /* need this for fmemopen & open_memstream */
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -39,6 +38,10 @@
    
    struct {
       char                          *file;
+      struct {
+        unsigned char           **data;
+        int                       size;
+      } mem;
       int                            w, h;
       char                          *comment;
       FILE                          *f;
@@ -67,9 +70,14 @@
    } out;
 };
 
-FILE *_epeg_memfile_read_open   (void *data, size_t size);
-void  _epeg_memfile_read_close  (FILE *f);
-FILE *_epeg_memfile_write_open  (void **data, size_t *size);
-void  _epeg_memfile_write_close (FILE *f);
+METHODDEF(void) _jpeg_decompress_error_exit(j_common_ptr cinfo);
+METHODDEF(void) _jpeg_init_source(j_decompress_ptr cinfo);
+METHODDEF(boolean) _jpeg_fill_input_buffer(j_decompress_ptr cinfo);
+METHODDEF(void) _jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes);
+METHODDEF(void) _jpeg_term_source(j_decompress_ptr cinfo);
+
+METHODDEF(void) _jpeg_init_destination(j_compress_ptr cinfo);
+METHODDEF(boolean) _jpeg_empty_output_buffer (j_compress_ptr cinfo);
+METHODDEF(void) _jpeg_term_destination (j_compress_ptr cinfo);
     
 #endif




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to