Code

Corrected image mask generation
authormiklosh <miklosh@users.sourceforge.net>
Sun, 19 Aug 2007 18:35:04 +0000 (18:35 +0000)
committermiklosh <miklosh@users.sourceforge.net>
Sun, 19 Aug 2007 18:35:04 +0000 (18:35 +0000)
src/extension/internal/pdfinput/svg-builder.cpp

index 7f801d4b44bd6aed0af06a53f87c21a221307c91..d5db5489d201742e5fe4c9db583466a6fe2deb7a 100644 (file)
@@ -1408,39 +1408,25 @@ Inkscape::XML::Node *SvgBuilder::_createImage(Stream *str, int width, int height
         image_stream->reset();
 
         // Convert grayscale values
-        unsigned char *buffer = NULL;
-        if ( color_map || invert_alpha ) {
-            buffer = new unsigned char[width];
-        }
-        if ( color_map ) {
-            for ( int y = 0 ; y < height ; y++ ) {
-                unsigned char *row = image_stream->getLine();
+        unsigned char *buffer = new unsigned char[width];
+        int invert_bit = invert_alpha ? 1 : 0;
+        for ( int y = 0 ; y < height ; y++ ) {
+            unsigned char *row = image_stream->getLine();
+            if (color_map) {
                 color_map->getGrayLine(row, buffer, width);
-                if (invert_alpha) {
-                    unsigned char *buf_ptr = buffer;
-                    for ( int x = 0 ; x < width ; x++ ) {
-                        *buf_ptr++ = ~(*buf_ptr);
-                    }
-                }
-                png_write_row(png_ptr, (png_bytep)buffer);
-            }
-        } else {
-            for ( int y = 0 ; y < height ; y++ ) {
-                unsigned char *row = image_stream->getLine();
-                if (invert_alpha) {
-                    unsigned char *buf_ptr = buffer;
-                    for ( int x = 0 ; x < width ; x++ ) {
-                        *buf_ptr++ = ~row[x];
+            } else {
+                unsigned char *buf_ptr = buffer;
+                for ( int x = 0 ; x < width ; x++ ) {
+                    if ( row[x] ^ invert_bit ) {
+                        *buf_ptr++ = 0;
+                    } else {
+                        *buf_ptr++ = 255;
                     }
-                    png_write_row(png_ptr, (png_bytep)buffer);
-                } else {
-                    png_write_row(png_ptr, (png_bytep)row);
                 }
             }
+            png_write_row(png_ptr, (png_bytep)buffer);
         }
-        if (buffer) {
-            delete buffer;
-        }
+        delete buffer;
     } else if (color_map) {
         image_stream = new ImageStream(str, width,
                                        color_map->getNumPixelComps(),