[Python-modules-commits] [gamera] 01/03: Imported Upstream version 3.4.2+svn1435

Daniel Stender danstender-guest at moszumanska.debian.org
Fri Jun 5 17:18:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

danstender-guest pushed a commit to branch master
in repository gamera.

commit 56743860d5ed7c3ed87c84d801455ac5107ba9be
Author: Daniel Stender <debian at danielstender.com>
Date:   Fri Jun 5 16:08:22 2015 +0200

    Imported Upstream version 3.4.2+svn1435
---
 CHANGES                          |   5 ++
 include/pixel.hpp                |  54 ++++++++++++
 include/plugins/png_support.hpp  | 184 +++++++++++++++++++++++----------------
 include/plugins/tiff_support.hpp |   7 --
 include/utility.hpp              |  10 ++-
 5 files changed, 178 insertions(+), 82 deletions(-)

diff --git a/CHANGES b/CHANGES
index 2523914..9f6a19f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
 Changes made between Gamera File Releases
 =========================================
 
+ - fixed error in reading/writing 16bit greyscale PNG images
+
+ - 16bit RGB PNG images now supported via downscaling
+   (fixes Debian bug #785548)
+
  - reading of tiff images more error robust
    (fixes Debian bug #784795)
 
diff --git a/include/pixel.hpp b/include/pixel.hpp
index 0d0b562..db27273 100644
--- a/include/pixel.hpp
+++ b/include/pixel.hpp
@@ -46,6 +46,7 @@
 #include "vigra/rgbvalue.hxx"
 #include "vigra/colorconversions.hxx"
 #include <complex>
+//#include <stdint.h>
 
 using namespace vigra;
 
@@ -78,6 +79,59 @@ namespace Gamera {
    * The Gamera::Grey16Pixel type is for 16bit greyscale images.
    */
   typedef unsigned int Grey16Pixel;
+  /*
+  // This does not work because OneBit pixel is already of this type:
+  //typedef unsigned short Grey16Pixel;
+  //typedef uint16_t Grey16Pixel;
+  */
+  /*
+  // For some reason, VIGRA does not work with user-defined pixel types:
+  struct Grey16Pixel {
+    short value;
+    Grey16Pixel(int v) {value=short(v);}
+    Grey16Pixel() {value=0;}
+    short operator=(Grey16Pixel n) {return value=n.value;}
+    short operator=(short n) {return value=n;}
+    short operator=(int n) {return value=short(n);}
+    bool operator==(Grey16Pixel n) {return value==n.value;}
+    bool operator==(short n) {return value==n;}
+    bool operator==(int n) {return value==(short)n;}
+    short operator-=(Grey16Pixel n) {return value-=n.value;}
+    short operator-=(short n) {return value-=n;}
+    short operator-=(int n) {return value-=(short)n;}
+    short operator+=(Grey16Pixel n) {return value+=n.value;}
+    short operator+=(short n) {return value+=n;}
+    short operator+=(int n) {return value+=(short)n;}
+    bool operator>(Grey16Pixel n) {return value>n.value;}
+    bool operator>(short n) {return value>n;}
+    bool operator>(int n) {return value>(short)n;}
+    bool operator>=(Grey16Pixel n) {return value>=n.value;}
+    bool operator>=(short n) {return value>=n;}
+    bool operator>=(int n) {return value>=(short)n;}
+    bool operator<(Grey16Pixel n) {return value<n.value;}
+    bool operator<(short n) {return value<n;}
+    bool operator<(int n) {return value<(short)n;}
+    bool operator<=(Grey16Pixel n) {return value<=n.value;}
+    bool operator<=(short n) {return value<=n;}
+    bool operator<=(int n) {return value<=(short)n;}
+    short operator-(short n) {return value-n;}
+    short operator+(short n) {return value+n;}
+    short operator*(short n) {return value*n;}
+    double operator*(double n) {return value*n;}
+    short operator/(short n) {return value*n;}
+    //int operator() {return value;}
+    operator short() {return value;}
+    operator short*() {return &value;}
+    operator int() {return value;}
+    operator long int() {return value;}
+    int operator++() {return value++;}
+    int operator--() {return value--;}
+    //operator&() {return &value;}
+  };
+  int operator*(double x, Grey16Pixel p) {return int(x*p.value);}
+  int operator*(int x, Grey16Pixel p) {return x*p.value;}
+  long int operator*(long int x, Grey16Pixel p) {return x*p.value;}
+  */
 
   /**
    * OneBitPixel
diff --git a/include/plugins/png_support.hpp b/include/plugins/png_support.hpp
index 66e10d5..73868d0 100644
--- a/include/plugins/png_support.hpp
+++ b/include/plugins/png_support.hpp
@@ -1,7 +1,7 @@
 /*
  *
- * Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom,
- * and Karl MacMillan
+ * Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom, Karl MacMillan
+ *               2015      Christoph Dalitz
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -28,6 +28,7 @@
 #include "image_utilities.hpp"
 #include <png.h>
 #include <stdio.h>
+#include <stdint.h>
 
 // TODO: Get/Save resolution information
 
@@ -52,7 +53,7 @@ void PNG_info_specific(const char* filename, FILE* & fp, png_structp& png_ptr, p
     throw std::runtime_error("Not a PNG file");
   }
   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
-				   NULL, NULL);
+                   NULL, NULL);
   if (!png_ptr) {
     fclose(fp);
     throw std::runtime_error("Could not read PNG header");
@@ -125,7 +126,7 @@ ImageInfo* PNG_info(char* filename) {
     info->m_x_resolution = x_resolution;
     info->m_y_resolution = y_resolution;
     if (color_type == PNG_COLOR_TYPE_PALETTE || color_type == PNG_COLOR_TYPE_RGB ||
-	color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+    color_type == PNG_COLOR_TYPE_RGB_ALPHA)
       info->m_ncolors = 3;
     else if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
       info->m_ncolors = 1;
@@ -145,6 +146,28 @@ void load_PNG_simple(T& image, png_structp& png_ptr) {
 }
 
 template<class T>
+void load_PNG_grey16(T& image, png_structp& png_ptr) {
+  uint16_t* row = new uint16_t[image.ncols()];
+  if (byte_order_little_endian())
+    png_set_swap(png_ptr);
+  try {
+    typename T::row_iterator r = image.row_begin();
+    for (; r != image.row_end(); ++r) {
+      png_read_row(png_ptr, (png_bytep)row, NULL);
+      uint16_t* from = row;
+      typename T::col_iterator c = r.begin();
+      for (; c != r.end(); ++c, ++from) {
+        c.set((int)*from);
+      }
+    }
+  } catch (std::exception e) {
+    delete[] row;
+    throw;
+  }
+  delete[] row;
+}
+
+template<class T>
 void load_PNG_onebit(T& image, png_structp& png_ptr) {
   png_set_invert_mono(png_ptr);
 #if PNG_LIBPNG_VER > 10399
@@ -161,10 +184,10 @@ void load_PNG_onebit(T& image, png_structp& png_ptr) {
       png_bytep from = row;
       typename T::col_iterator c = r.begin();
       for (; c != r.end(); ++c, ++from) {
-	if (*from)
-	  c.set(pixel_traits<OneBitPixel>::black());
-	else
-	c.set(pixel_traits<OneBitPixel>::white());
+        if (*from)
+          c.set(pixel_traits<OneBitPixel>::black());
+        else
+          c.set(pixel_traits<OneBitPixel>::white());
       }
     }
   } catch (std::exception e) {
@@ -203,45 +226,55 @@ Image* load_PNG(const char* filename, int storage) {
       PNG_close(fp, png_ptr, info_ptr, end_info);
       throw std::runtime_error("Pixel type must be OneBit to use RLE data.");
     }
+    if (bit_depth > 8) {
+#if PNG_LIBPNG_VER >= 10504
+      png_set_scale_16(png_ptr);
+#else
+      png_set_strip_16(png_ptr);
+#endif
+    }
+    else if (bit_depth < 8) {
+      png_set_expand(png_ptr);
+    }
     if (color_type == PNG_COLOR_TYPE_PALETTE)
       png_set_palette_to_rgb(png_ptr);
     typedef TypeIdImageFactory<RGB, DENSE> fact;
     fact::image_type* image =
       fact::create(Point(0, 0), Dim(width, height));
     load_PNG_simple(*image, png_ptr);
-	//Damon
-	image->resolution(reso);
-	//Damon: end	
+    //Damon
+    image->resolution(reso);
+    //Damon: end    
     PNG_close(fp, png_ptr, info_ptr, end_info);
     return image;
   } else if (color_type == PNG_COLOR_TYPE_GRAY ||
-	     color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+             color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
     if (bit_depth == 1) {
       if (storage == DENSE) {
-	typedef TypeIdImageFactory<ONEBIT, DENSE> fact;
-	fact::image_type* image =
-	  fact::create(Point(0, 0), Dim(width, height));
-	load_PNG_onebit(*image, png_ptr);
-	//Damon
-	image->resolution(reso);
-	//Damon: end	
-	PNG_close(fp, png_ptr, info_ptr, end_info);
-	return image;
+        typedef TypeIdImageFactory<ONEBIT, DENSE> fact;
+        fact::image_type* image =
+          fact::create(Point(0, 0), Dim(width, height));
+        load_PNG_onebit(*image, png_ptr);
+        //Damon
+        image->resolution(reso);
+        //Damon: end    
+        PNG_close(fp, png_ptr, info_ptr, end_info);
+        return image;
       } else {
-	typedef TypeIdImageFactory<ONEBIT, RLE> fact;
-	fact::image_type* image =
-	  fact::create(Point(0, 0), Dim(width, height));
-	load_PNG_onebit(*image, png_ptr);
-	//Damon
-	image->resolution(reso);
-	//Damon: end	
-	PNG_close(fp, png_ptr, info_ptr, end_info);
-	return image;
-      }	
+        typedef TypeIdImageFactory<ONEBIT, RLE> fact;
+        fact::image_type* image =
+          fact::create(Point(0, 0), Dim(width, height));
+        load_PNG_onebit(*image, png_ptr);
+        //Damon
+        image->resolution(reso);
+        //Damon: end    
+        PNG_close(fp, png_ptr, info_ptr, end_info);
+        return image;
+      } 
     } else if (bit_depth <= 8) {
       if (storage == RLE) {
-	PNG_close(fp, png_ptr, info_ptr, end_info);
-	throw std::runtime_error("Pixel type must be OneBit to use RLE data.");
+        PNG_close(fp, png_ptr, info_ptr, end_info);
+        throw std::runtime_error("Pixel type must be OneBit to use RLE data.");
       }
       if (bit_depth < 8) {
 #if PNG_LIBPNG_VER > 10399
@@ -252,25 +285,25 @@ Image* load_PNG(const char* filename, int storage) {
       }
       typedef TypeIdImageFactory<GREYSCALE, DENSE> fact_type;
       fact_type::image_type*
-	image = fact_type::create(Point(0, 0), Dim(width, height));
+        image = fact_type::create(Point(0, 0), Dim(width, height));
       load_PNG_simple(*image, png_ptr);
-	  //Damon
-	  image->resolution(reso);
-	  //Damon: end	
+      //Damon
+      image->resolution(reso);
+      //Damon: end  
       PNG_close(fp, png_ptr, info_ptr, end_info);
       return image;
     } else if (bit_depth == 16) {
       if (storage == RLE) {
-	PNG_close(fp, png_ptr, info_ptr, end_info);
-	throw std::runtime_error("Pixel type must be OneBit to use RLE data.");
+        PNG_close(fp, png_ptr, info_ptr, end_info);
+        throw std::runtime_error("Pixel type must be OneBit to use RLE data.");
       }
       typedef TypeIdImageFactory<GREY16, DENSE> fact_type;
       fact_type::image_type*
-	image = fact_type::create(Point(0, 0), Dim(width, height));
-      load_PNG_simple(*image, png_ptr);
-	  //Damon
-	  image->resolution(reso);
-	  //Damon: end	
+        image = fact_type::create(Point(0, 0), Dim(width, height));
+      load_PNG_grey16(*image, png_ptr);
+      //Damon
+      image->resolution(reso);
+      //Damon: end  
       PNG_close(fp, png_ptr, info_ptr, end_info);
       return image;
     }
@@ -297,15 +330,15 @@ struct PNG_saver<OneBitPixel> {
     try {
       typename T::row_iterator r = image.row_begin();
       for (; r != image.row_end(); ++r) {
-	png_bytep from = row;
-	typename T::col_iterator c = r.begin();
-	for (; c != r.end(); ++c, ++from) {
-	  if (is_black(c.get()))
-	    *from = 0;
-	  else
-	    *from = 255;
-	}
-	png_write_row(png_ptr, row);
+    png_bytep from = row;
+    typename T::col_iterator c = r.begin();
+    for (; c != r.end(); ++c, ++from) {
+      if (is_black(c.get()))
+        *from = 0;
+      else
+        *from = 255;
+    }
+    png_write_row(png_ptr, row);
       }
     } catch (std::exception e) {
       delete[] row;
@@ -330,12 +363,12 @@ struct PNG_saver<FloatPixel> {
     try {
       typename T::row_iterator r = image.row_begin();
       for (; r != image.row_end(); ++r) {
-	png_bytep from = row;
-	typename T::col_iterator c = r.begin();
-	for (; c != r.end(); ++c, ++from) {
-	  *from = (png_byte)(*c * max);
-	}
-	png_write_row(png_ptr, row);
+    png_bytep from = row;
+    typename T::col_iterator c = r.begin();
+    for (; c != r.end(); ++c, ++from) {
+      *from = (png_byte)(*c * max);
+    }
+    png_write_row(png_ptr, row);
       }
     } catch (std::exception e) {
       delete[] row;
@@ -360,12 +393,12 @@ struct PNG_saver<ComplexPixel> {
     try {
       typename T::row_iterator r = image.row_begin();
       for (; r != image.row_end(); ++r) {
-	png_bytep from = row;
-	typename T::col_iterator c = r.begin();
-	for (; c != r.end(); ++c, ++from) {
-	  *from = (png_byte)((*c).real() * max);
-	}
-	png_write_row(png_ptr, row);
+    png_bytep from = row;
+    typename T::col_iterator c = r.begin();
+    for (; c != r.end(); ++c, ++from) {
+      *from = (png_byte)((*c).real() * max);
+    }
+    png_write_row(png_ptr, row);
       }
     } catch (std::exception e) {
       delete[] row;
@@ -379,15 +412,18 @@ template<>
 struct PNG_saver<Grey16Pixel> {
   template<class T>
   void operator()(T& image, png_structp png_ptr) {
-    png_bytep row = new png_byte[image.ncols() * 2];
+    //png_bytep row = new png_byte[image.ncols() * 2];
+    uint16_t* row = new uint16_t[image.ncols()];
+    if (byte_order_little_endian())
+      png_set_swap(png_ptr);
     try {
       typename T::row_iterator r = image.row_begin();
       for (; r != image.row_end(); ++r) {
-	typename T::col_iterator c = r.begin();
-	unsigned short* from = (unsigned short *)row;
-	for (; c != r.end(); ++c, ++from)
-	  *from = (unsigned short)(*c && 0xffff);
-	png_write_row(png_ptr, row);
+        typename T::col_iterator c = r.begin();
+        uint16_t* from = (uint16_t*)row;
+        for (; c != r.end(); ++c, ++from)
+          *from = (uint16_t)(*c);
+        png_write_row(png_ptr, (png_bytep)row);
       }
     } catch (std::exception e) {
       delete[] row;
@@ -414,7 +450,7 @@ void save_PNG(T& image, const char* filename) {
     png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
     fclose(fp);
     throw std::runtime_error("Couldn't create PNG header");
-  }			
+  }         
 
   if (setjmp(png_jmpbuf(png_ptr))) {
     png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -435,8 +471,8 @@ void save_PNG(T& image, const char* filename) {
     bit_depth = image.depth();
   int color_type = (image.ncolors() == 3) ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_GRAY;
   png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, 
-	       PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
-	       PNG_FILTER_TYPE_DEFAULT);
+           PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+           PNG_FILTER_TYPE_DEFAULT);
   
   //Damon 
   png_uint_32 res_x = (png_uint_32)(image.resolution() / METER_PER_INCH);
diff --git a/include/plugins/tiff_support.hpp b/include/plugins/tiff_support.hpp
index 4516851..c7cde5d 100644
--- a/include/plugins/tiff_support.hpp
+++ b/include/plugins/tiff_support.hpp
@@ -229,13 +229,6 @@ namespace {
   };
 
 
-  // runtime test for endianness
-  // (safer and less cumbersome than querying compiler macros)
-  bool byte_order_little_endian() {
-    long numberone = 1;
-    return (*((char*)(&numberone)));
-  }
-
   template<>
   struct tiff_saver<OneBitPixel> {
     template<class T>
diff --git a/include/utility.hpp b/include/utility.hpp
index 1eb0752..05b8b94 100644
--- a/include/utility.hpp
+++ b/include/utility.hpp
@@ -1,6 +1,7 @@
 /*
  *
- * Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom, and Karl MacMillan
+ * Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom, Karl MacMillan
+ *               2015      Christoph Dalitz
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -28,6 +29,13 @@
 
 namespace Gamera {
 
+  // runtime test for endianness
+  // (safer and less cumbersome than querying compiler macros)
+  inline bool byte_order_little_endian() {
+    long numberone = 1;
+    return (*((char*)(&numberone)));
+  }
+
   inline void byte_swap32(unsigned char *ptr) {
     register unsigned char val;
     

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/gamera.git



More information about the Python-modules-commits mailing list