]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed inline PNG in Bbrowser
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 3 Dec 2009 10:52:28 +0000 (10:52 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 3 Dec 2009 10:52:28 +0000 (10:52 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@793 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/BBrowser/Draw.pm
code_perl/Maasha/KISS.pm
www/index.cgi

index c250ae944e3c401b32ebd22b638b463c45ab9f04..d83ae2e3df2c5e60978d1dc3681267d4f2ae9247 100644 (file)
@@ -33,6 +33,7 @@ use strict;
 use Data::Dumper;
 use Cairo;
 use Pango;
+use MIME::Base64;
 
 use vars qw( @ISA @EXPORT );
 
@@ -145,6 +146,32 @@ sub file_png
 }
 
 
+sub base64_png
+{
+    # Martin A. Hansen, December 2009.
+
+    # Extract a PNG stream from a Cairo::Surface object
+    # and convert it to base64 before returning it.
+
+    my ( $surface,   # Cairo::Surface object
+       ) = @_;
+
+    # Returns a string.
+
+    my ( $png_data, $callback, $base64 );
+
+    $png_data = "";
+
+    $callback = sub { $png_data .= $_[ 1 ] };
+    
+    $surface->write_to_png_stream( $callback );
+
+    $base64 = MIME::Base64::encode_base64( $png_data );
+
+    return $base64;
+}
+
+
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 1;
index d0267675ddae568f772e783af21575a3b75d3211..a75ca57153f2544331731c1025ac183606ca5c41 100644 (file)
@@ -301,6 +301,8 @@ sub kiss_index_offset
         }
     }
 
+    # Maasha::Common::error( "No offset" ) if not defined $offset;
+
     return $offset;
 }
 
index a8eabb311361c86350347b3b799ebc7195b37c58..b4ccffc2a3ad9cd19478f3ef2fd39423e2af97f8 100755 (executable)
@@ -653,7 +653,7 @@ sub section_browse
 
     # Returns a list.
 
-    my ( @tracks, $i, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
+    my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img );
 
     push @features, [ Maasha::BBrowser::Track::track_ruler( $cookie ) ];
     push @features, [ Maasha::BBrowser::Track::track_seq( $cookie ) ];
@@ -667,8 +667,6 @@ sub section_browse
         push @features, [ Maasha::BBrowser::Track::track_feature( $tracks[ $i ], $cookie ) ];
     }
 
-    $file = "fisk.png";   # FIXME
-
     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
     $cr      = Cairo::Context->create( $surface );
 
@@ -680,10 +678,10 @@ sub section_browse
         Maasha::BBrowser::Draw::draw_feature( $cr, $feat ) if $feat;
     }
 
-    Maasha::BBrowser::Draw::file_png( $surface, $file );
+    $png_data = Maasha::BBrowser::Draw::base64_png( $surface );
 
     push @img, Maasha::XHTML::img(
-        src    => $file,
+        src    => "data:image/png;base64,$png_data",
         alt    => "Browser Tracks",
         height => $cookie->{ 'TRACK_OFFSET' },
         width  => $cookie->{ 'IMG_WIDTH' },