From: <ha...@us...> - 2010-03-06 08:52:26
|
Revision: 7001 http://octave.svn.sourceforge.net/octave/?rev=7001&view=rev Author: hauberg Date: 2010-03-06 08:52:20 +0000 (Sat, 06 Mar 2010) Log Message: ----------- Remove JPEG and PNG functions and as a result simplify build system Modified Paths: -------------- trunk/octave-forge/main/image/src/Makefile Removed Paths: ------------- trunk/octave-forge/main/image/src/Makeconf.in trunk/octave-forge/main/image/src/autogen.sh trunk/octave-forge/main/image/src/configure.base trunk/octave-forge/main/image/src/jpgread.cc trunk/octave-forge/main/image/src/jpgwrite.cc trunk/octave-forge/main/image/src/pngcanvas.h trunk/octave-forge/main/image/src/pngread.cc trunk/octave-forge/main/image/src/pngwrite.cc Deleted: trunk/octave-forge/main/image/src/Makeconf.in =================================================================== --- trunk/octave-forge/main/image/src/Makeconf.in 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/Makeconf.in 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,14 +0,0 @@ - -## Makeconf is automatically generated from Makeconf.base and Makeconf.add -## in the various subdirectories. To regenerate, use ./autogen.sh to -## create a new ./Makeconf.in, then use ./configure to generate a new -## Makeconf. - -@DEFHAVE_JPEG@ -@DEFHAVE_PNG@ -MKOCTFILE=@MKOCTFILE@ - -%.o: %.c ; $(MKOCTFILE) -c $< -%.o: %.f ; $(MKOCTFILE) -c $< -%.o: %.cc ; $(MKOCTFILE) -c $< -%.oct: %.cc ; $(MKOCTFILE) $< Modified: trunk/octave-forge/main/image/src/Makefile =================================================================== --- trunk/octave-forge/main/image/src/Makefile 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/Makefile 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,28 +1,9 @@ -sinclude Makeconf - -ifdef HAVE_JPEG - JPEG=jpgwrite.oct jpgread.oct -endif - -ifdef HAVE_PNG - PNG=pngread.oct pngwrite.oct -endif - all: __spatial_filtering__.oct __bilateral__.oct __custom_gaussian_smoothing__.oct \ __imboundary__.oct bwlabel.oct bwfill.oct rotate_scale.oct hough_line.oct \ - graycomatrix.oct deriche.oct __bwdist.oct nonmax_supress.oct \ - $(JPEG) $(PNG) + graycomatrix.oct deriche.oct __bwdist.oct nonmax_supress.oct -jpgread.oct: jpgread.cc - $(MKOCTFILE) $< -ljpeg +%.oct: %.cc + mkoctfile -Wall $< -jpgwrite.oct: jpgwrite.cc - $(MKOCTFILE) $< -ljpeg - -pngread.oct: pngread.cc - $(MKOCTFILE) $< -lpng - -pngwrite.oct: pngwrite.cc - $(MKOCTFILE) $< -lpng - -clean: ; -$(RM) *.o octave-core core *.oct *~ +clean: + rm -f *.o octave-core core *.oct *~ Deleted: trunk/octave-forge/main/image/src/autogen.sh =================================================================== --- trunk/octave-forge/main/image/src/autogen.sh 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/autogen.sh 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,27 +0,0 @@ -#! /bin/sh - -## Generate ./configure -rm -f configure.in -echo "dnl --- DO NOT EDIT --- Automatically generated by autogen.sh" > configure.in -cat configure.base >> configure.in -cat <<EOF >> configure.in - AC_OUTPUT(\$CONFIGURE_OUTPUTS) - dnl XXX FIXME XXX chmod is not in autoconf's list of portable functions - - echo " " - echo " \"\\\$prefix\" is \$prefix" - echo " \"\\\$exec_prefix\" is \$exec_prefix" - AC_MSG_RESULT([\$STATUS_MSG - -find . -name NOINSTALL -print # shows which toolboxes won't be installed -]) -EOF - -autoconf configure.in > configure.tmp -if [ diff configure.tmp configure > /dev/null 2>&1 ]; then - rm -f configure.tmp; -else - mv -f configure.tmp configure - chmod 0755 configure -fi -rm -f configure.in Deleted: trunk/octave-forge/main/image/src/configure.base =================================================================== --- trunk/octave-forge/main/image/src/configure.base 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/configure.base 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,64 +0,0 @@ -dnl The configure script is generated by autogen.sh from configure.base -dnl and the various configure.add files in the source tree. Edit -dnl configure.base and reprocess rather than modifying ./configure. - -dnl autoconf 2.13 certainly doesn't work! What is the minimum requirement? -AC_PREREQ(2.2) - -AC_INIT(configure.base) - -MKOCTFILE=mkoctfile -AC_SUBST(MKOCTFILE) - -dnl Strip on windows, don't strip on Mac OS/X or IRIX -dnl For the rest, you can force strip using MKOCTFILE="mkoctfile -s" -dnl or avoid strip using STRIP=: before ./configure -case "$canonical_host_type" in - powerpc-apple-darwin*|*-sgi-*) - STRIP=: - ;; - *-cygwin-*|*-mingw-*) - MKOCTFILE="$MKOCTFILE -s" - ;; -esac - -dnl Define the following macro: -dnl OF_CHECK_LIB(lib,fn,true,false,helpers) -dnl This is just like AC_CHECK_LIB, but it doesn't update LIBS -AC_DEFUN([OF_CHECK_LIB], -[save_LIBS="$LIBS" -AC_CHECK_LIB($1,$2,$3,$4,$5) -LIBS="$save_LIBS" -]) - -AC_DEFINE(have_jpeg) -AC_CHECK_HEADER(jpeglib.h, have_jpeg=yes, have_jpeg=no) -if test $have_jpeg = yes ; then - OF_CHECK_LIB(jpeg, jpeg_std_error, have_jpeg=yes, have_jpeg=no) - if test $have_jpeg = no ; then - IMAGESTATUS="libjpeg not found" - else - IMAGESTATUS="jpeg" - AC_SUBST(DEFHAVE_JPEG) - DEFHAVE_JPEG="HAVE_JPEG=1" - fi -else - IMAGESTATUS="jpeglib.h not found" -fi - -AC_DEFINE(have_png) -AC_CHECK_HEADER(png.h, have_png=yes, have_png=no) -if test $have_png = yes ; then - OF_CHECK_LIB(png, png_set_sig_bytes, have_png=yes, have_png=no) - if test $have_png = no ; then - IMAGESTATUS="$IMAGESTATUS, libpng not found" - else - IMAGESTATUS="$IMAGESTATUS, png" - AC_SUBST(DEFHAVE_PNG) - DEFHAVE_PNG="HAVE_PNG=1" - fi -else - IMAGESTATUS="$IMAGESTATUS, png.h not found" -fi - -CONFIGURE_OUTPUTS="Makeconf" Deleted: trunk/octave-forge/main/image/src/jpgread.cc =================================================================== --- trunk/octave-forge/main/image/src/jpgread.cc 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/jpgread.cc 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,183 +0,0 @@ - // - // This is a hack into octave - // based on jpgread.c by jpgread by Drea Thomas, The Mathworks and the - // examples in the IJG distribution. - // - // (C) 1998 Andy Adler. This code is in the public domain - // USE THIS CODE AT YOUR OWN RISK - // - // $Id$ - // - -/* Modified: Stefan van der Walt <st...@su...> - * Date: 27 January 2004 - * - Manual error handler to prevent segfaults in Octave. - * - Use uint8NDArray for output. - */ - -/* - * Compilation: - * First, try - * mkoctfile jpgread.cc -ljpeg - * - * If this doesn't work, install the jpeg library which is part of - * "The Independent JPEG Group's JPEG software" collection. - * - * The jpeg library came from - * - * ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6.tar.gz - * - * Extract and build the library: - * tar xvfz jpegsrc.v6.tar.gz - * cd jpeg-6b - * ./configure - * make - * make test - * - * Compile this file using: - * mkoctfile jpgread.cc -I<jpeg-6b include dir> -L<jpeg-6b lib dir> -ljpeg - */ - -#include <octave/oct.h> -#include <iostream> -#include <csetjmp> - -#ifdef __cplusplus -extern "C" { -#endif - -#include "jpeglib.h" - -#ifdef __cplusplus -} //extern "C" -#endif - -struct oct_error_mgr { - struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ -}; - -typedef struct oct_error_mgr * oct_error_ptr; - -METHODDEF(void) -oct_error_exit (j_common_ptr cinfo) -{ - /* cinfo->err really points to an oct_error_mgr struct, so coerce pointer */ - oct_error_ptr octerr = (oct_error_ptr) cinfo->err; - - /* Format error message and send to interpreter */ - char errmsg[JMSG_LENGTH_MAX]; - (octerr->pub.format_message)(cinfo, errmsg); - error("jpgread: %s", errmsg); - - /* Return control to the setjmp point */ - longjmp(octerr->setjmp_buffer, 1); -} - -DEFUN_DLD (jpgread, args, nargout , "\ --*- texinfo -*-\n\ -@deftypefn {Function File} {@var{I} =} jpgread(@var{filename})\n\ -Read a JPEG file from disk.\n\ -\n\ -For a grey-level image, the output is an MxN matrix. For a\n\ -colour image, three such matrices are returned (MxNx3),\n\ -representing the red, green and blue components. The output\n\ -is of class 'uint8'.\n\ -\n\ -@seealso{imread, im2double, im2gray, im2rgb}\n\ -@end deftypefn\n\ -") { - warning ("'jpgread' has been deprecated in favor of 'imread'. This function will be removed from future versions of the 'image' package."); - octave_value_list retval; - int nargin = args.length(); - - FILE * infile; - - JSAMPARRAY buffer; - long row_stride; - struct jpeg_decompress_struct cinfo; - struct oct_error_mgr jerr; - - // - // We bail out if the input parameters are bad - // - if ((nargin != 1) || !args(0).is_string() || (nargout != 1)) { - print_usage (); - return retval; - } - - // - // Open jpg file - // - std::string filename = args(0).string_value(); - if ((infile = fopen(filename.c_str(), "rb")) == NULL) { - error("jpgread: couldn't open file %s", filename.c_str()); - return retval; - } - - // - // Initialize the jpeg library - // - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = oct_error_exit; - if (setjmp(jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - jpeg_destroy_decompress(&cinfo); - fclose(infile); - return retval; - } - - jpeg_create_decompress(&cinfo); - - // - // Read the jpg header to get info about size and color depth - // - jpeg_stdio_src(&cinfo, infile); - jpeg_read_header(&cinfo, TRUE); - jpeg_start_decompress(&cinfo); - - // - // Allocate buffer for one scan line - // - row_stride = cinfo.output_width * cinfo.output_components; - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); - - // - // Create an NDArray for the output. Loop through each of the - // scanlines and copy the image data from the buffer. - // - - dim_vector dim = dim_vector(); - dim.resize(3); - dim(0) = cinfo.output_height; - dim(1) = cinfo.output_width; - dim(2) = cinfo.output_components; - uint8NDArray out = uint8NDArray(dim, 0); - - Array<int> coord = Array<int> (3); - for (unsigned long j=0; cinfo.output_scanline < cinfo.output_height; j++) { - jpeg_read_scanlines(&cinfo, buffer, 1); - - coord(0) = j; - for (unsigned long i=0; i<cinfo.output_width; i++) { - coord(1) = i; - for (int c = 0; c < cinfo.output_components; c++) { - coord(2) = c; - out(coord) = buffer[0][i*cinfo.output_components+c]; - } - } - } - retval.append(out.squeeze()); - - // - // Clean up - // - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - fclose(infile); - - return retval; -} Deleted: trunk/octave-forge/main/image/src/jpgwrite.cc =================================================================== --- trunk/octave-forge/main/image/src/jpgwrite.cc 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/jpgwrite.cc 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,258 +0,0 @@ - // This is a hack into octave - // based on jpgwrite.c by jpgread by Drea Thomas, The Mathworks, and the - // examples in the IJG distribution. - // - // (C) 1998 Andy Adler. This code is in the public domain - // USE THIS CODE AT YOUR OWN RISK - // - // $Id$ - // - -#include <octave/oct.h> -#include <iostream> - -#ifdef __cplusplus -extern "C" { -#endif - -#include "jpeglib.h" - -#ifdef __cplusplus -} //extern "C" -#endif - -#define GRAYIMAGES - -/* - * Simple jpeg writing MEX-file. - * - * Synopsis: - * jpgwrite(filename,r,g,b,quality) - * - * Compilation: - * First, try - * mkoctfile jpgwrite.cc -ljpeg - * - * If this doesn't work, then do - * - * Calls the jpeg library which is part of - * "The Independent JPEG Group's JPEG software" collection. - * - * The jpeg library came from, - * - * ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6.tar.gz - */ - -DEFUN_DLD (jpgwrite, args, , "\ --*- texinfo -*-\n\ -@deftypefn {Function File} jpgwrite(@var{filename}, @var{R}, @var{G}, @var{B}, @var{quality})\n\ -@deftypefnx{Function File} jpgwrite(@var{filename}, @var{I}, @var{quality})\n\ -Write a JPEG file to disc.\n\ -\n\ -If three matrices @var{R}, @var{G}, and @var{B} are given the function will write\n\ -a color image to the disc, where @var{R} is the red channel, @var{G} the green channel,\n\ -and @var{B} the blue channel of the image.\n\ -\n\ -If only one matrix @var{I} is given the function writes a gray-scale image to the disc.\n\ -\n\ -In all cases the data matrices should have integer values between 0 and 255.\n\ -\n\ -If specified, @var{quality} should be in the range 1-100 and will default to\n\ -75 if not specified. 100 is best quality, and 1 is best compression.\n\ -@seealso{jpgread, imwrite}\n\ -@end deftypefn\n\ -") { - warning ("'jpgwrite' has been deprecated in favor of 'imwrite'. This function will be removed from future versions of the 'image' package."); - octave_value_list retval; - int nargin = args.length(); - - FILE * outfile; - - JSAMPARRAY buffer; - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; - int quality=75; //default value - -// -// We bail out if the input parameters are bad -// - if (nargin < 2 || !args(0).is_string() ) { - print_usage (); - return retval; - } - - -// -// Open jpg file -// - std::string filename = args(0).string_value(); - if ((outfile = fopen(filename.c_str(), "wb")) == NULL) { - error("Couldn't open file"); - return retval; - } - -// -// Set Jpeg parameters -// - if (nargin == 3) { - quality= (int) args(2).double_value(); - } else if (nargin == 5) { - quality= (int) args(4).double_value(); - } - -// -// Initialize the jpeg library -// Read the jpg header to get info about size and color depth -// - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_compress(&cinfo); - jpeg_stdio_dest(&cinfo, outfile); - - -// -// set parameters for compression -// - - if ( nargin <= 3 ) { -// -// we're here because only one matrix of grey scale values was provided -// - Matrix avg= args(1).matrix_value(); - long image_width = args(1).columns(); - long image_height = args(1).rows(); - - - cinfo.image_width = image_width; /* image width and height, in pixels */ - cinfo.image_height = image_height; -#ifdef GRAYIMAGES - cinfo.input_components = 1; - cinfo.input_components = JCS_GRAYSCALE; -#else - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; -#endif - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); -// -// start compressor -// - jpeg_start_compress(&cinfo, TRUE); - -// -// Allocate buffer for one scan line -// - long row_stride = image_width * cinfo.input_components ; - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); -// -// Now, loop thru each of the scanlines. For each, copy the image -// data from the buffer, data must be [0 255] -// - for( long j=0; cinfo.next_scanline < cinfo.image_height; j++) { - for(unsigned long i=0; i<cinfo.image_width; i++) { -#ifdef GRAYIMAGES - buffer[0][i] = (unsigned char) avg(j,i); -#else - buffer[0][i*3+0] = (unsigned char) avg(j,i); - buffer[0][i*3+1] = (unsigned char) avg(j,i); - buffer[0][i*3+2] = (unsigned char) avg(j,i); -#endif - } - jpeg_write_scanlines(&cinfo, buffer,1); - } - - } // if nargin <= 3 - else { -// -// we're here because red green and blue matrices were provided -// we assume that they're the same size -// - Matrix red = args(1).matrix_value(); - Matrix green= args(2).matrix_value(); - Matrix blue = args(3).matrix_value(); - long image_width = args(1).columns(); - long image_height = args(1).rows(); - - if ( args(2).columns() != image_width || - args(3).columns() != image_width || - args(2).rows() != image_height || - args(3).rows() != image_height ) { - error("R,G,B matrix sizes aren't the same"); - return retval; - } - - cinfo.image_width = image_width; /* image width and height, in pixels */ - cinfo.image_height = image_height; - cinfo.input_components = 3; /* # of color components per pixel */ - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, quality, TRUE ); -// -// start compressor -// - jpeg_start_compress(&cinfo, TRUE); - -// -// Allocate buffer for one scan line -// - long row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); -// -// Now, loop thru each of the scanlines. For each, copy the image -// data from the buffer, data must be [0 255] -// - for( long j=0; cinfo.next_scanline < cinfo.image_height; j++) { - for(unsigned long i=0; i<cinfo.image_width; i++) { - buffer[0][i*3+0] = (unsigned char) red(j,i); - buffer[0][i*3+1] = (unsigned char) green(j,i); - buffer[0][i*3+2] = (unsigned char) blue(j,i); - } - jpeg_write_scanlines(&cinfo, buffer,1); - } - - } // else nargin > 3 - -// -// Clean up -// - - jpeg_finish_compress(&cinfo); - fclose(outfile); - jpeg_destroy_compress(&cinfo); - - - return retval; - -} - -/* - -%!test -%! if exist("jpgwrite","file") -%! ## build test image for r/w tests -%! x=linspace(-8,8,200); -%! [xx,yy]=meshgrid(x,x); -%! r=sqrt(xx.^2+yy.^2) + eps; -%! map=colormap(hsv); -%! A=sin(r)./r; -%! minval = min(A(:)); -%! maxval = max(A(:)); -%! z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1; -%! Rw=Gw=Bw=z; -%! Rw(:)=fix(255*map(z,1)); -%! Gw(:)=fix(255*map(z,2)); -%! Bw(:)=fix(255*map(z,3)); -%! Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners -%! jpgwrite('test.jpg',Rw,Gw,Bw); -%! stats=stat("test.jpg"); -%! assert(stats.size,6423); -%! im = jpgread('test.jpg'); -%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); -%! assert(all(Rw(:)-double(Rr(:))<35)); -%! assert(all(Gw(:)-double(Gr(:))<35)); -%! assert(all(Bw(:)-double(Br(:))<35)); -%! unlink('test.jpg'); -%! endif - -*/ Deleted: trunk/octave-forge/main/image/src/pngcanvas.h =================================================================== --- trunk/octave-forge/main/image/src/pngcanvas.h 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/pngcanvas.h 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,75 +0,0 @@ -/* - * readpng.h - * - * Copyright (C) 2003 Nadav Rotem <nad...@ho...> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Modified: Stefan van der Walt <st...@su...> - * Date: 28 January 2005 - * - Fix bugs, restructure - */ - -typedef struct -{ - int width; - int height; - int bit_depth; - int color_type; - unsigned char **row_pointers; -} canvas; - -//////////////Libcanvas/////////// -canvas *new_canvas(int width, int height, int stride) -{ - // Default stride if none given - if (stride==0) stride=width*4; - - // Clean allocation of canvas structure - canvas *can=new(canvas); - unsigned char *image_data = new unsigned char[stride*height]; - unsigned char **row_pointers = new unsigned char *[height]; - if (can == NULL || image_data == NULL || row_pointers == NULL) - { - if (can == NULL) delete can; - if (image_data == NULL) delete[] image_data; - if (row_pointers == NULL) delete[] row_pointers; - return NULL; - } - - // Fill in canvas structure - can->width=width; - can->height=height; - can->bit_depth=8; - can->color_type=PNG_COLOR_TYPE_RGB_ALPHA; - can->row_pointers = row_pointers; - for (int i=0; i < height; i++) row_pointers[i] = image_data + i*stride; - - return can; -} - -void delete_canvas(canvas *can) -{ - - if (can!=NULL) - { - delete[] can->row_pointers[0]; - delete[] can->row_pointers; - delete can; - } - return; -} - Deleted: trunk/octave-forge/main/image/src/pngread.cc =================================================================== --- trunk/octave-forge/main/image/src/pngread.cc 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/pngread.cc 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,295 +0,0 @@ -/* - * pngread.cc - * - * Copyright (C) 2003 Nadav Rotem <nad...@ho...> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; If not, see <http://www.gnu.org/licenses/>. - */ - -/* - -Load PNG files to octave using libpng; - - PNG (Portable Network Graphics) is an extensible file format for the - lossless, portable, well-compressed storage of raster images. PNG pro- - vides a patent-free replacement for GIF and can also replace many com- - mon uses of TIFF. Indexed-color, grayscale, and truecolor images are - supported, plus an optional alpha channel. Sample depths range from 1 - to 16 bits. - -*/ - -/* - * Modified: Stefan van der Walt <st...@su...> - * Date: 28 January 2005 - * - Fix bugs, restructure - */ - -#include "png.h" -#include "pngcanvas.h" -#include <octave/oct.h> - -canvas *load_canvas(char *filename); - -DEFUN_DLD (pngread, args, nargout , -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{I}, @var{alpha}] =} pngread(@var{filename})\n\ -\n\ -Read a PNG file from disk.\n\ -\n\ -The image is returned as a matrix of dimension MxN (for grey-level images)\n\ -or MxNx3 (for colour images). The numeric type of @var{I} and @var{alpha}\n\ -is @code{uint8} for grey-level and RGB images, or @code{logical} for\n\ -black-and-white images.\n\ -\n\ -@end deftypefn\n\ -@seealso{imread}") -{ - warning ("'pngread' has been deprecated in favor of 'imread'. This function will be removed from future versions of the 'image' package."); - octave_value_list retval; - int nargin = args.length(); - - // - // We bail out if the input parameters are bad - // - if (nargin != 1 || !args(0).is_string()) { - print_usage (); - return retval; - } - - // - // Load png file - // - canvas *pic=load_canvas((char *)args(0).string_value().c_str()); - if (!pic) return retval; - - dim_vector dim = dim_vector(); - dim.resize(3); - dim(0) = pic->height; - dim(1) = pic->width; - dim(2) = 3; - - if ( (pic->color_type == PNG_COLOR_TYPE_GRAY) || - (pic->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || - ((pic->color_type == PNG_COLOR_TYPE_PALETTE) && (pic->bit_depth == 1)) ) - dim(2) = 1; - - if (pic->bit_depth > 1 && pic->bit_depth < 8) - pic->bit_depth = 8; //this should never happen according to load_canvas code - - int isAlfaChannelPresent = 0; - if ( pic->color_type & PNG_COLOR_MASK_ALPHA) - isAlfaChannelPresent=1; - - - NDArray out(dim); - - dim.resize(2); - NDArray alpha(dim); - - Array<int> coord = Array<int> (3); - - int major_byte, minor_byte,row_pxl_position; - /* calculate the number of color channels (including alpha) per pixel */ - int ElementsPerPixel=out.dims()(2)+isAlfaChannelPresent; - for (unsigned long j=0; j < pic->height; j++) { - coord(0) = j; - for (unsigned long i=0; i < pic->width; i++) { - coord(1) = i; - - for (int c = 0; c < out.dims()(2); c++) { - coord(2) = c; - switch(pic->bit_depth) { - case 8: - row_pxl_position=(i*ElementsPerPixel+c); - out(coord) = pic->row_pointers[j][row_pxl_position]; - break; - case 16: - // converting big endian - row_pxl_position=2*(i*ElementsPerPixel+c); - major_byte=pic->row_pointers[j][row_pxl_position]; - minor_byte=pic->row_pointers[j][row_pxl_position+1] ; - out(coord) = major_byte*256+minor_byte; - break; - default: - printf("do not know how to handle bit depth of %d\n",pic->bit_depth); - } - } - if (isAlfaChannelPresent) { // it always should according to load canvas code - switch(pic->bit_depth) { - case 8: - row_pxl_position=(i*ElementsPerPixel+ElementsPerPixel-1); - alpha(j,i) = pic->row_pointers[j][row_pxl_position]; - break; - case 16: - // converting big endian - row_pxl_position=2*(i*ElementsPerPixel+ElementsPerPixel-1); - major_byte = pic->row_pointers[j][row_pxl_position]; - minor_byte = pic->row_pointers[j][row_pxl_position+1]; - alpha(j,i) = major_byte*256+minor_byte; - break; - default: - printf("do not know how to handle bit depth of %d\n",pic->bit_depth); - } - } else { - alpha(j,i) = 255; - } - } - } - out = out.squeeze(); - - switch (pic->bit_depth) { - case 1: - retval.append((boolNDArray)out); - retval.append((boolNDArray)alpha); - break; - case 8: - retval.append((uint8NDArray)out); - retval.append((uint8NDArray)alpha); - break; - case 16: - retval.append((uint16NDArray)out); - retval.append((uint16NDArray)alpha); - break; - default: - retval.append(out); - retval.append(alpha); - } - - delete_canvas(pic); - return retval; -} - -canvas *load_canvas(char *filename) -{ - png_structp png_ptr; - png_infop info_ptr; - - FILE *infile = fopen(filename,"rb"); - if (!infile) { - error("pngread could not open file %s", filename); - return NULL; - } - - unsigned char sig[8]; - const size_t bytes_read = fread (sig, 1, 8, infile); - if (!png_check_sig (sig, 8) || bytes_read != 8) { - error ("pngread invalid signature in %s", filename); - fclose (infile); - return NULL; - } - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL); - if (!png_ptr) { - error("pngread out of memory"); - fclose(infile); - return NULL; - } - - info_ptr = png_create_info_struct(png_ptr); - if(!info_ptr) { - error("pngread can't generate info"); - png_destroy_read_struct(&png_ptr,NULL,NULL); - fclose(infile); - return NULL; - } - - /* Set error handling */ - if (setjmp(png_jmpbuf(png_ptr))) { - error("pngread: libpng exited abnormally"); - png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); - fclose(infile); - return NULL; - } - - png_init_io(png_ptr, infile); - png_set_sig_bytes(png_ptr, 8); - png_read_info(png_ptr, info_ptr); - - png_uint_32 width,height; - int color_type, bit_depth; - png_get_IHDR(png_ptr,info_ptr,&width,&height, - &bit_depth,&color_type,NULL,NULL,NULL); - - /* Transform grayscale images with depths < 8-bit to 8-bit, change - * paletted images to RGB, and add a full alpha channel if there is - * transparency information in a tRNS chunk. - */ - if (color_type == PNG_COLOR_TYPE_PALETTE) { - png_set_palette_to_rgb(png_ptr); - } - if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { - png_set_gray_1_2_4_to_8(png_ptr); // this function deprecated need to be redone - bit_depth=8; - info_ptr->bit_depth=bit_depth; - } - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { //add alpha - png_set_tRNS_to_alpha(png_ptr); - } - - // Always transform image to RGB - if (color_type == PNG_COLOR_TYPE_GRAY - || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb(png_ptr); - color_type= (color_type | PNG_COLOR_MASK_COLOR); - info_ptr->color_type=color_type; - } - - // If no alpha layer is present, create one - if (!(color_type & PNG_COLOR_MASK_ALPHA)) - { - png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); - color_type= (color_type | PNG_COLOR_MASK_ALPHA); - info_ptr->color_type=color_type; - } - - if (bit_depth < 8) { - png_set_packing(png_ptr); - bit_depth=8; - info_ptr->bit_depth=bit_depth; - } - - // Hey! Our signal could be small and in the lower bits, - // leave our data alone and do not decrease accuracy - // 16 -> 8 bits commented out - // For now, use 8-bit only - //if (bit_depth == 16) { - //png_set_strip_16(png_ptr); - //bit_depth=8; - //info_ptr->bit_depth=bit_depth; - //} - - png_read_update_info(png_ptr,info_ptr); - - // Read the data from the file - int stride = png_get_rowbytes(png_ptr, info_ptr); - canvas *can = new_canvas(width, height, stride); - - if (can) { - png_read_image(png_ptr, can->row_pointers); - } else { - error("pngread out of memory"); - } - - png_read_end(png_ptr,NULL); - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); - - fclose(infile); - - // Set color type and depth. Used to determine octave output arguments. - can->color_type = color_type; - can->bit_depth = bit_depth; - return can; -} Deleted: trunk/octave-forge/main/image/src/pngwrite.cc =================================================================== --- trunk/octave-forge/main/image/src/pngwrite.cc 2010-03-05 23:45:42 UTC (rev 7000) +++ trunk/octave-forge/main/image/src/pngwrite.cc 2010-03-06 08:52:20 UTC (rev 7001) @@ -1,205 +0,0 @@ -/* - * pngwrite.cc - * - * Copyright (C) 2003 Nadav Rotem <nad...@ho...> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; If not, see <http://www.gnu.org/licenses/>. - */ - -/* - -Write PNG files to disk from octave - - PNG (Portable Network Graphics) is an extensible file format for the - lossless, portable, well-compressed storage of raster images. PNG pro- - vides a patent-free replacement for GIF and can also replace many com- - mon uses of TIFF. Indexed-color, grayscale, and truecolor images are - supported, plus an optional alpha channel. Sample depths range from 1 - to 16 bits. - -*/ - -/* - * Modified: Stefan van der Walt <st...@su...> - * Date: 28 January 2005 - * - Fix bugs, restructure - */ - -#include "png.h" -#include "pngcanvas.h" -#include <octave/oct.h> - -void save_canvas(canvas *can, char *filename); - -DEFUN_DLD (pngwrite, args, ,"\ --*- texinfo -*-\n\ -@deftypefn {Function File} pngwrite(@var{filename}, @var{R}, @var{G}, @var{B}, @var{A})\n\ -Writes a png file to the disk using the Red, Green, Blue and Alpha matrices.\n\ -\n\ -Data must be [0 255] or the high bytes will be lost.\n\ -@seealso{imwrite}\n\ -@end deftypefn\n\ -") { - warning ("'pngwrite' has been deprecated in favor of 'imwrite'. This function will be removed from future versions of the 'image' package."); - octave_value_list retval; - int nargin = args.length(); - - // - // We bail out if the input parameters are bad - // - if (nargin < 5 || !args(0).is_string() ) { - print_usage (); - return retval; - } - - Matrix red = args(1).matrix_value(); - Matrix green= args(2).matrix_value(); - Matrix blue = args(3).matrix_value(); - Matrix alpha= args(4).matrix_value(); - - long image_width = args(1).columns(); - long image_height = args(1).rows(); - - if ( args(2).columns() != image_width || - args(3).columns() != image_width || - args(4).columns() != image_width || - args(2).rows() != image_height || - args(3).rows() != image_height || - args(4).rows() != image_height ) - { - error("pngwrite R,G,B,A matrix sizes aren't the same"); - return retval; - } - - canvas *pic=new_canvas(image_width, image_height, image_width*4); - if (!pic) { - error("pngwrite out of memory"); - return retval; - } - - for(int i=0; i < pic->width; i++) { - for(int j=0; j < pic->height; j++) { - pic->row_pointers[j][i*4+0]=(unsigned char)(red(j,i)); - pic->row_pointers[j][i*4+1]=(unsigned char)(green(j,i)); - pic->row_pointers[j][i*4+2]=(unsigned char)(blue(j,i)); - pic->row_pointers[j][i*4+3]=(unsigned char)(alpha(j,i)); - } - } - - - save_canvas(pic,(char *)args(0).string_value().c_str()); - delete_canvas(pic); - - return retval; -} - -void save_canvas(canvas *can,char *filename) -{ - FILE *fp; - png_structp png_ptr; - png_infop info_ptr; - - fp = fopen(filename, "wb"); - if (fp == NULL) { - error("pngwrite could not open %s", filename); - return; - } - - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) { - fclose(fp); - error("pngwrite: cannot create write structure"); - return; - } - - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - fclose(fp); - error("pngwrite: cannot not create image structure"); - png_destroy_write_struct(&png_ptr, png_infopp_NULL); - return; - } - - if (setjmp(png_jmpbuf(png_ptr))) { - fclose(fp); - png_destroy_write_struct(&png_ptr, &info_ptr); - error("pngread: libpng exited abnormally"); - return; - } - - png_init_io(png_ptr, fp); - png_set_compression_level(png_ptr, 3); - - png_set_IHDR(png_ptr, info_ptr, can->width, can->height, - can->bit_depth, can->color_type, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - - png_set_gAMA(png_ptr, info_ptr, 0.7); - - time_t gmt; - png_time mod_time; - png_text text_ptr[2]; - time(&gmt); - png_convert_from_time_t(&mod_time, gmt); - png_set_tIME(png_ptr, info_ptr, &mod_time); - text_ptr[0].key = png_charp ("Created by"); - text_ptr[0].text = png_charp ("Octave"); - text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; - - png_set_text(png_ptr, info_ptr, text_ptr, 1); - - png_write_info(png_ptr, info_ptr); - png_write_image(png_ptr, can->row_pointers); - png_write_end(png_ptr, info_ptr); - png_destroy_write_struct(&png_ptr, &info_ptr); - fclose(fp); -} - -/* - -%!test -%! if exist("jpgwrite","file") -%! ## build test image for r/w tests -%! x=linspace(-8,8,200); -%! [xx,yy]=meshgrid(x,x); -%! r=sqrt(xx.^2+yy.^2) + eps; -%! map=colormap(hsv); -%! A=sin(r)./r; -%! minval = min(A(:)); -%! maxval = max(A(:)); -%! z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1; -%! Rw=Gw=Bw=z; -%! Rw(:)=fix(255*map(z,1)); -%! Gw(:)=fix(255*map(z,2)); -%! Bw(:)=fix(255*map(z,3)); -%! Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners -%! pngwrite('test.png',Rw,Gw,Bw,Aw); -%! stats=stat("test.png"); -%! assert(stats.size,24738); -%! im = pngread('test.png'); -%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); -%! assert(all(double(Rr(:))==Rw(:))); -%! assert(all(double(Gr(:))==Gw(:))); -%! assert(all(double(Br(:))==Bw(:))); -%! [im,Ar] = pngread('test.png'); -%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); -%! assert(all(double(Rr(:))==Rw(:))); -%! assert(all(double(Gr(:))==Gw(:))); -%! assert(all(double(Br(:))==Bw(:))); -%! assert(all(double(Ar(:))==Aw(:))); -%! unlink('test.png'); -%! endif - -*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |