Author: adamblokus
Date: Thu Jun 5 07:20:32 2008
New Revision: 4263
URL:
http://source.netsurf-browser.org?rev=4263&view=rev
Log:
Added hadling images other than png and jpeg - with transparency.
Modified:
branches/adamblokus/netsurf/gtk/gtk_bitmap.c
branches/adamblokus/netsurf/pdf/pdf_plotters.c
Modified: branches/adamblokus/netsurf/gtk/gtk_bitmap.c
URL:
http://source.netsurf-browser.org/branches/adamblokus/netsurf/gtk/gtk_bit...
==============================================================================
--- branches/adamblokus/netsurf/gtk/gtk_bitmap.c (original)
+++ branches/adamblokus/netsurf/gtk/gtk_bitmap.c Thu Jun 5 07:20:32 2008
@@ -211,6 +211,14 @@
void (*invalidate)(struct bitmap *bitmap, void *private_word)) {
}
+int bitmap_get_width(struct bitmap *bitmap){
+ return gdk_pixbuf_get_width(bitmap->primary);
+}
+
+int bitmap_get_height(struct bitmap *bitmap){
+ return gdk_pixbuf_get_height(bitmap->primary);
+}
+
static GdkPixbuf *
gtk_bitmap_generate_pretile(GdkPixbuf *primary, int repeat_x, int repeat_y)
{
Modified: branches/adamblokus/netsurf/pdf/pdf_plotters.c
URL:
http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/pdf_plo...
==============================================================================
--- branches/adamblokus/netsurf/pdf/pdf_plotters.c (original)
+++ branches/adamblokus/netsurf/pdf/pdf_plotters.c Thu Jun 5 07:20:32 2008
@@ -22,6 +22,7 @@
#include "desktop/plotters.h"
#include "utils/log.h"
#include "utils/utils.h"
+#include "image/bitmap.h"
#include "hpdf.h"
@@ -296,7 +297,10 @@
bool pdf_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg, struct content *content){
- HPDF_Image image;
+ HPDF_Image image=NULL,smask;
+ char *img_buffer,*rgb_buffer,*alpha_buffer;
+ int img_width,img_height,img_rowstride;
+ int i,j;
#ifdef PDF_DEBUG
LOG(("%d %d %d %d %X %X %X", x, y, width, height,
@@ -311,28 +315,58 @@
switch(content->type){
/*Handle "embeddable" types of images*/
case CONTENT_JPEG:
-// image = HPDF_LoadJpegImageFromFile(pdf_doc,"testres/jpeg.jpeg");
image=HPDF_LoadJpegImageFromMem(pdf_doc,content->source_data,
content->total_size);
- HPDF_Page_DrawImage(pdf_page,image,
- x, page_height-y-height,
- width, height);
- return true;
+ break;
+
case CONTENT_PNG:
-// image = HPDF_LoadPngImageFromFile(pdf_doc,"testres/png.png");
image=HPDF_LoadPngImageFromMem(pdf_doc,content->source_data,
content->total_size);
- HPDF_Page_DrawImage(pdf_page,image,
- x, page_height-y-height,
- width, height);
- return true;
+ break;
}
}
- /*Handle pixmaps*/
- HPDF_Page_SetRGBFill(pdf_page,1,0,0);
- HPDF_Page_Rectangle(pdf_page,x,page_height-y-height,width,height);
- HPDF_Page_Fill(pdf_page);
+ if(!image){
+
+ /*Handle pixmaps*/
+ img_buffer = bitmap_get_buffer(bitmap);
+ img_width = bitmap_get_width(bitmap);
+ img_height = bitmap_get_height(bitmap);
+ img_rowstride = bitmap_get_rowstride(bitmap);
+
+ rgb_buffer = (char*)malloc(3*img_width*img_height);
+ alpha_buffer = (char*)malloc(img_width*img_height);
+ if(!(rgb_buffer&&alpha_buffer)){
+ LOG(("Not enough memory?"));
+ return false;
+ }
+
+ for(i=0;i<img_height;i++)
+ for(j=0;j<img_width;j++){
+ rgb_buffer[(i*img_width+j)*3] = img_buffer[i*img_rowstride+j*4];
+ rgb_buffer[(i*img_width+j)*3+1] = img_buffer[i*img_rowstride+j*4+1];
+ rgb_buffer[(i*img_width+j)*3+2] = img_buffer[i*img_rowstride+j*4+2];
+ alpha_buffer[i*img_width+j] = img_buffer[i*img_rowstride+j*4+3];
+ }
+
+ smask=HPDF_LoadRawImageFromMem(pdf_doc,alpha_buffer,
+ img_width,img_height,
+ HPDF_CS_DEVICE_GRAY,8);
+
+ image=HPDF_LoadRawImageFromMem(pdf_doc,rgb_buffer,
+ img_width,img_height,
+ HPDF_CS_DEVICE_RGB,8);
+
+ HPDF_Image_AddSMask(pdf_doc,image,smask);
+
+ free(rgb_buffer);
+ free(alpha_buffer);
+ }
+
+ if(image)
+ HPDF_Page_DrawImage(pdf_page,image,
+ x, page_height-y-height,
+ width, height);
return true;
}