Update of /cvsroot/meshdb/src/geo/libgeo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16626/libgeo Modified Files: Tag: leonard-dev image-png.c image-ppm.c image.h Makefile.am Added Files: Tag: leonard-dev image-jpeg.c image-private.h image.c Log Message: fix alt; make image libs selectable (jpg is still buggy?) --- NEW FILE: image-jpeg.c --- #include <stdio.h> #include "compat/err.h" #include "image.h" #include "image-private.h" #include "jpeglib.h" static struct jpeg_error_mgr jerr; static struct jpeg_compress_struct cinfo; static JSAMPLE *sample; static int xpos; static int xwidth; static void image_jpg_begin(width, height) int width, height; { cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, stdout); cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); sample = (JSAMPLE *)malloc(width * 3 * sizeof (char)); xpos = 0; xwidth = width; } static void image_jpg_write_rgb(rgb) rgb_t *rgb; { memcpy((char *)sample + 3 * xpos, rgb, 3); xpos++; if (xpos >= xwidth) { JSAMPROW row_pointer[1]; row_pointer[0] = sample; jpeg_write_scanlines(&cinfo, row_pointer, 1); xpos = 0; } } static void image_jpg_end() { jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); free(sample); } struct image_class image_jpg_class = { IMAGE_TYPE_JPG, image_jpg_begin, image_jpg_write_rgb, image_jpg_end }; --- NEW FILE: image-private.h --- struct image_class { const char *type; void (*begin)(int width, int height); void (*write_rgb)(rgb_t *rgb); void (*end)(void); }; --- NEW FILE: image.c --- #include <stdio.h> #include <stdlib.h> #include "compat/err.h" #include "image.h" #include "image-private.h" extern struct image_class image_png_class; extern struct image_class image_pnm_class; extern struct image_class image_jpg_class; static struct image_class *selected_class = &image_png_class; static struct image_class *known_classes[] = { &image_png_class, &image_pnm_class, &image_jpg_class }; static int samples_remaining; void image_set_type(type) const char *type; { int i; for (i = 0; i < sizeof known_classes / sizeof *known_classes; i++) if (strcmp(type, known_classes[i]->type) == 0) { selected_class = known_classes[i]; return; } errx(1, "image_set_type: unknown type %s", type); } const char * image_get_type() { return selected_class->type; } void image_begin(w, h) int w, h; { (*selected_class->begin)(w,h); samples_remaining = w * h; } void image_write_rgb(rgb) rgb_t *rgb; { if (samples_remaining <= 0) warnx("image_write_rgb: Too many samples!"); (*selected_class->write_rgb)(rgb); samples_remaining--; } void image_write3(r, g, b) unsigned char r, g, b; { rgb_t rgb = { r, g, b }; image_write_rgb(&rgb); } void image_end() { if (samples_remaining != 0) warnx("image_end: Too few samples written (%d more)!", samples_remaining); (*selected_class->end)(); fflush(stdout); } Index: image-png.c =================================================================== RCS file: /cvsroot/meshdb/src/geo/libgeo/image-png.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- image-png.c 24 Nov 2003 07:04:49 -0000 1.2 +++ image-png.c 21 Jan 2005 16:05:23 -0000 1.2.2.1 @@ -4,6 +4,7 @@ #include "compat/err.h" #include "png.h" #include "image.h" +#include "image-private.h" #ifndef png_jmpbuf # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) @@ -14,8 +15,8 @@ static int width, height; static int xpos, xmax; -void -image_begin(w, h) +static void +image_png_begin(w, h) int w, h; { int i; @@ -29,8 +30,8 @@ xpos = 0; } -void -image_write_rgb(rgb) +static void +image_png_write_rgb(rgb) rgb_t *rgb; { if (xpos < xmax) { @@ -44,15 +45,7 @@ } void -image_write3(r, g, b) - unsigned char r, g, b; -{ - rgb_t rgb = { r, g, b }; - image_write_rgb(&rgb); -} - -void -image_end() +image_png_end() { png_structp png_ptr; png_infop info_ptr; @@ -81,10 +74,18 @@ info_ptr->color_type = PNG_COLOR_TYPE_RGB; info_ptr->interlace_type = PNG_INTERLACE_ADAM7; png_set_rows(png_ptr, info_ptr, rows); - png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION); png_write_png(png_ptr, info_ptr, NULL, NULL); png_destroy_write_struct(&png_ptr, &info_ptr); free(rows); free(data); } + +struct image_class image_png_class = { + IMAGE_TYPE_PNG, + image_png_begin, + image_png_write_rgb, + image_png_end +}; + Index: image-ppm.c =================================================================== RCS file: /cvsroot/meshdb/src/geo/libgeo/image-ppm.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -d -r1.1.1.1 -r1.1.1.1.2.1 --- image-ppm.c 10 Aug 2002 03:51:32 -0000 1.1.1.1 +++ image-ppm.c 21 Jan 2005 16:05:24 -0000 1.1.1.1.2.1 @@ -1,30 +1,29 @@ #include <stdio.h> #include "image.h" +#include "image-private.h" -void -image_begin(width, height) +static void +pnm_image_begin(width, height) int width, height; { printf("P6\n%u %u 255\n", width, height); } -void -image_write_rgb(rgb) +static void +pnm_image_write_rgb(rgb) rgb_t *rgb; { fwrite(rgb, sizeof *rgb, 1, stdout); } -void -image_write3(r, g, b) - unsigned char r, g, b; +static void +pnm_image_end() { - rgb_t rgb = { r, g, b }; - image_write_rgb(&rgb); } -void -image_end() -{ - fflush(stdout); -} +struct image_class image_pnm_class = { + IMAGE_TYPE_PNM, + pnm_image_begin, + pnm_image_write_rgb, + pnm_image_end +}; Index: image.h =================================================================== RCS file: /cvsroot/meshdb/src/geo/libgeo/image.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -d -r1.1.1.1 -r1.1.1.1.2.1 --- image.h 10 Aug 2002 03:51:32 -0000 1.1.1.1 +++ image.h 21 Jan 2005 16:05:25 -0000 1.1.1.1.2.1 @@ -8,3 +8,9 @@ void image_write_rgb(rgb_t *rgb); void image_write3(unsigned char r, unsigned char g, unsigned char b); void image_end(void); + +#define IMAGE_TYPE_PNM "image/pnm" +#define IMAGE_TYPE_PNG "image/png" +#define IMAGE_TYPE_JPG "image/jpeg" +void image_set_type(const char *); +const char *image_get_type(void); Index: Makefile.am =================================================================== RCS file: /cvsroot/meshdb/src/geo/libgeo/Attic/Makefile.am,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- Makefile.am 7 Nov 2004 12:16:34 -0000 1.1.2.2 +++ Makefile.am 21 Jan 2005 16:05:25 -0000 1.1.2.3 @@ -4,5 +4,5 @@ lib_LIBRARIES = libgeo.a libgeo_a_SOURCES = alt.c qt.c ntv2.c spread.c geodesy.c vincenty.c inclin.c -libgeo_a_SOURCES += image-png.c +libgeo_a_SOURCES += image.c image-ppm.c image-png.c image-jpeg.c |