Code

replace text strings by ints for tools/bounding_box
[inkscape.git] / src / sp-image.cpp
index d535874e93c34d8ba69d0b91bb6fa1774704474e..95e104b7652774de37739cd4266a38ea20e179d1 100644 (file)
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include <libnr/nr-matrix-fns.h>
 
+#include <cstring>
+#include <string>
+#include <libnr/nr-matrix-fns.h>
+#include <libnr/nr-matrix-ops.h>
+#include <libnr/nr-translate-matrix-ops.h>
+#include <libnr/nr-scale-translate-ops.h>
 //#define GDK_PIXBUF_ENABLE_BACKEND 1
 //#include <gdk-pixbuf/gdk-pixbuf-io.h>
 #include "display/nr-arena-image.h"
@@ -231,17 +236,17 @@ void user_read_data( png_structp png_ptr, png_bytep data, png_size_t length )
 //    g_message("things out");
 }
 
-void user_write_data( png_structp png_ptr, png_bytep data, png_size_t length )
+void user_write_data( png_structp /*png_ptr*/, png_bytep /*data*/, png_size_t /*length*/ )
 {
     //g_message( "user_write_data(%d)", length );
 }
 
-void user_flush_data( png_structp png_ptr )
+void user_flush_data( png_structp /*png_ptr*/ )
 {
     //g_message( "user_flush_data" );
 }
 
-GdkPixbuf*  pixbuf_new_from_file( const char *filename, GError **error )
+GdkPixbuf*  pixbuf_new_from_file( const char *filename, GError **/*error*/ )
 {
     GdkPixbuf* buf = NULL;
     PushPull youme;
@@ -361,12 +366,64 @@ GdkPixbuf*  pixbuf_new_from_file( const char *filename, GError **error )
                                 }
 */
 
+#if defined(PNG_sRGB_SUPPORTED)
+                                {
+                                    int intent = 0;
+                                    if ( png_get_sRGB(pngPtr, infoPtr, &intent) ) {
+//                                         g_message("Found an sRGB png chunk");
+                                    }
+                                }
+#endif // defined(PNG_sRGB_SUPPORTED)
+
+#if defined(PNG_cHRM_SUPPORTED)
+                                {
+                                    double white_x = 0;
+                                    double white_y = 0;
+                                    double red_x = 0;
+                                    double red_y = 0;
+                                    double green_x = 0;
+                                    double green_y = 0;
+                                    double blue_x = 0;
+                                    double blue_y = 0;
+
+                                    if ( png_get_cHRM(pngPtr, infoPtr,
+                                                      &white_x, &white_y,
+                                                      &red_x, &red_y,
+                                                      &green_x, &green_y,
+                                                      &blue_x, &blue_y) ) {
+//                                         g_message("Found a cHRM png chunk");
+                                    }
+                                }
+#endif // defined(PNG_cHRM_SUPPORTED)
+
+#if defined(PNG_gAMA_SUPPORTED)
+                                {
+                                    double file_gamma = 0;
+                                    if ( png_get_gAMA(pngPtr, infoPtr, &file_gamma) ) {
+//                                         g_message("Found a gAMA png chunk");
+                                    }
+                                }
+#endif // defined(PNG_gAMA_SUPPORTED)
+
+#if defined(PNG_iCCP_SUPPORTED)
+                                {
+                                    char* name = 0;
+                                    int compression_type = 0;
+                                    char* profile = 0;
+                                    png_uint_32 proflen = 0;
+                                    if ( png_get_iCCP(pngPtr, infoPtr, &name, &compression_type, &profile, &proflen) ) {
+//                                         g_message("Found an iCCP chunk named [%s] with %d bytes and comp %d", name, proflen, compression_type);
+                                    }
+                                }
+#endif // defined(PNG_iCCP_SUPPORTED)
+
+
                                 // now clean it up.
                                 png_destroy_read_struct( &pngPtr, &infoPtr, NULL );//&endPtr );
                             }
                             else
                             {
-                                g_message("Error when creating PNG read struct");
+//                                 g_message("Error when creating PNG read struct");
                             }
                         }
                     }
@@ -394,6 +451,7 @@ GdkPixbuf*  pixbuf_new_from_file( const char *filename, GError **error )
                         gchar *tmp = g_strdup_printf( "%d", dpiX );
                         if ( tmp )
                         {
+//                             g_message("Need to set DpiX: %s", tmp);
                             //gdk_pixbuf_set_option( buf, "Inkscape::DpiX", tmp );
                             g_free( tmp );
                         }
@@ -403,6 +461,7 @@ GdkPixbuf*  pixbuf_new_from_file( const char *filename, GError **error )
                         gchar *tmp = g_strdup_printf( "%d", dpiY );
                         if ( tmp )
                         {
+//                             g_message("Need to set DpiY: %s", tmp);
                             //gdk_pixbuf_set_option( buf, "Inkscape::DpiY", tmp );
                             g_free( tmp );
                         }
@@ -919,7 +978,7 @@ sp_image_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
 }
 
 static void
-sp_image_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
+sp_image_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const /*flags*/)
 {
        SPImage const &image = *SP_IMAGE(item);
 
@@ -940,7 +999,6 @@ static void
 sp_image_print (SPItem *item, SPPrintContext *ctx)
 {
        SPImage *image;
-       NRMatrix tp, ti, s, t;
        guchar *px;
        int w, h, rs, pixskip;
 
@@ -955,20 +1013,22 @@ sp_image_print (SPItem *item, SPPrintContext *ctx)
        rs = gdk_pixbuf_get_rowstride (image->pixbuf);
        pixskip = gdk_pixbuf_get_n_channels (image->pixbuf) * gdk_pixbuf_get_bits_per_sample (image->pixbuf) / 8;
 
+    NR::Matrix t;
        if (image->aspect_align == SP_ASPECT_NONE) {
                /* fixme: (Lauris) */
-               nr_matrix_set_translate (&tp, image->x.computed, image->y.computed);
-               nr_matrix_set_scale (&s, image->width.computed, -image->height.computed);
-               nr_matrix_set_translate (&ti, 0.0, -1.0);
+        NR::translate tp = NR::translate(image->x.computed, image->y.computed);
+        NR::scale s = NR::scale(image->width.computed, -image->height.computed);
+        NR::translate ti = NR::translate(0.0, -1.0);
+           t = s * tp;
+           t = ti * t;
        } else { // preserveAspectRatio
-               nr_matrix_set_translate (&tp, image->viewx, image->viewy);
-               nr_matrix_set_scale (&s, image->viewwidth, -image->viewheight);
-               nr_matrix_set_translate (&ti, 0.0, -1.0);
+        NR::translate tp = NR::translate(image->viewx, image->viewy);
+        NR::scale s = NR::scale(image->viewwidth, -image->viewheight);
+        NR::translate ti = NR::translate(0.0, -1.0);
+           t = s * tp;
+           t = ti * t;
        }
 
-       nr_matrix_multiply (&t, &s, &tp);
-       nr_matrix_multiply (&t, &ti, &t);
-
        if (image->aspect_align == SP_ASPECT_NONE)
                sp_print_image_R8G8B8A8_N (ctx, px, w, h, rs, &t, SP_OBJECT_STYLE (item));
        else // preserveAspectRatio
@@ -1000,7 +1060,7 @@ sp_image_description(SPItem *item)
 }
 
 static NRArenaItem *
-sp_image_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
+sp_image_show (SPItem *item, NRArena *arena, unsigned int /*key*/, unsigned int /*flags*/)
 {
        int pixskip, rs;
        SPImage * image;