r13359 mono - in /trunk/netsurf/atari/plot: plotter.c plotter.h plotter_vdi.c plotter_vdi.h
by netsurf@semichrome.net
Author: mono
Date: Sat Dec 31 09:21:49 2011
New Revision: 13359
URL: http://source.netsurf-browser.org?rev=13359&view=rev
Log:
Added support for 8bit displays, having big problems with transparent plots ( snapshot of background isn't always taken from correct position, maybe a bug in fvdi)
Modified:
trunk/netsurf/atari/plot/plotter.c
trunk/netsurf/atari/plot/plotter.h
trunk/netsurf/atari/plot/plotter_vdi.c
trunk/netsurf/atari/plot/plotter_vdi.h
Modified: trunk/netsurf/atari/plot/plotter.c
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/plot/plotter.c?rev=...
==============================================================================
--- trunk/netsurf/atari/plot/plotter.c (original)
+++ trunk/netsurf/atari/plot/plotter.c Sat Dec 31 09:21:49 2011
@@ -627,10 +627,20 @@
out[2] = 1000 * b + 0.5;
return;
}
-
-
-
-static short web_std_colors[6] = {0, 51, 102, 153, 204, 255};
+
+void vdi1000_to_rgb( unsigned short * in, unsigned char * out )
+{
+ double r = ((double)in[0]/1000); /* prozentsatz red */
+ double g = ((double)in[1]/1000); /* prozentsatz green */
+ double b = ((double)in[2]/1000); /* prozentsatz blue */
+ out[2] = 255 * r + 0.5;
+ out[1] = 255 * g + 0.5;
+ out[0] = 255 * b + 0.5;
+ return;
+}
+
+
+static short web_std_colors[6] = {0, 51, 102, 153, 204, 255};
/*
Convert an RGB color into an index into the 216 colors web pallette
@@ -640,7 +650,20 @@
short ret = 0;
short i;
unsigned char rgb[3] = {r,g,b};
- unsigned char tval[3];
+ unsigned char tval[3];
+
+ int diff_a, diff_b, diff_c;
+ diff_a = abs(r-g);
+ diff_b = abs(r-b);
+ diff_c = abs(r-b);
+ if( diff_a < 2 && diff_b < 2 && diff_c < 2 ){
+ if( (r!=0XFF) && (g!=0XFF) && (g!=0XFF) ){
+ if( ((r&0xF0)>>4) != 0 )
+ //printf("conv gray: %x -> %d\n", ((r&0xF0)>>4) , (OFFSET_CUST_PAL) + ((r&0xF0)>>4) );
+ return( (OFFSET_CUST_PAL - OFFSET_WEB_PAL) + ((r&0xF0)>>4) );
+ }
+ }
+
/* convert each 8bit color to 6bit web color: */
for( i=0; i<3; i++) {
if(0 == rgb[i] % web_std_colors[1] ) {
Modified: trunk/netsurf/atari/plot/plotter.h
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/plot/plotter.h?rev=...
==============================================================================
--- trunk/netsurf/atari/plot/plotter.h (original)
+++ trunk/netsurf/atari/plot/plotter.h Sat Dec 31 09:21:49 2011
@@ -164,6 +164,8 @@
typedef int (*_pmf_polygon)(GEM_PLOTTER self, const int *p, unsigned int n, const plot_style_t * pstyle);
typedef int (*_pmf_path)(GEM_PLOTTER self, const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
typedef int (*_pmf_bitmap_resize) ( GEM_PLOTTER self, struct bitmap * bm, int nw, int nh );
+typedef int (*_pmf_bitmap_convert)( GEM_PLOTTER self, struct bitmap * img, int x, int y,
+ GRECT * clip, uint32_t bg, uint32_t flags, MFDB *out );
typedef int (*_pmf_bitmap)(GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
unsigned long bg, unsigned long flags );
typedef int (*_pmf_plot_mfdb)(GEM_PLOTTER self, GRECT * loc, MFDB * mfdb, uint32_t flags);
@@ -208,7 +210,9 @@
_pmf_polygon polygon;
_pmf_path path;
/* scale an netsurf bitmap: */
- _pmf_bitmap_resize bitmap_resize;
+ _pmf_bitmap_resize bitmap_resize;
+ /* convert an ABGR (netsurf) bitmap to screen format, ready for vro_cpyfm */
+ _pmf_bitmap_convert bitmap_convert;
/* plot an netsurf bitmap into the buffer / screen: */
_pmf_bitmap bitmap;
/* plot an mfdb into the buffer / screen: */
@@ -290,6 +294,7 @@
void dump_font_drivers(void);
void dump_plot_drivers(void);
void dump_vdi_info(short);
+
/* convert an rgb color to vdi1000 color */
void rgb_to_vdi1000( unsigned char * in, unsigned short * out );
@@ -351,6 +356,7 @@
#define OFFSET_CUST_PAL 232
#define OFFSET_CUSTOM_COLOR 255 /* this one is used by the TC renderer */
#define RGB_TO_VDI(c) rgb_to_666_index( (c&0xFF),(c&0xFF00)>>8,(c&0xFF0000)>>16)+OFFSET_WEB_PAL
+/* the name of this macro is crap - it should be named bgr_to_rgba ... or so */
#define ABGR_TO_RGB(c) ( ((c&0xFF)<<16) | (c&0xFF00) | ((c&0xFF0000)>>16) ) << 8
/* calculate MFDB compatible rowstride (in number of bits) */
Modified: trunk/netsurf/atari/plot/plotter_vdi.c
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/plot/plotter_vdi.c?...
==============================================================================
--- trunk/netsurf/atari/plot/plotter_vdi.c (original)
+++ trunk/netsurf/atari/plot/plotter_vdi.c Sat Dec 31 09:21:49 2011
@@ -1,27 +1,27 @@
-/*
- * Copyright 2010 Ole Loots <ole(a)monochrom.net>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <windom.h>
+/*
+ * Copyright 2010 Ole Loots <ole(a)monochrom.net>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <windom.h>
#include <Hermes/Hermes.h>
#include "atari/plot/eddi.h"
@@ -43,621 +43,612 @@
default:\
dst = 1;\
break;\
- }\
-
-static int dtor( GEM_PLOTTER self );
-static int resize( GEM_PLOTTER self, int w, int h );
-static int move( GEM_PLOTTER self, short x, short y );
-static int lock( GEM_PLOTTER self );
-static int unlock( GEM_PLOTTER self );
-static int update_region( GEM_PLOTTER self, GRECT region );
-static int update_screen_region( GEM_PLOTTER self, GRECT region );
-static int update_screen( GEM_PLOTTER self );
-static int put_pixel(GEM_PLOTTER self, int x, int y, int color );
-static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst );
-static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle);
-static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle);
-static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int polygon(GEM_PLOTTER self,const int *p, unsigned int n, const plot_style_t * pstyle);
-static int path(GEM_PLOTTER self,const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
-static int bitmap_resize( GEM_PLOTTER self, struct bitmap * img, int nw, int nh );
-static int bitmap( GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags );
-static int plot_mfdb( GEM_PLOTTER self, GRECT * where, MFDB * mfdb, uint32_t flags);
-static int text(GEM_PLOTTER self, int x, int y, const char *text,size_t length, const plot_font_style_t *fstyle);
-
-#ifdef WITH_8BPP_SUPPORT
-static unsigned short sys_pal[256][3]; /*RGB*/
-static unsigned short pal[256][3]; /*RGB*/
-extern unsigned char rgb_web_pal[126][3];
+ }\
+
+static int dtor( GEM_PLOTTER self );
+static int resize( GEM_PLOTTER self, int w, int h );
+static int move( GEM_PLOTTER self, short x, short y );
+static int lock( GEM_PLOTTER self );
+static int unlock( GEM_PLOTTER self );
+static int update_region( GEM_PLOTTER self, GRECT region );
+static int update_screen_region( GEM_PLOTTER self, GRECT region );
+static int update_screen( GEM_PLOTTER self );
+static int put_pixel(GEM_PLOTTER self, int x, int y, int color );
+static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst );
+static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle);
+static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle);
+static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
+static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
+static int polygon(GEM_PLOTTER self,const int *p, unsigned int n, const plot_style_t * pstyle);
+static int path(GEM_PLOTTER self,const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
+static int bitmap_resize( GEM_PLOTTER self, struct bitmap * img, int nw, int nh );
+static int bitmap_convert( GEM_PLOTTER self, struct bitmap * img, int x, int y,
+ GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out );
+static int bitmap_convert_8( GEM_PLOTTER self, struct bitmap * img,int x, int y,
+ GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out );
+static int bitmap( GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
+ unsigned long bg, unsigned long flags );
+static int plot_mfdb( GEM_PLOTTER self, GRECT * where, MFDB * mfdb, uint32_t flags);
+static int text(GEM_PLOTTER self, int x, int y, const char *text,size_t length, const plot_font_style_t *fstyle);
+
+
+#ifdef WITH_8BPP_SUPPORT
+static unsigned short sys_pal[256][3]; /*RGB*/
+static unsigned short pal[256][3]; /*RGB*/
extern unsigned short vdi_web_pal[126][3];
-int32 * hermes_pal_p;
#endif
extern struct s_vdi_sysinfo vdi_sysinfo;
static HermesHandle hermes_pal_h; /* hermes palette handle */
static HermesHandle hermes_cnv_h; /* hermes converter instance handle */
-static HermesHandle hermes_res_h;
-
-
-static inline void vsl_rgbcolor( short vdih, uint32_t cin )
-{
- if( vdi_sysinfo.scr_bpp > 8 ) {
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
- vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0] );
- vsl_color( vdih, OFFSET_CUSTOM_COLOR );
- } else {
- if( vdi_sysinfo.scr_bpp >= 4 )
- vsl_color( vdih, RGB_TO_VDI(cin) );
- else
- vsl_color( vdih, BLACK );
- }
-}
-
-static inline void vsf_rgbcolor( short vdih, uint32_t cin )
-{
- if( vdi_sysinfo.scr_bpp > 8 ) {
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
- vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] );
- vsf_color( vdih, OFFSET_CUSTOM_COLOR );
- } else {
- if( vdi_sysinfo.scr_bpp >= 4 )
- vsf_color( vdih, RGB_TO_VDI(cin) );
- else
- vsf_color( vdih, WHITE );
- }
-}
-
-int ctor_plotter_vdi(GEM_PLOTTER self )
-{
- int retval = 0;
- int i;
- struct rect clip;
-
- self->dtor = dtor;
- self->resize= resize;
- self->move = move;
- self->lock = lock;
- self->unlock = unlock;
- self->update_region = update_region;
- self->update_screen_region = update_screen_region;
- self->update_screen = update_screen;
- self->put_pixel = put_pixel;
- self->copy_rect = copy_rect;
- self->clip = plotter_std_clip;
- self->arc = arc;
- self->disc = disc;
- self->line = line;
- self->rectangle = rectangle;
- self->polygon = polygon;
- self->path = path;
- self->bitmap = bitmap;
- self->bitmap_resize = bitmap_resize;
- self->plot_mfdb = plot_mfdb;
- self->text = text;
- LOG(("Screen: x: %d, y: %d\n", vdi_sysinfo.scr_w, vdi_sysinfo.scr_h));
-
- self->priv_data = malloc( sizeof(struct s_vdi_priv_data) );
- if( self->priv_data == NULL )
- return( 0-ERR_NO_MEM );
- memset( self->priv_data, 0, sizeof(struct s_vdi_priv_data) );
- DUMMY_PRIV(self)->bufops = 0;
- DUMMY_PRIV(self)->size_buf_packed = 0;
- DUMMY_PRIV(self)->size_buf_planar = 0;
- DUMMY_PRIV(self)->buf_packed = NULL;
- DUMMY_PRIV(self)->buf_planar = NULL;
- if( vdi_sysinfo.vdiformat == VDI_FORMAT_PACK ) {
- self->bpp_virt = vdi_sysinfo.scr_bpp;
- } else {
- DUMMY_PRIV(self)->bufops = C2P;
- self->bpp_virt = 8;
- }
- if( FIRSTFB(self).w > vdi_sysinfo.scr_w || FIRSTFB(self).h > vdi_sysinfo.scr_h ){
- return( 0-ERR_BUFFERSIZE_EXCEEDS_SCREEN );
- }
-
- FIRSTFB(self).size = calc_chunked_buffer_size( FIRSTFB(self).w, FIRSTFB(self).h, FIRSTFB(self).w, self->bpp_virt );
- /* offscreen: FIRSTFB(self).mem = malloc( FIRSTFB(self).size ); */
- FIRSTFB(self).mem = NULL;
- update_visible_rect( self );
-
- clip.x0 = 0;
- clip.y0 = 0;
- clip.x1 = FIRSTFB(self).w;
- clip.y1 = FIRSTFB(self).h;
- self->clip( self, &clip );
+static HermesHandle hermes_res_h;
+
+
+static inline void vsl_rgbcolor( short vdih, uint32_t cin )
+{
+ if( vdi_sysinfo.scr_bpp > 8 ) {
+ unsigned short c[4];
+ rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
+ vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0] );
+ vsl_color( vdih, OFFSET_CUSTOM_COLOR );
+ } else {
+ if( vdi_sysinfo.scr_bpp >= 4 ){
+ vsl_color( vdih, RGB_TO_VDI(cin) );
+ }
+ else
+ vsl_color( vdih, BLACK );
+ }
+}
+
+static inline void vsf_rgbcolor( short vdih, uint32_t cin )
+{
+ if( vdi_sysinfo.scr_bpp > 8 ) {
+ unsigned short c[4];
+ rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
+ vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] );
+ vsf_color( vdih, OFFSET_CUSTOM_COLOR );
+ } else {
+ if( vdi_sysinfo.scr_bpp >= 4 ){
+ vsf_color( vdih, RGB_TO_VDI(cin) );
+ }
+ else
+ vsf_color( vdih, WHITE );
+ }
+}
+
+int ctor_plotter_vdi(GEM_PLOTTER self )
+{
+ int retval = 0;
+ int i;
+ struct rect clip;
+
+ self->dtor = dtor;
+ self->resize= resize;
+ self->move = move;
+ self->lock = lock;
+ self->unlock = unlock;
+ self->update_region = update_region;
+ self->update_screen_region = update_screen_region;
+ self->update_screen = update_screen;
+ self->put_pixel = put_pixel;
+ self->copy_rect = copy_rect;
+ self->clip = plotter_std_clip;
+ self->arc = arc;
+ self->disc = disc;
+ self->line = line;
+ self->rectangle = rectangle;
+ self->polygon = polygon;
+ self->path = path;
+ self->bitmap = bitmap;
+ self->bitmap_resize = bitmap_resize;
+ self->bitmap_convert =(app.nplanes > 8) ? bitmap_convert : bitmap_convert_8;
+ //self->bitmap_convert =bitmap_convert;
+ self->plot_mfdb = plot_mfdb;
+ self->text = text;
+ LOG(("Screen: x: %d, y: %d\n", vdi_sysinfo.scr_w, vdi_sysinfo.scr_h));
+
+ self->priv_data = malloc( sizeof(struct s_vdi_priv_data) );
+ if( self->priv_data == NULL )
+ return( 0-ERR_NO_MEM );
+ memset( self->priv_data, 0, sizeof(struct s_vdi_priv_data) );
+ DUMMY_PRIV(self)->bufops = 0;
+ DUMMY_PRIV(self)->size_buf_packed = 0;
+ DUMMY_PRIV(self)->size_buf_planar = 0;
+ DUMMY_PRIV(self)->buf_packed = NULL;
+ DUMMY_PRIV(self)->buf_planar = NULL;
+ if( vdi_sysinfo.vdiformat == VDI_FORMAT_PACK ) {
+ self->bpp_virt = vdi_sysinfo.scr_bpp;
+ } else {
+ DUMMY_PRIV(self)->bufops = C2P;
+ self->bpp_virt = 8;
+ }
+ if( FIRSTFB(self).w > vdi_sysinfo.scr_w || FIRSTFB(self).h > vdi_sysinfo.scr_h ){
+ return( 0-ERR_BUFFERSIZE_EXCEEDS_SCREEN );
+ }
+
+ FIRSTFB(self).size = calc_chunked_buffer_size( FIRSTFB(self).w, FIRSTFB(self).h, FIRSTFB(self).w, self->bpp_virt );
+ /* offscreen: FIRSTFB(self).mem = malloc( FIRSTFB(self).size ); */
+ FIRSTFB(self).mem = NULL;
+ update_visible_rect( self );
+
+ clip.x0 = 0;
+ clip.y0 = 0;
+ clip.x1 = FIRSTFB(self).w;
+ clip.y1 = FIRSTFB(self).h;
+ self->clip( self, &clip );
+
+ assert( Hermes_Init() );
/* store system palette & setup the new (web) palette: */
-#ifdef WITH_8BPP_SUPPORT
- i = 0;
- if( app.nplanes <= 8 ){
- for( i=0; i<=255; i++ ) {
- vq_color(self->vdi_handle, i, 1, (unsigned short*)&sys_pal[i][0] );
- if( i<OFFSET_WEB_PAL ) {
- pal[i][0] = sys_pal[i][0];
- pal[i][1] = sys_pal[i][1];
- pal[i][2] = sys_pal[i][2];
- } else if( app.nplanes >= 8 ) {
- if ( i < OFFSET_CUST_PAL ){
- pal[i][0] = vdi_web_pal[i-OFFSET_WEB_PAL][0];
- pal[i][1] = vdi_web_pal[i-OFFSET_WEB_PAL][1];
- pal[i][2] = vdi_web_pal[i-OFFSET_WEB_PAL][2];
- }
- if( i >= OFFSET_CUST_PAL ) {
- /* here we could define 22 additional colors... */
- }
- vs_color( self->vdi_handle, i, &pal[i][0] );
- }
- }
- } else {
- /* no need to change the palette - its application specific */
- }
-#endif
-
- unsigned char * col;
- assert( Hermes_Init() );
-/*
- hermes_pal_h = Hermes_PaletteInstance();
- hermes_pal_p = Hermes_PaletteGet(hermes_pal_h);
- assert(hermes_pal_p);
-
- for( i = 0; i<OFFSET_CUST_PAL; i++) {
- col = (unsigned char *)(hermes_pal_p+i);
- if( i < OFFSET_WEB_PAL ) {
- col[0] = sys_pal[i][0];
- col[1] = sys_pal[i][1];
- col[2] = sys_pal[i][2];
- }
- if( i >= OFFSET_WEB_PAL ) {
- col[0] = rgb_web_pal[i-OFFSET_WEB_PAL][0];
- col[1] = rgb_web_pal[i-OFFSET_WEB_PAL][1];
- col[2] = rgb_web_pal[i-OFFSET_WEB_PAL][2];
- }
- col[3] = 0;
- }
- Hermes_PaletteInvalidateCache(hermes_pal_h);
-*/
-
- unsigned long flags = ( self->flags & PLOT_FLAG_DITHER ) ? HERMES_CONVERT_DITHER : 0;
- hermes_cnv_h = Hermes_ConverterInstance( flags );
- assert( hermes_cnv_h );
- hermes_res_h = Hermes_ConverterInstance( flags );
- assert( hermes_res_h );
-
- /* set up the src & dst format: */
- /* netsurf uses RGBA ... */
- DUMMY_PRIV(self)->nsfmt.a = 0xFFUL;
- DUMMY_PRIV(self)->nsfmt.b = 0x0FF00UL;
- DUMMY_PRIV(self)->nsfmt.g = 0x0FF0000UL;
- DUMMY_PRIV(self)->nsfmt.r = 0x0FF000000UL;
- DUMMY_PRIV(self)->nsfmt.bits = 32;
- DUMMY_PRIV(self)->nsfmt.indexed = false;
- DUMMY_PRIV(self)->nsfmt.has_colorkey = false;
-
- DUMMY_PRIV(self)->vfmt.r = vdi_sysinfo.mask_r;
- DUMMY_PRIV(self)->vfmt.g = vdi_sysinfo.mask_g;
- DUMMY_PRIV(self)->vfmt.b = vdi_sysinfo.mask_b;
- DUMMY_PRIV(self)->vfmt.a = vdi_sysinfo.mask_a;
- DUMMY_PRIV(self)->vfmt.bits = self->bpp_virt;
- DUMMY_PRIV(self)->vfmt.indexed = false;
- DUMMY_PRIV(self)->vfmt.has_colorkey = false;
-
- return( 1 );
-}
-
-static int dtor( GEM_PLOTTER self )
-{
- int i=0;
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- for( i=0; i<MAX_FRAMEBUFS; i++) {
- if( self->fbuf[i].mem != NULL )
- free( self->fbuf[i].mem );
- }
-
-
- /* close Hermes stuff: */
+#ifdef WITH_8BPP_SUPPORT
+ i = 0;
+
+ unsigned char * col;
+ unsigned char rgbcol[4];
+ unsigned char graytone=0;
+ if( app.nplanes <= 8 ){
+ for( i=0; i<=255; i++ ) {
+
+ // get the current color and save it for restore:
+ vq_color(self->vdi_handle, i, 1, (unsigned short*)&sys_pal[i][0] );
+ if( i<OFFSET_WEB_PAL ) {
+ pal[i][0] = sys_pal[i][0];
+ pal[i][1] = sys_pal[i][1];
+ pal[i][2] = sys_pal[i][2];
+ } else if( app.nplanes >= 8 ) {
+ if ( i < OFFSET_CUST_PAL ){
+ pal[i][0] = vdi_web_pal[i-OFFSET_WEB_PAL][0];
+ pal[i][1] = vdi_web_pal[i-OFFSET_WEB_PAL][1];
+ pal[i][2] = vdi_web_pal[i-OFFSET_WEB_PAL][2];
+ //set the new palette color to websafe value:
+ vs_color( self->vdi_handle, i, &pal[i][0] );
+ }
+ if( i >= OFFSET_CUST_PAL && i<OFFSET_CUST_PAL+16 ) {
+ /* here we define 20 additional gray colors... */
+ rgbcol[1] = rgbcol[2] = rgbcol[3] = ((graytone&0x0F) << 4);
+ rgb_to_vdi1000( &rgbcol[0], &pal[i][0] );
+ printf("graytone: %d (%x), index: %d\n",rgbcol[1], rgbcol[1],i );
+ vs_color( self->vdi_handle, i, &pal[i][0] );
+ graytone++;
+ }
+
+ }
+ }
+ } else {
+ /* no need to change the palette - its application specific */
+ }
+
+
+#endif
+
+ unsigned long flags = ( self->flags & PLOT_FLAG_DITHER ) ? HERMES_CONVERT_DITHER : 0;
+ hermes_cnv_h = Hermes_ConverterInstance( flags );
+ assert( hermes_cnv_h );
+ hermes_res_h = Hermes_ConverterInstance( flags );
+ assert( hermes_res_h );
+
+ /* set up the src & dst format: */
+ /* netsurf uses RGBA ... */
+ DUMMY_PRIV(self)->nsfmt.a = 0xFFUL;
+ DUMMY_PRIV(self)->nsfmt.b = 0x0FF00UL;
+ DUMMY_PRIV(self)->nsfmt.g = 0x0FF0000UL;
+ DUMMY_PRIV(self)->nsfmt.r = 0x0FF000000UL;
+ DUMMY_PRIV(self)->nsfmt.bits = 32;
+ DUMMY_PRIV(self)->nsfmt.indexed = false;
+ DUMMY_PRIV(self)->nsfmt.has_colorkey = false;
+
+ DUMMY_PRIV(self)->vfmt.r = vdi_sysinfo.mask_r;
+ DUMMY_PRIV(self)->vfmt.g = vdi_sysinfo.mask_g;
+ DUMMY_PRIV(self)->vfmt.b = vdi_sysinfo.mask_b;
+ DUMMY_PRIV(self)->vfmt.a = vdi_sysinfo.mask_a;
+ DUMMY_PRIV(self)->vfmt.bits = self->bpp_virt;
+ DUMMY_PRIV(self)->vfmt.indexed = ( app.nplanes <= 8 ) ? 1 : 0;
+ DUMMY_PRIV(self)->vfmt.has_colorkey = 0;
+
+ return( 1 );
+}
+
+static int dtor( GEM_PLOTTER self )
+{
+ int i=0;
+ LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
+ for( i=0; i<MAX_FRAMEBUFS; i++) {
+ if( self->fbuf[i].mem != NULL )
+ free( self->fbuf[i].mem );
+ }
+
+
+ /* close Hermes stuff: */
Hermes_ConverterReturn( hermes_cnv_h );
-#ifdef WITH_8BPP_SUPPORT
- if( app.nplanes <= 8 ){
- /* restore system palette */
- for( i=0; i<=255; i++ ) {
- vs_color( self->vdi_handle, i, &sys_pal[i][0] );
- }
- }
- Hermes_PaletteReturn( hermes_pal_h );
-#endif
-
- Hermes_Done();
-
- if( self->priv_data != NULL ){
- if( DUMMY_PRIV(self)->buf_packed )
- free( DUMMY_PRIV(self)->buf_packed );
- if( DUMMY_PRIV(self)->buf_planar )
- free( DUMMY_PRIV(self)->buf_planar );
- free( self->priv_data );
- }
- return( 1 );
-}
-
-static int resize( GEM_PLOTTER self, int w, int h )
-{
- if( w == CURFB(self).w && h == CURFB(self).h )
- return( 1 );
- /* todo: needed when using offscreen buffers...
+ Hermes_Done();
+
+ if( self->priv_data != NULL ){
+ if( DUMMY_PRIV(self)->buf_packed )
+ free( DUMMY_PRIV(self)->buf_packed );
+ if( DUMMY_PRIV(self)->buf_planar )
+ free( DUMMY_PRIV(self)->buf_planar );
+ free( self->priv_data );
+ }
+ snapshot_destroy( self );
+ return( 1 );
+}
+
+static int resize( GEM_PLOTTER self, int w, int h )
+{
+ if( w == CURFB(self).w && h == CURFB(self).h )
+ return( 1 );
+ /* todo: needed when using offscreen buffers...
int newsize = calc_chunked_buffer_size( w, h, w, self->bpp_virt );
LOG(("%s: %s, oldsize: %d\n", (char*)__FILE__, __FUNCTION__, CURFB(self).size ));
- if( newsize > self->screen_buffer_size ) {
- self->screen_buffer_size = newsize;
- self->screen_buffer =realloc( self->screen_buffer , self->screen_buffer_size );
- }
- */
- CURFB(self).w = w;
- CURFB(self).h = h;
- update_visible_rect( self );
- LOG(("%s: %s, newsize: %d\n", (char*)__FILE__, (char*)__FUNCTION__, CURFB(self).size ));
- return( 1 );
-}
-static int move( GEM_PLOTTER self,short x, short y )
-{
- bool upd;
- if(x == CURFB(self).x && y == CURFB(self).y ){
- return 1;
- }
- LOG(("%s: x: %d, y: %d\n",(char*)__FUNCTION__, x, y));
- CURFB(self).x = x;
- CURFB(self).y = y;
- update_visible_rect( self );
- return( 1 );
-}
-
-
-static int lock( GEM_PLOTTER self )
-{
+ if( newsize > self->screen_buffer_size ) {
+ self->screen_buffer_size = newsize;
+ self->screen_buffer =realloc( self->screen_buffer , self->screen_buffer_size );
+ }
+ */
+ CURFB(self).w = w;
+ CURFB(self).h = h;
+ update_visible_rect( self );
+ LOG(("%s: %s, newsize: %d\n", (char*)__FILE__, (char*)__FUNCTION__, CURFB(self).size ));
+ return( 1 );
+}
+static int move( GEM_PLOTTER self,short x, short y )
+{
+ bool upd;
+ if(x == CURFB(self).x && y == CURFB(self).y ){
+ return 1;
+ }
+ LOG(("%s: x: %d, y: %d\n",(char*)__FUNCTION__, x, y));
+ CURFB(self).x = x;
+ CURFB(self).y = y;
+ update_visible_rect( self );
+ return( 1 );
+}
+
+
+static int lock( GEM_PLOTTER self )
+{
LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
if( (self->flags & PLOT_FLAG_LOCKED) != 0 )
- return(1);
- self->flags |= PLOT_FLAG_LOCKED;
+ return(1);
+ self->flags |= PLOT_FLAG_LOCKED;
if( !wind_update(BEG_UPDATE|0x100) )
return(0);
if( !wind_update(BEG_MCTRL|0x100) ){
wind_update(END_UPDATE);
return(0);
- }
- graf_mouse(M_OFF, NULL);
- return( 1 );
-}
-
-static int unlock( GEM_PLOTTER self )
-{
+ }
+ graf_mouse(M_OFF, NULL);
+ return( 1 );
+}
+
+static int unlock( GEM_PLOTTER self )
+{
LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
if( (self->flags & PLOT_FLAG_LOCKED) == 0 )
- return(1);
- self->flags &= ~PLOT_FLAG_LOCKED;
- wind_update(END_MCTRL);
- wind_update(END_UPDATE);
- graf_mouse(M_ON, NULL);
- return( 1 );
-}
-
-/*
- region specifies an rectangle within the framebuffer
- calculation of screen coords is done automatically.
-*/
-static int update_region( GEM_PLOTTER self, GRECT region )
-{
- int src_offs;
- GRECT screen_area, tmp, visible;
- short pxy[10];
- plotter_get_visible_grect( self, &visible );
-
-/*
- LOG(("%s: %s %d\n", (char*)__FILE__, __FUNCTION__, __LINE__));
- LOG(("region: x:%d, y:%d, w:%d, h:%d\n", region.g_x, region.g_y, region.g_w, region.g_h ));
- LOG(("visible: x:%d, y:%d, w:%d, h:%d\n", visible.g_x, visible.g_y, visible.g_w, visible.g_h ));
-*/
- /* sanitize region: */
- tmp = region;
- if( !rc_intersect(&visible, &tmp) )
- return( 0 );
-/*
- region is partially out of bottom or left:
- if( region.g_x < self->visible.g_x )
- {
- region.g_w = self->visible.g_x - region.g_x;
- region.g_x = self->visible.g_x;
- }
- if( region.g_y < self->visible.g_y )
- {
- region.g_h = self->visible.g_y - region.g_y;
- region.g_y = self->visible.g_y;
- }
- region is partially out of top or right:
- if( region.g_x + region.g_w > self->visible.g_x + self->visible.g_w )
- {
- region.g_w = self->visible.g_w - region.g_x;
- }
- if( region.g_y + region.g_h > self->visible.g_y + self->visible.g_h )
- {
- region.g_h = self->visible.g_h - region.g_y;
- }
- now region contains coords of framebuffer that needs redraw.
-*/
- if( fbrect_to_screen( self, tmp, &screen_area) ) {
- pxy[0] = screen_area.g_x;
- pxy[1] = screen_area.g_y;
- pxy[2] = screen_area.g_x + screen_area.g_w;
- pxy[3] = screen_area.g_y;
- pxy[4] = screen_area.g_x + screen_area.g_w;
- pxy[5] = screen_area.g_y + screen_area.g_h;
- pxy[6] = screen_area.g_x;
- pxy[7] = screen_area.g_y + screen_area.g_h;
- pxy[8] = screen_area.g_x;
- pxy[9] = screen_area.g_y;
- }
- return( 1 );
-}
-
-/*
- region specifies an rectangle within the screen,
- calculation of framebuffer coords is done automatically.
-*/
-static int update_screen_region( GEM_PLOTTER self, GRECT region )
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
-
- return( 1 );
-}
-
-/* Updates all visible parts of the framebuffer */
-static int update_screen( GEM_PLOTTER self )
-{
- GRECT target, src;
- int src_offset;
- int i,x;
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- if( !(PLOT_FLAG_OFFSCREEN & self->flags) )
- return( 0 );
- target.g_x = src.g_x = 0;
- target.g_y = src.g_y = 0;
- target.g_w = src.g_w = CURFB(self).w;
- target.g_h = src.g_h = CURFB(self).h;
- if( !fbrect_to_screen( self, target, &target ) )
- return( -1 );
- src_offset = get_pixel_offset( CURFB(self).vis_x, CURFB(self).vis_y, CURFB(self).w, self->bpp_virt );
- LOG(("area: x:%d ,y:%d ,w:%d ,h:%d, from: %p (offset: %d) \n",
- target.g_x, target.g_y,
- target.g_w, target.g_h,
- ((char*)CURFB(self).mem)+src_offset, src_offset
- ));
-
- return( 1 );
-}
-static int put_pixel(GEM_PLOTTER self, int x, int y, int color )
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- return( 1 );
-}
+ return(1);
+ self->flags &= ~PLOT_FLAG_LOCKED;
+ wind_update(END_MCTRL);
+ wind_update(END_UPDATE);
+ graf_mouse(M_ON, NULL);
+ return( 1 );
+}
+
+/*
+ region specifies an rectangle within the framebuffer
+ calculation of screen coords is done automatically.
+*/
+static int update_region( GEM_PLOTTER self, GRECT region )
+{
+ int src_offs;
+ GRECT screen_area, tmp, visible;
+ short pxy[10];
+ plotter_get_visible_grect( self, &visible );
+
+/*
+ LOG(("%s: %s %d\n", (char*)__FILE__, __FUNCTION__, __LINE__));
+ LOG(("region: x:%d, y:%d, w:%d, h:%d\n", region.g_x, region.g_y, region.g_w, region.g_h ));
+ LOG(("visible: x:%d, y:%d, w:%d, h:%d\n", visible.g_x, visible.g_y, visible.g_w, visible.g_h ));
+*/
+ /* sanitize region: */
+ tmp = region;
+ if( !rc_intersect(&visible, &tmp) )
+ return( 0 );
+/*
+ region is partially out of bottom or left:
+ if( region.g_x < self->visible.g_x )
+ {
+ region.g_w = self->visible.g_x - region.g_x;
+ region.g_x = self->visible.g_x;
+ }
+ if( region.g_y < self->visible.g_y )
+ {
+ region.g_h = self->visible.g_y - region.g_y;
+ region.g_y = self->visible.g_y;
+ }
+ region is partially out of top or right:
+ if( region.g_x + region.g_w > self->visible.g_x + self->visible.g_w )
+ {
+ region.g_w = self->visible.g_w - region.g_x;
+ }
+ if( region.g_y + region.g_h > self->visible.g_y + self->visible.g_h )
+ {
+ region.g_h = self->visible.g_h - region.g_y;
+ }
+ now region contains coords of framebuffer that needs redraw.
+*/
+ if( fbrect_to_screen( self, tmp, &screen_area) ) {
+ pxy[0] = screen_area.g_x;
+ pxy[1] = screen_area.g_y;
+ pxy[2] = screen_area.g_x + screen_area.g_w;
+ pxy[3] = screen_area.g_y;
+ pxy[4] = screen_area.g_x + screen_area.g_w;
+ pxy[5] = screen_area.g_y + screen_area.g_h;
+ pxy[6] = screen_area.g_x;
+ pxy[7] = screen_area.g_y + screen_area.g_h;
+ pxy[8] = screen_area.g_x;
+ pxy[9] = screen_area.g_y;
+ }
+ return( 1 );
+}
+
+/*
+ region specifies an rectangle within the screen,
+ calculation of framebuffer coords is done automatically.
+*/
+static int update_screen_region( GEM_PLOTTER self, GRECT region )
+{
+ LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
+
+ return( 1 );
+}
+
+/* Updates all visible parts of the framebuffer */
+static int update_screen( GEM_PLOTTER self )
+{
+ GRECT target, src;
+ int src_offset;
+ int i,x;
+ LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
+ if( !(PLOT_FLAG_OFFSCREEN & self->flags) )
+ return( 0 );
+ target.g_x = src.g_x = 0;
+ target.g_y = src.g_y = 0;
+ target.g_w = src.g_w = CURFB(self).w;
+ target.g_h = src.g_h = CURFB(self).h;
+ if( !fbrect_to_screen( self, target, &target ) )
+ return( -1 );
+ src_offset = get_pixel_offset( CURFB(self).vis_x, CURFB(self).vis_y, CURFB(self).w, self->bpp_virt );
+ LOG(("area: x:%d ,y:%d ,w:%d ,h:%d, from: %p (offset: %d) \n",
+ target.g_x, target.g_y,
+ target.g_w, target.g_h,
+ ((char*)CURFB(self).mem)+src_offset, src_offset
+ ));
+
+ return( 1 );
+}
+static int put_pixel(GEM_PLOTTER self, int x, int y, int color )
+{
+ LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
+ return( 1 );
+}
/* copy an rectangle from the plot buffer to screen */
-/* because this is an on-screen plotter, this is an screen to screen copy. */
-static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst )
-{
- MFDB devmf;
- MFDB scrmf;
- short pxy[8];
- GRECT vis;
-
- /* clip to visible rect, only needed for onscreen renderer: */
- plotter_get_visible_grect( self, &vis );
-
- if( !rc_intersect(&vis, &src) )
- return 1;
- if( !rc_intersect(&vis, &dst) )
- return 1;
-
- src.g_x = CURFB(self).x + src.g_x;
- src.g_y = CURFB(self).y + src.g_y;
- dst.g_x = CURFB(self).x + dst.g_x;
- dst.g_y = CURFB(self).y + dst.g_y;
-
- devmf.fd_addr = NULL;
- devmf.fd_w = src.g_w;
- devmf.fd_h = src.g_h;
- devmf.fd_wdwidth = 0;
- devmf.fd_stand = 0;
- devmf.fd_nplanes = 0;
- devmf.fd_r1 = devmf.fd_r2 = devmf.fd_r3 = 0;
-
- scrmf.fd_addr = NULL;
- scrmf.fd_w = dst.g_w;
- scrmf.fd_h = dst.g_h;
- scrmf.fd_wdwidth = 0 ;
- scrmf.fd_stand = 0;
- scrmf.fd_nplanes = 0;
- scrmf.fd_r1 = scrmf.fd_r2 = scrmf.fd_r3 = 0;
-
- pxy[0] = src.g_x;
- pxy[1] = src.g_y;
- pxy[2] = pxy[0] + src.g_w-1;
- pxy[3] = pxy[1] + src.g_h-1;
- pxy[4] = dst.g_x;
- pxy[5] = dst.g_y;
- pxy[6] = pxy[4] + dst.g_w-1;
- pxy[7] = pxy[5] + dst.g_h-1;
- self->lock( self );
- vro_cpyfm( self->vdi_handle, S_ONLY, (short*)&pxy, &devmf, &scrmf);
- self->unlock( self );
-
- return( 1 );
-}
-
-static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle)
-{
- //plotter_vdi_clip( self, 1);
- vswr_mode( self->vdi_handle, MD_REPLACE );
- if( pstyle->fill_type == PLOT_OP_TYPE_NONE )
- return 1;
- if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour);
- vsf_perimeter( self->vdi_handle, 1);
- vsf_interior( self->vdi_handle, 1 );
- v_arc( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius, angle1*10, angle2*10 );
- } else {
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour);
- vsl_width( self->vdi_handle, 1 );
- vsf_perimeter( self->vdi_handle, 1);
- v_arc( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius, angle1*10, angle2*10 );
- }
- //plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle)
-{
- plotter_vdi_clip( self, 1);
- if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
- vsf_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
- vsf_perimeter( self->vdi_handle, 1);
- vsf_interior( self->vdi_handle, 0 );
- v_circle( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius );
- } else {
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
- vsf_perimeter( self->vdi_handle, 0);
- vsf_interior( self->vdi_handle, FIS_SOLID );
- v_circle( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius );
- }
- plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-
-static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- short pxy[4];
- uint32_t lt;
- int sw = pstyle->stroke_width;
-
- pxy[0] = CURFB(self).x + x0;
- pxy[1] = CURFB(self).y + y0;
- pxy[2] = CURFB(self).x + x1;
- pxy[3] = CURFB(self).y + y1;
-
- plotter_vdi_clip( self, 1);
- if( sw == 0)
- sw = 1;
- NSLT2VDI(lt, pstyle)
+/* because this is an on-screen plotter, this is an screen to screen copy. */
+static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst )
+{
+ MFDB devmf;
+ MFDB scrmf;
+ short pxy[8];
+ GRECT vis;
+
+ /* clip to visible rect, only needed for onscreen renderer: */
+ plotter_get_visible_grect( self, &vis );
+
+ if( !rc_intersect(&vis, &src) )
+ return 1;
+ if( !rc_intersect(&vis, &dst) )
+ return 1;
+
+ src.g_x = CURFB(self).x + src.g_x;
+ src.g_y = CURFB(self).y + src.g_y;
+ dst.g_x = CURFB(self).x + dst.g_x;
+ dst.g_y = CURFB(self).y + dst.g_y;
+
+ devmf.fd_addr = NULL;
+ devmf.fd_w = src.g_w;
+ devmf.fd_h = src.g_h;
+ devmf.fd_wdwidth = 0;
+ devmf.fd_stand = 0;
+ devmf.fd_nplanes = 0;
+ devmf.fd_r1 = devmf.fd_r2 = devmf.fd_r3 = 0;
+
+ scrmf.fd_addr = NULL;
+ scrmf.fd_w = dst.g_w;
+ scrmf.fd_h = dst.g_h;
+ scrmf.fd_wdwidth = 0 ;
+ scrmf.fd_stand = 0;
+ scrmf.fd_nplanes = 0;
+ scrmf.fd_r1 = scrmf.fd_r2 = scrmf.fd_r3 = 0;
+
+ pxy[0] = src.g_x;
+ pxy[1] = src.g_y;
+ pxy[2] = pxy[0] + src.g_w-1;
+ pxy[3] = pxy[1] + src.g_h-1;
+ pxy[4] = dst.g_x;
+ pxy[5] = dst.g_y;
+ pxy[6] = pxy[4] + dst.g_w-1;
+ pxy[7] = pxy[5] + dst.g_h-1;
+ self->lock( self );
+ vro_cpyfm( self->vdi_handle, S_ONLY, (short*)&pxy, &devmf, &scrmf);
+ self->unlock( self );
+
+ return( 1 );
+}
+
+static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle)
+{
+ //plotter_vdi_clip( self, 1);
+ vswr_mode( self->vdi_handle, MD_REPLACE );
+ if( pstyle->fill_type == PLOT_OP_TYPE_NONE )
+ return 1;
+ if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
+ vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour);
+ vsf_perimeter( self->vdi_handle, 1);
+ vsf_interior( self->vdi_handle, 1 );
+ v_arc( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius, angle1*10, angle2*10 );
+ } else {
+ vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour);
+ vsl_width( self->vdi_handle, 1 );
+ vsf_perimeter( self->vdi_handle, 1);
+ v_arc( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius, angle1*10, angle2*10 );
+ }
+ //plotter_vdi_clip( self, 0);
+ return ( 1 );
+}
+
+static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle)
+{
+ plotter_vdi_clip( self, 1);
+ if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
+ vsf_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
+ vsf_perimeter( self->vdi_handle, 1);
+ vsf_interior( self->vdi_handle, 0 );
+ v_circle( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius );
+ } else {
+ vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
+ vsf_perimeter( self->vdi_handle, 0);
+ vsf_interior( self->vdi_handle, FIS_SOLID );
+ v_circle( self->vdi_handle, CURFB(self).x + x, CURFB(self).y + y, radius );
+ }
+ plotter_vdi_clip( self, 0);
+ return ( 1 );
+}
+
+
+static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
+{
+ short pxy[4];
+ uint32_t lt;
+ int sw = pstyle->stroke_width;
+
+ pxy[0] = CURFB(self).x + x0;
+ pxy[1] = CURFB(self).y + y0;
+ pxy[2] = CURFB(self).x + x1;
+ pxy[3] = CURFB(self).y + y1;
+
+ plotter_vdi_clip( self, 1);
+ if( sw == 0)
+ sw = 1;
+ NSLT2VDI(lt, pstyle)
vsl_type( self->vdi_handle, (lt&0x0F) );
- /* if the line style is not available within VDI system,define own style: */
- if( (lt&0x0F) == 7 ){
- vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
- }
- vsl_width( self->vdi_handle, (short)sw );
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- short pxy[4];
+ /* if the line style is not available within VDI system,define own style: */
+ if( (lt&0x0F) == 7 ){
+ vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
+ }
+ vsl_width( self->vdi_handle, (short)sw );
+ vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
+ v_pline(self->vdi_handle, 2, (short *)&pxy );
+ plotter_vdi_clip( self, 0);
+ return ( 1 );
+}
+
+static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
+{
+ short pxy[4];
GRECT r, rclip, sclip;
- int sw = pstyle->stroke_width;
+ int sw = pstyle->stroke_width;
uint32_t lt;
- /* current canvas clip: */
- rclip.g_x = self->clipping.x0;
- rclip.g_y = self->clipping.y0;
- rclip.g_w = self->clipping.x1 - self->clipping.x0;
- rclip.g_h = self->clipping.y1 - self->clipping.y0;
-
- /* physical clipping: */
- sclip.g_x = rclip.g_x;
- sclip.g_y = rclip.g_y;
- sclip.g_w = CURFB(self).vis_w;
- sclip.g_h = CURFB(self).vis_h;
-
- rc_intersect(&sclip, &rclip);
- r.g_x = x0;
- r.g_y = y0;
- r.g_w = x1 - x0;
+ /* current canvas clip: */
+ rclip.g_x = self->clipping.x0;
+ rclip.g_y = self->clipping.y0;
+ rclip.g_w = self->clipping.x1 - self->clipping.x0;
+ rclip.g_h = self->clipping.y1 - self->clipping.y0;
+
+ /* physical clipping: */
+ sclip.g_x = rclip.g_x;
+ sclip.g_y = rclip.g_y;
+ sclip.g_w = CURFB(self).vis_w;
+ sclip.g_h = CURFB(self).vis_h;
+
+ rc_intersect(&sclip, &rclip);
+ r.g_x = x0;
+ r.g_y = y0;
+ r.g_w = x1 - x0;
r.g_h = y1 - y0;
if( !rc_intersect( &rclip, &r ) ) {
- return( 1 );
+ return( 1 );
}
if( pstyle->stroke_type != PLOT_OP_TYPE_NONE ){
/*
manually draw the line, because we do not need vdi clipping
for vertical / horizontal line draws.
*/
- if( sw == 0)
+ if( sw == 0)
sw = 1;
- NSLT2VDI(lt, pstyle);
+ NSLT2VDI(lt, pstyle);
vsl_type( self->vdi_handle, (lt&0x0F) );
/*
if the line style is not available within VDI system,
define own style:
- */
- if( (lt&0x0F) == 7 ){
- vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
- }
- vsl_width( self->vdi_handle, (short)sw );
+ */
+ if( (lt&0x0F) == 7 ){
+ vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
+ }
+ vsl_width( self->vdi_handle, (short)sw );
vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
/* top border: */
if( r.g_y == y0){
- pxy[0] = CURFB(self).x + r.g_x;
- pxy[1] = CURFB(self).y + r.g_y ;
- pxy[2] = CURFB(self).x + r.g_x + r.g_w;
+ pxy[0] = CURFB(self).x + r.g_x;
+ pxy[1] = CURFB(self).y + r.g_y ;
+ pxy[2] = CURFB(self).x + r.g_x + r.g_w;
pxy[3] = CURFB(self).y + r.g_y;
v_pline(self->vdi_handle, 2, (short *)&pxy );
}
/* right border: */
if( r.g_x + r.g_w == x1 ){
- pxy[0] = CURFB(self).x + r.g_x + r.g_w;
- pxy[1] = CURFB(self).y + r.g_y;
- pxy[2] = CURFB(self).x + r.g_x + r.g_w;
+ pxy[0] = CURFB(self).x + r.g_x + r.g_w;
+ pxy[1] = CURFB(self).y + r.g_y;
+ pxy[2] = CURFB(self).x + r.g_x + r.g_w;
pxy[3] = CURFB(self).y + r.g_y + r.g_h;
v_pline(self->vdi_handle, 2, (short *)&pxy );
}
/* bottom border: */
if( r.g_y+r.g_h == y1 ){
- pxy[0] = CURFB(self).x + r.g_x;
- pxy[1] = CURFB(self).y + r.g_y+r.g_h;
- pxy[2] = CURFB(self).x + r.g_x+r.g_w;
+ pxy[0] = CURFB(self).x + r.g_x;
+ pxy[1] = CURFB(self).y + r.g_y+r.g_h;
+ pxy[2] = CURFB(self).x + r.g_x+r.g_w;
pxy[3] = CURFB(self).y + r.g_y+r.g_h;
v_pline(self->vdi_handle, 2, (short *)&pxy );
}
/* left border: */
if( r.g_x == x0 ){
- pxy[0] = CURFB(self).x + r.g_x;
- pxy[1] = CURFB(self).y + r.g_y;
- pxy[2] = CURFB(self).x + r.g_x;
+ pxy[0] = CURFB(self).x + r.g_x;
+ pxy[1] = CURFB(self).y + r.g_y;
+ pxy[2] = CURFB(self).x + r.g_x;
pxy[3] = CURFB(self).y + r.g_y + r.g_h;
v_pline(self->vdi_handle, 2, (short *)&pxy );
}
}
- if( pstyle->fill_type != PLOT_OP_TYPE_NONE ){
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
- vsf_perimeter( self->vdi_handle, 0);
- vsf_interior( self->vdi_handle, FIS_SOLID );
-
- pxy[0] = CURFB(self).x + r.g_x+pstyle->stroke_width;
- pxy[1] = CURFB(self).y + r.g_y+pstyle->stroke_width;
- pxy[2] = CURFB(self).x + r.g_x + r.g_w -1 - pstyle->stroke_width ;
- pxy[3] = CURFB(self).y + r.g_y + r.g_h -1 - pstyle->stroke_width;
+ if( pstyle->fill_type != PLOT_OP_TYPE_NONE ){
+ vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
+ vsf_perimeter( self->vdi_handle, 0);
+ vsf_interior( self->vdi_handle, FIS_SOLID );
+
+ pxy[0] = CURFB(self).x + r.g_x+pstyle->stroke_width;
+ pxy[1] = CURFB(self).y + r.g_y+pstyle->stroke_width;
+ pxy[2] = CURFB(self).x + r.g_x + r.g_w -1 - pstyle->stroke_width ;
+ pxy[3] = CURFB(self).y + r.g_y + r.g_h -1 - pstyle->stroke_width;
vsf_style( self->vdi_handle, 1);
v_bar( self->vdi_handle, (short*)&pxy );
}
-
+
return ( 1 );
}
@@ -766,128 +757,378 @@
return( 0 );
}
-
-static struct bitmap * snapshot_create(GEM_PLOTTER self, int x, int y, int w, int h)
+
+// create snapshot, native screen format
+static MFDB * snapshot_create_native_mfdb( GEM_PLOTTER self, int x, int y, int w, int h)
+{
+ MFDB scr;
+ short pxy[8];
+
+ /* allocate memory for the snapshot */
+ {
+ int scr_stride = MFDB_STRIDE( w );
+ int scr_size = ( ((scr_stride >> 3) * h) * vdi_sysinfo.scr_bpp );
+ if( DUMMY_PRIV(self)->size_buf_scr == 0 ){
+ /* init screen mfdb */
+ DUMMY_PRIV(self)->buf_scr.fd_addr = malloc( scr_size );
+ DUMMY_PRIV(self)->size_buf_scr = scr_size;
+ } else {
+ if( scr_size > DUMMY_PRIV(self)->size_buf_scr ) {
+ DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
+ DUMMY_PRIV(self)->buf_scr.fd_addr, scr_size
+ );
+ DUMMY_PRIV(self)->size_buf_scr = scr_size;
+ }
+ }
+ if( DUMMY_PRIV(self)->buf_scr.fd_addr == NULL ) {
+ DUMMY_PRIV(self)->size_buf_scr = 0;
+ return( NULL );
+ }
+ DUMMY_PRIV(self)->buf_scr.fd_nplanes = vdi_sysinfo.scr_bpp;
+ DUMMY_PRIV(self)->buf_scr.fd_w = scr_stride;
+ DUMMY_PRIV(self)->buf_scr.fd_h = h;
+ DUMMY_PRIV(self)->buf_scr.fd_wdwidth = scr_stride >> 4;
+ assert( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL );
+ }
+ init_mfdb( 0, w, h, 0, &scr );
+ pxy[0] = x;
+ pxy[1] = y;
+ pxy[2] = pxy[0] + w-1;
+ pxy[3] = pxy[1] + h-1;
+ pxy[4] = 0;
+ pxy[5] = 0;
+ pxy[6] = w-1;
+ pxy[7] = h-1;
+ vro_cpyfm(
+ self->vdi_handle, S_ONLY, (short*)&pxy,
+ &scr, &DUMMY_PRIV(self)->buf_scr
+ );
+ dbg_pxy("ntv snap", pxy );
+
+/*
+Debug: output copy to screen:
+ pxy[0] = 0;
+ pxy[1] = 0;
+ pxy[2] = pxy[0] + w-1;
+ pxy[3] = pxy[1] + h-1;
+ pxy[4] = x+20;
+ pxy[5] = y;
+ pxy[6] = w-1;
+ pxy[7] = h-1;
+ vro_cpyfm(
+ self->vdi_handle, S_ONLY, (short*)&pxy,
+ &DUMMY_PRIV(self)->buf_scr,&scr
+ );
+*/
+
+ return( &DUMMY_PRIV(self)->buf_scr );
+}
+
+// create snapshot, vdi std. format
+static MFDB * snapshot_create_std_mfdb(GEM_PLOTTER self, int x, int y, int w, int h)
+{
+ /* allocate memory for the snapshot */
+ {
+ int scr_stride = MFDB_STRIDE( w );
+ int scr_size = ( ((scr_stride >> 3) * h) * app.nplanes );
+ if( DUMMY_PRIV(self)->size_buf_std == 0 ){
+ /* init screen mfdb */
+ DUMMY_PRIV(self)->buf_std.fd_addr = malloc( scr_size );
+ DUMMY_PRIV(self)->size_buf_std = scr_size;
+ } else {
+ if( scr_size > DUMMY_PRIV(self)->size_buf_std ) {
+ DUMMY_PRIV(self)->buf_std.fd_addr = realloc(
+ DUMMY_PRIV(self)->buf_std.fd_addr, scr_size
+ );
+ DUMMY_PRIV(self)->size_buf_std = scr_size;
+ }
+ }
+ if( DUMMY_PRIV(self)->buf_std.fd_addr == NULL ) {
+ DUMMY_PRIV(self)->size_buf_std = 0;
+ return( NULL );
+ }
+ DUMMY_PRIV(self)->buf_std.fd_nplanes = app.nplanes;
+ DUMMY_PRIV(self)->buf_std.fd_w = scr_stride;
+ DUMMY_PRIV(self)->buf_std.fd_h = h;
+ DUMMY_PRIV(self)->buf_std.fd_stand = 1;
+ DUMMY_PRIV(self)->buf_std.fd_wdwidth = scr_stride >> 4;
+ assert( DUMMY_PRIV(self)->buf_std.fd_addr != NULL );
+ }
+ MFDB * native = snapshot_create_native_mfdb( self, x,y,w,h );
+ assert( native );
+
+ vr_trnfm( self->vdi_handle, native, &DUMMY_PRIV(self)->buf_std );
+ return( &DUMMY_PRIV(self)->buf_std );
+}
+
+/*
+ This will create an snapshot of the screen in netsurf ABGR format
+*/
+static struct bitmap * snapshot_create(GEM_PLOTTER self, int x, int y, int w, int h)
+{
+ int err;
+ MFDB * native;
+
+ native = snapshot_create_native_mfdb( self, x, y, w, h );
+
+ /* allocate buffer for result bitmap: */
+ if( DUMMY_PRIV(self)->buf_scr_compat == NULL ) {
+ DUMMY_PRIV(self)->buf_scr_compat = bitmap_create(w, h, 0);
+ } else {
+ DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
+ DUMMY_PRIV(self)->buf_scr_compat->bpp,
+ w * DUMMY_PRIV(self)->buf_scr_compat->bpp,
+ BITMAP_GROW,
+ DUMMY_PRIV(self)->buf_scr_compat );
+ }
+
+ /* convert screen buffer to ns format: */
+ err = Hermes_ConverterRequest( hermes_cnv_h,
+ &DUMMY_PRIV(self)->vfmt,
+ &DUMMY_PRIV(self)->nsfmt
+ );
+ assert( err != 0 );
+ err = Hermes_ConverterCopy( hermes_cnv_h,
+ native->fd_addr,
+ 0, /* x src coord of top left in pixel coords */
+ 0, /* y src coord of top left in pixel coords */
+ w, h,
+ native->fd_w * vdi_sysinfo.pixelsize, /* stride as bytes */
+ DUMMY_PRIV(self)->buf_scr_compat->pixdata,
+ 0, /* x dst coord of top left in pixel coords */
+ 0, /* y dst coord of top left in pixel coords */
+ w, h,
+ bitmap_get_rowstride(DUMMY_PRIV(self)->buf_scr_compat) /* stride as bytes */
+ );
+ assert( err != 0 );
+ return( (struct bitmap * )DUMMY_PRIV(self)->buf_scr_compat );
+}
+
+static void snapshot_suspend(GEM_PLOTTER self )
+{
+ if( DUMMY_PRIV(self)->size_buf_scr > CONV_KEEP_LIMIT ) {
+ DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
+ DUMMY_PRIV(self)->buf_scr.fd_addr, CONV_KEEP_LIMIT
+ );
+ if( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL ) {
+ DUMMY_PRIV(self)->size_buf_scr = CONV_KEEP_LIMIT;
+ } else {
+ DUMMY_PRIV(self)->size_buf_scr = 0;
+ }
+ }
+
+ if( DUMMY_PRIV(self)->size_buf_std > CONV_KEEP_LIMIT ) {
+ DUMMY_PRIV(self)->buf_std.fd_addr = realloc(
+ DUMMY_PRIV(self)->buf_std.fd_addr, CONV_KEEP_LIMIT
+ );
+ if( DUMMY_PRIV(self)->buf_std.fd_addr != NULL ) {
+ DUMMY_PRIV(self)->size_buf_std = CONV_KEEP_LIMIT;
+ } else {
+ DUMMY_PRIV(self)->size_buf_std = 0;
+ }
+ }
+
+ if( bitmap_buffer_size( DUMMY_PRIV(self)->buf_scr_compat ) > CONV_KEEP_LIMIT ) {
+ int w = 0;
+ int h = 1;
+ w = (CONV_KEEP_LIMIT / DUMMY_PRIV(self)->buf_scr_compat->bpp);
+ assert( CONV_KEEP_LIMIT == w*DUMMY_PRIV(self)->buf_scr_compat->bpp );
+ DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
+ DUMMY_PRIV(self)->buf_scr_compat->bpp,
+ CONV_KEEP_LIMIT, BITMAP_SHRINK, DUMMY_PRIV(self)->buf_scr_compat
+ );
+ }
+}
+
+static void snapshot_destroy( GEM_PLOTTER self )
+{
+ if( DUMMY_PRIV(self)->buf_scr.fd_addr ) {
+ free( DUMMY_PRIV(self)->buf_scr.fd_addr );
+ DUMMY_PRIV(self)->buf_scr.fd_addr = NULL;
+ }
+
+ if( DUMMY_PRIV(self)->buf_std.fd_addr ) {
+ free( DUMMY_PRIV(self)->buf_std.fd_addr );
+ DUMMY_PRIV(self)->buf_std.fd_addr = NULL;
+ }
+
+ if( DUMMY_PRIV(self)->buf_scr_compat ) {
+ bitmap_destroy( DUMMY_PRIV(self)->buf_scr_compat );
+ DUMMY_PRIV(self)->buf_scr_compat = NULL;
+ }
+}
+
+
+void set_stdpx( MFDB * dst, int x, int y, unsigned char val )
{
- MFDB scr;
- short pxy[8];
- int err;
-
- /* make sure the screen format is pixel packed... */
- /* no method to convert planar screen to pixel packed ... right now */
- assert( vdi_sysinfo.vdiformat == VDI_FORMAT_PACK );
-
- {
- int scr_stride = MFDB_STRIDE( w );
- int scr_size = ( ((scr_stride >> 3) * h) * vdi_sysinfo.scr_bpp );
- if( DUMMY_PRIV(self)->size_buf_scr == 0 ){
- /* init screen mfdb */
- DUMMY_PRIV(self)->buf_scr.fd_addr = malloc( scr_size );
- DUMMY_PRIV(self)->size_buf_scr = scr_size;
- } else {
- if( scr_size > DUMMY_PRIV(self)->size_buf_scr ) {
- DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_scr.fd_addr, scr_size
- );
- DUMMY_PRIV(self)->size_buf_scr = scr_size;
- }
- }
- if( DUMMY_PRIV(self)->buf_scr.fd_addr == NULL ) {
- DUMMY_PRIV(self)->size_buf_scr = 0;
- return( NULL );
- }
- DUMMY_PRIV(self)->buf_scr.fd_nplanes = vdi_sysinfo.scr_bpp;
- DUMMY_PRIV(self)->buf_scr.fd_w = scr_stride;
- DUMMY_PRIV(self)->buf_scr.fd_h = h;
- DUMMY_PRIV(self)->buf_scr.fd_wdwidth = scr_stride >> 4;
- assert( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL );
- }
-
- init_mfdb( 0, w, h, 0, &scr );
- pxy[0] = x;
- pxy[1] = y;
- pxy[2] = pxy[0] + w-1;
- pxy[3] = pxy[1] + h-1;
- pxy[4] = 0;
- pxy[5] = 0;
- pxy[6] = pxy[2];
- pxy[7] = pxy[3];
- vro_cpyfm(
- self->vdi_handle, S_ONLY, (short*)&pxy,
- &scr, &DUMMY_PRIV(self)->buf_scr
- );
-
- /* convert screen buffer to ns format: */
- if( DUMMY_PRIV(self)->buf_scr_compat == NULL ) {
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_create(w, h, 0);
- } else {
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
- DUMMY_PRIV(self)->buf_scr_compat->bpp,
- w * DUMMY_PRIV(self)->buf_scr_compat->bpp,
- BITMAP_GROW,
- DUMMY_PRIV(self)->buf_scr_compat );
- }
- err = Hermes_ConverterRequest( hermes_cnv_h,
- &DUMMY_PRIV(self)->vfmt,
- &DUMMY_PRIV(self)->nsfmt
- );
- assert( err != 0 );
- err = Hermes_ConverterCopy( hermes_cnv_h,
- DUMMY_PRIV(self)->buf_scr.fd_addr,
- 0, /* x src coord of top left in pixel coords */
- 0, /* y src coord of top left in pixel coords */
- w, h,
- DUMMY_PRIV(self)->buf_scr.fd_w * vdi_sysinfo.pixelsize, /* stride as bytes */
- DUMMY_PRIV(self)->buf_scr_compat->pixdata,
- 0, /* x dst coord of top left in pixel coords */
- 0, /* y dst coord of top left in pixel coords */
- w, h,
- bitmap_get_rowstride(DUMMY_PRIV(self)->buf_scr_compat) /* stride as bytes */
- );
- assert( err != 0 );
- return( (struct bitmap * )DUMMY_PRIV(self)->buf_scr_compat );
-}
-
-static void snapshot_suspend(GEM_PLOTTER self )
-{
- if( DUMMY_PRIV(self)->size_buf_scr > CONV_KEEP_LIMIT ) {
- DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_scr.fd_addr, CONV_KEEP_LIMIT
- );
- if( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL ) {
- DUMMY_PRIV(self)->size_buf_scr = CONV_KEEP_LIMIT;
- } else {
- DUMMY_PRIV(self)->size_buf_scr = 0;
- }
- }
-
- if( bitmap_buffer_size( DUMMY_PRIV(self)->buf_scr_compat ) > CONV_KEEP_LIMIT ) {
- int w = 0;
- int h = 1;
- w = (CONV_KEEP_LIMIT / DUMMY_PRIV(self)->buf_scr_compat->bpp);
- assert( CONV_KEEP_LIMIT == w*DUMMY_PRIV(self)->buf_scr_compat->bpp );
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
- DUMMY_PRIV(self)->buf_scr_compat->bpp,
- CONV_KEEP_LIMIT, BITMAP_SHRINK, DUMMY_PRIV(self)->buf_scr_compat
- );
- }
-}
-
-static void snapshot_destroy( GEM_PLOTTER self )
-{
- if( DUMMY_PRIV(self)->buf_scr.fd_addr ) {
- free( DUMMY_PRIV(self)->buf_scr.fd_addr );
- DUMMY_PRIV(self)->buf_scr.fd_addr = NULL;
- }
-
- if( DUMMY_PRIV(self)->buf_scr_compat ) {
- bitmap_destroy( DUMMY_PRIV(self)->buf_scr_compat );
- DUMMY_PRIV(self)->buf_scr_compat = NULL;
- }
-}
-
+ int p;
+ short * buf;
+ int wdplanesz = dst->fd_wdwidth*dst->fd_h;
+ short whichbit = (1<<(15-(x%16)));
+
+ buf = dst->fd_addr;
+ buf += ((dst->fd_wdwidth*(y))+(x>>4));
+ for( p=0; p<=dst->fd_nplanes-1; p++) {
+ *buf = (val&(1<<p)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+ buf += wdplanesz;
+ }
+}
+
+unsigned char get_stdpx(MFDB * dst, int x, int y )
+{
+ unsigned char ret=0;
+ int p;
+ short * buf;
+ int wdplanesz = dst->fd_wdwidth*dst->fd_h;
+ short whichbit = (1<<(15-(x%16)));
+
+ buf = dst->fd_addr;
+ buf += ((dst->fd_wdwidth*(y))+(x>>4));
+ for( p=0; p<=dst->fd_nplanes-1; p++) {
+ if( *buf & whichbit )
+ ret |= (01<<p);
+ buf += wdplanesz;
+ }
+ return( ret );
+}
+
+static int bitmap_convert_8( GEM_PLOTTER self,
+ struct bitmap * img,
+ int x,
+ int y,
+ GRECT * clip,
+ uint32_t bg,
+ uint32_t flags,
+ MFDB *out )
+{
+
+ int dststride; /* stride of dest. image */
+ int dstsize; /* size of dest. in byte */
+ int err;
+ int bw;
+ struct bitmap * scrbuf = NULL;
+ struct bitmap * bm;
+
+ assert( clip->g_h > 0 );
+ assert( clip->g_w > 0 );
+
+ bm = img;
+ bw = bitmap_get_width( img );
+
+ dststride = MFDB_STRIDE( clip->g_w );
+ dstsize = ( ((dststride >> 3) * clip->g_h) * self->bpp_virt );
+
+ /* (re)allocate buffer for out image: */
+ /* altough the buffer is named "buf_packed" on 8bit systems */
+ /* it's not... */
+ if( dstsize > DUMMY_PRIV(self)->size_buf_packed) {
+ int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
+ if( DUMMY_PRIV(self)->buf_packed == NULL )
+ DUMMY_PRIV(self)->buf_packed =(void*)malloc( blocks * CONV_BLOCK_SIZE );
+ else
+ DUMMY_PRIV(self)->buf_packed =(void*)realloc(
+ DUMMY_PRIV(self)->buf_packed,
+ blocks * CONV_BLOCK_SIZE
+ );
+ assert( DUMMY_PRIV(self)->buf_packed );
+ if( DUMMY_PRIV(self)->buf_packed == NULL ) {
+ return( 0-ERR_NO_MEM );
+ }
+ DUMMY_PRIV(self)->size_buf_packed = blocks * CONV_BLOCK_SIZE;
+ }
+
+
+ /*
+ on 8 bit systems we must convert the TC (ABGR) image
+ to vdi standard format. ( only tested for 256 colors )
+ and then convert it to native format
+ */
+
+ // realloc mem for stdform
+ MFDB stdform;
+ if( ((self->flags & PLOT_FLAG_TRANS) != 0) || ( (flags & BITMAP_MONOGLYPH) != 0) ) {
+ // point image to snapshot buffer, otherwise allocate mem
+ MFDB * bg = snapshot_create_std_mfdb( self, x+clip->g_x,y+clip->g_y, clip->g_w, clip->g_h );
+ stdform.fd_addr = bg->fd_addr;
+ } else {
+ if( dstsize > DUMMY_PRIV(self)->size_buf_planar) {
+ int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
+ if( DUMMY_PRIV(self)->buf_planar == NULL )
+ DUMMY_PRIV(self)->buf_planar =(void*)malloc( blocks * CONV_BLOCK_SIZE );
+ else
+ DUMMY_PRIV(self)->buf_planar =(void*)realloc(
+ DUMMY_PRIV(self)->buf_planar,
+ blocks * CONV_BLOCK_SIZE
+ );
+ assert( DUMMY_PRIV(self)->buf_planar );
+ if( DUMMY_PRIV(self)->buf_planar == NULL ) {
+ return( 0-ERR_NO_MEM );
+ }
+ DUMMY_PRIV(self)->size_buf_planar = blocks * CONV_BLOCK_SIZE;
+ }
+ stdform.fd_addr = DUMMY_PRIV(self)->buf_planar;
+ }
+ stdform.fd_w = dststride;
+ stdform.fd_h = clip->g_h;
+ stdform.fd_wdwidth = dststride >> 4;
+ stdform.fd_stand = 1;
+ stdform.fd_nplanes = (short)self->bpp_virt;
+ stdform.fd_r1 = stdform.fd_r2 = stdform.fd_r3 = 0;
+ /*printf("bpp virt: %d, bytestr: %d, planesize %d\n",
+ self->bpp_virt, ((dststride >> 3) * self->bpp_virt), stdform.fd_wdwidth*stdform.fd_h );
+ */
+ // convert pixels to std. format
+ int wdplanesz = stdform.fd_wdwidth*stdform.fd_h;
+ int bytestride = (dststride >> 3) * self->bpp_virt;
+ unsigned long max = ((char*)stdform.fd_addr)+dstsize;
+ int img_stride = bitmap_get_rowstride(bm);
+
+ // first, get snapshot in planar buffer,
+ // then apply transparency.
+ for( y=0; y<clip->g_h; y++ ){
+ uint32_t * imgpixel;
+ imgpixel = (uint32_t *)(bm->pixdata + (img_stride * (y+clip->g_y)));
+ for( x=0; x<clip->g_w; x++ ){
+ uint32_t pixel = imgpixel[x+clip->g_x];
+ unsigned long col = ABGR_TO_RGB( (pixel&0xFFFFFF00)>>8 );
+ unsigned char val = RGB_TO_VDI( col>>8 );
+ if( (pixel&0xFF) == 0 ){
+ set_stdpx( &stdform, x,y, get_stdpx( &stdform,x,y ) );
+ continue;
+ }
+
+ if( (pixel&0xFF) >=128 ){
+ set_stdpx( &stdform, x,y, val );
+ } else {
+ char rgb[4];
+ col = get_stdpx( &stdform,x,y );
+ // TBD: use lookup table!
+ vdi1000_to_rgb( &pal[col], &rgb[0] );
+ pixel = ablend( pixel, ((rgb[2] << 16) | (rgb[1] << 8) | (rgb[0]))<<8 );
+ col = ABGR_TO_RGB( (pixel&0xFFFFFF00)>>8 );
+ val = RGB_TO_VDI( col>>8 );
+ set_stdpx( &stdform, x,y, val );
+ }
+ }
+ }
+
+ // convert into native format:
+ MFDB native;
+ native.fd_addr = DUMMY_PRIV(self)->buf_packed;
+ native.fd_w = dststride;
+ native.fd_h = clip->g_h;
+ native.fd_wdwidth = dststride >> 4;
+ native.fd_stand = 0;
+ native.fd_nplanes = (short)self->bpp_virt;
+ native.fd_r1 = native.fd_r2 = native.fd_r3 = 0;
+ vr_trnfm( self->vdi_handle, &stdform, &native );
+ *out = native;
+
+ return(0);
+}
+
/* convert bitmap to the virutal (chunked) framebuffer format */
-static int convert_bitmap( GEM_PLOTTER self,
+static int bitmap_convert( GEM_PLOTTER self,
struct bitmap * img,
int x,
int y,
@@ -1057,7 +1298,7 @@
pxy[7] = CURFB(self).y + loc.g_y + off.g_h-1;
/* Convert the Bitmap to native screen format - ready for output*/
/* This includes blending transparent pixels */
- if( convert_bitmap( self, bmp, pxy[4], pxy[5], &off, bg, flags, &src_mf) != 0 ) {
+ if( self->bitmap_convert( self, bmp, pxy[4], pxy[5], &off, bg, flags, &src_mf) != 0 ) {
return( true );
}
vro_cpyfm( self->vdi_handle, S_ONLY, (short*)&pxy, &src_mf, &scrmf);
Modified: trunk/netsurf/atari/plot/plotter_vdi.h
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/plot/plotter_vdi.h?...
==============================================================================
--- trunk/netsurf/atari/plot/plotter_vdi.h (original)
+++ trunk/netsurf/atari/plot/plotter_vdi.h Sat Dec 31 09:21:49 2011
@@ -32,9 +32,14 @@
int size_buf_planar;
/* buffer for plot operations that require device format, */
- /* currently used for transparent mfdb blits: */
+ /* currently used for transparent mfdb blits and snapshots: */
MFDB buf_scr;
- int size_buf_scr;
+ int size_buf_scr;
+
+ /* buffer for std form, used during 8bpp snapshot */
+ MFDB buf_std;
+ int size_buf_std;
+
struct bitmap * buf_scr_compat;
/* intermediate bitmap format */
11 years, 8 months
r13358 vince - in /trunk/netsurf: gtk/scaffolding.c gtk/tabs.c image/ico.c
by netsurf@semichrome.net
Author: vince
Date: Sat Dec 31 06:57:47 2011
New Revision: 13358
URL: http://source.netsurf-browser.org?rev=13358&view=rev
Log:
ensure favicon is correctly set
Modified:
trunk/netsurf/gtk/scaffolding.c
trunk/netsurf/gtk/tabs.c
trunk/netsurf/image/ico.c
Modified: trunk/netsurf/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/scaffolding.c?rev=133...
==============================================================================
--- trunk/netsurf/gtk/scaffolding.c (original)
+++ trunk/netsurf/gtk/scaffolding.c Sat Dec 31 06:57:47 2011
@@ -1998,7 +1998,7 @@
{
struct gtk_scaffolding *g = nsgtk_get_scaffold(_g);
struct bitmap *icon_bitmap = NULL;
- GdkPixbuf *icon_pixbuf;
+ GdkPixbuf *icon_pixbuf = NULL;
if (g->top_level != _g) {
return;
@@ -2007,11 +2007,13 @@
if (icon != NULL) {
icon_bitmap = content_get_bitmap(icon);
if (icon_bitmap != NULL) {
+ LOG(("Using %p bitmap", icon_bitmap));
icon_pixbuf = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16);
- }
+ }
}
if (icon_pixbuf == NULL) {
+ LOG(("Using default favicon"));
g_object_ref(favicon_pixbuf);
icon_pixbuf = favicon_pixbuf;
}
Modified: trunk/netsurf/gtk/tabs.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/tabs.c?rev=13358&r1=1...
==============================================================================
--- trunk/netsurf/gtk/tabs.c (original)
+++ trunk/netsurf/gtk/tabs.c Sat Dec 31 06:57:47 2011
@@ -197,20 +197,11 @@
gtk_widget_show_all(tab_contents);
gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs),
gtk_notebook_get_n_pages(GTK_NOTEBOOK(tabs)) - 1);
- if (option_new_blank) {
- /*char *blankpage = malloc(strlen(res_dir_location) +
- SLEN("file:///blankpage") + 1);
- blankpage = g_strconcat("file:///", res_dir_location,
- "blankpage", NULL); */
- /* segfaults
- struct browser_window *bw =
- nsgtk_get_browser_window(window);
- browser_window_go(bw, blankpage, 0, true); */
- /* free(blankpage); */
- }
+
if (background) {
gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs), remember);
}
+
gtk_widget_grab_focus(GTK_WIDGET(nsgtk_scaffolding_urlbar(
nsgtk_get_scaffold(window))));
}
Modified: trunk/netsurf/image/ico.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/ico.c?rev=13358&r1=...
==============================================================================
--- trunk/netsurf/image/ico.c (original)
+++ trunk/netsurf/image/ico.c Sat Dec 31 06:57:47 2011
@@ -135,6 +135,7 @@
bmp = ico_find(ico->ico, 255, 255);
if (bmp == NULL) {
/* return error */
+ LOG(("Failed to select icon"));
return false;
}
@@ -155,12 +156,18 @@
/* select most appropriate sized icon for size */
bmp = ico_find(ico->ico, data->width, data->height);
+ if (bmp == NULL) {
+ /* return error */
+ LOG(("Failed to select icon"));
+ return false;
+ }
/* ensure its decided */
if (bmp->decoded == false) {
if (bmp_decode(bmp) != BMP_OK) {
return false;
} else {
+ LOG(("Decoding bitmap"));
bitmap_modified(bmp->bitmap);
}
@@ -218,7 +225,14 @@
nsico_content *ico = (nsico_content *) c;
/* TODO: Pick best size for purpose.
* Currently assumes it's for a URL bar. */
- struct bmp_image *bmp = ico_find(ico->ico, 16, 16);
+ struct bmp_image *bmp;
+
+ bmp = ico_find(ico->ico, 16, 16);
+ if (bmp == NULL) {
+ /* return error */
+ LOG(("Failed to select icon"));
+ return NULL;
+ }
if (bmp->decoded == false) {
if (bmp_decode(bmp) != BMP_OK) {
11 years, 8 months
r13357 vince - in /trunk/netsurf/gtk: gui.c gui.h scaffolding.c toolbar.c
by netsurf@semichrome.net
Author: vince
Date: Fri Dec 30 18:00:54 2011
New Revision: 13357
URL: http://source.netsurf-browser.org?rev=13357&view=rev
Log:
load default favicon once
Modified:
trunk/netsurf/gtk/gui.c
trunk/netsurf/gtk/gui.h
trunk/netsurf/gtk/scaffolding.c
trunk/netsurf/gtk/toolbar.c
Modified: trunk/netsurf/gtk/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gui.c?rev=13357&r1=13...
==============================================================================
--- trunk/netsurf/gtk/gui.c (original)
+++ trunk/netsurf/gtk/gui.c Fri Dec 30 18:00:54 2011
@@ -87,6 +87,8 @@
char *print_options_file_location;
char *languages_file_location;
+GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+
struct glade_file_location_s *glade_file_location;
static GtkWindow *nsgtk_warning_window;
@@ -388,6 +390,17 @@
/* Default Icon */
search_default_ico_location = filepath_find(respath, "default.ico");
LOG(("Using '%s' as default search ico", search_default_ico_location));
+
+ /* Default favicon */
+ resource_filename = filepath_find(respath, "favicon.png");
+ if (resource_filename != NULL) {
+ favicon_pixbuf = gdk_pixbuf_new_from_file(resource_filename, NULL);
+ free(resource_filename);
+ if (favicon_pixbuf == NULL) {
+ favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16);
+
+ }
+ }
/* Toolbar inicies file */
toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
Modified: trunk/netsurf/gtk/gui.h
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gui.h?rev=13357&r1=13...
==============================================================================
--- trunk/netsurf/gtk/gui.h (original)
+++ trunk/netsurf/gtk/gui.h Fri Dec 30 18:00:54 2011
@@ -54,6 +54,8 @@
extern char *res_dir_location;
extern char *print_options_file_location;
+extern GdkPixbuf *favicon_pixbuf; /* favicon default pixbuf */
+
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *);
#endif /* GTK_GUI_H */
Modified: trunk/netsurf/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/scaffolding.c?rev=133...
==============================================================================
--- trunk/netsurf/gtk/scaffolding.c (original)
+++ trunk/netsurf/gtk/scaffolding.c Fri Dec 30 18:00:54 2011
@@ -2012,10 +2012,8 @@
}
if (icon_pixbuf == NULL) {
- char imagepath[strlen(res_dir_location) +
- SLEN("favicon.png") + 1];
- sprintf(imagepath, "%sfavicon.png", res_dir_location);
- icon_pixbuf = gdk_pixbuf_new_from_file(imagepath, NULL);
+ g_object_ref(favicon_pixbuf);
+ icon_pixbuf = favicon_pixbuf;
}
if (icon_pixbuf == NULL) {
Modified: trunk/netsurf/gtk/toolbar.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/toolbar.c?rev=13357&r...
==============================================================================
--- trunk/netsurf/gtk/toolbar.c (original)
+++ trunk/netsurf/gtk/toolbar.c Fri Dec 30 18:00:54 2011
@@ -704,10 +704,6 @@
return GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET(
theme->image[HISTORY_BUTTON]), ""));
case URL_BAR_ITEM: {
- char imagefile[strlen(res_dir_location) + SLEN("favicon.png")
- + 1];
- sprintf(imagefile, "%sfavicon.png", res_dir_location);
- GdkPixbuf *iconbuf = gdk_pixbuf_new_from_file(imagefile, NULL);
GtkWidget *entry = nsgtk_entry_new();
GtkWidget *w = GTK_WIDGET(gtk_tool_item_new());
@@ -716,9 +712,9 @@
return NULL;
}
- if (iconbuf != NULL) {
- nsgtk_entry_set_icon_from_pixbuf(entry, GTK_ENTRY_ICON_PRIMARY, iconbuf);
- }
+ nsgtk_entry_set_icon_from_pixbuf(entry,
+ GTK_ENTRY_ICON_PRIMARY,
+ favicon_pixbuf);
gtk_container_add(GTK_CONTAINER(w), entry);
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
11 years, 8 months
r13356 vince - in /trunk/netsurf/gtk: compat.c compat.h scaffolding.c toolbar.c
by netsurf@semichrome.net
Author: vince
Date: Fri Dec 30 17:22:18 2011
New Revision: 13356
URL: http://source.netsurf-browser.org?rev=13356&view=rev
Log:
only use libsexy entry widget prior to gtk 2.16
Modified:
trunk/netsurf/gtk/compat.c
trunk/netsurf/gtk/compat.h
trunk/netsurf/gtk/scaffolding.c
trunk/netsurf/gtk/toolbar.c
Modified: trunk/netsurf/gtk/compat.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/compat.c?rev=13356&r1...
==============================================================================
--- trunk/netsurf/gtk/compat.c (original)
+++ trunk/netsurf/gtk/compat.c Fri Dec 30 17:22:18 2011
@@ -124,3 +124,48 @@
return gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo_box));
#endif
}
+
+GtkWidget *nsgtk_entry_new(void)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ return gtk_entry_new();
+#else
+ return GTK_WIDGET(sexy_icon_entry_new());
+#endif
+}
+
+void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entry), icon_pos, pixbuf);
+#else
+ GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
+
+ if (image != NULL) {
+ sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
+ (SexyIconEntryPosition)icon_pos,
+ image);
+
+ g_object_unref(image);
+ }
+
+#endif
+}
+
+void nsgtk_entry_set_icon_from_stock(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id)
+{
+#if GTK_CHECK_VERSION(2,16,0)
+ gtk_entry_set_icon_from_stock(GTK_ENTRY(entry), icon_pos, stock_id);
+#else
+ GtkImage *image = GTK_IMAGE(gtk_image_new_from_stock(stock_id,
+ GTK_ICON_SIZE_LARGE_TOOLBAR));
+
+ if (image != NULL) {
+ sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
+ (SexyIconEntryPosition)icon_pos,
+ image);
+ g_object_unref(image);
+ }
+
+#endif
+}
Modified: trunk/netsurf/gtk/compat.h
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/compat.h?rev=13356&r1...
==============================================================================
--- trunk/netsurf/gtk/compat.h (original)
+++ trunk/netsurf/gtk/compat.h Fri Dec 30 17:22:18 2011
@@ -37,4 +37,17 @@
void nsgtk_combo_box_text_append_text(GtkWidget *combo_box, const gchar *text);
gchar *nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box);
+GtkWidget *nsgtk_entry_new(void);
+void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf);
+void nsgtk_entry_set_icon_from_stock(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id);
+
+#if !GTK_CHECK_VERSION(2,16,0)
+#include "gtk/sexy_icon_entry.h"
+
+typedef enum {
+ GTK_ENTRY_ICON_PRIMARY = SEXY_ICON_ENTRY_PRIMARY,
+ GTK_ENTRY_ICON_SECONDARY = SEXY_ICON_ENTRY_SECONDARY
+} GtkEntryIconPosition;
+#endif
+
#endif /* NETSURF_GTK_COMPAT_H */
Modified: trunk/netsurf/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/scaffolding.c?rev=133...
==============================================================================
--- trunk/netsurf/gtk/scaffolding.c (original)
+++ trunk/netsurf/gtk/scaffolding.c Fri Dec 30 17:22:18 2011
@@ -74,7 +74,6 @@
#include "gtk/treeview.h"
#include "gtk/window.h"
#include "gtk/options.h"
-#include "gtk/sexy_icon_entry.h"
#include "gtk/compat.h"
#include "gtk/gdk.h"
#include "image/ico.h"
@@ -135,9 +134,7 @@
GtkToolbar *tool_bar;
struct nsgtk_button_connect *buttons[PLACEHOLDER_BUTTON];
GtkImage *throbber;
- GtkImage *icoFav;
struct gtk_search *search;
- GtkImage *webSearchIco;
GtkWidget *webSearchEntry;
GtkPaned *status_pane;
@@ -1993,22 +1990,6 @@
gtk_image_set_from_pixbuf(g->throbber, nsgtk_throbber->framedata[0]);
}
-static GtkImage *
-nsgtk_image_new_from_surface(cairo_surface_t *surface, int w, int h)
-{
- GdkPixbuf *pixbuf;
- GtkImage *image = NULL;
-
- pixbuf = nsgdk_pixbuf_get_from_surface(surface, w, h);
-
- if (pixbuf != NULL) {
- image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
- }
-
- g_object_unref(pixbuf);
-
- return image;
-}
/**
* set favicon
@@ -2016,76 +1997,71 @@
void gui_window_set_icon(struct gui_window *_g, hlcache_handle *icon)
{
struct gtk_scaffolding *g = nsgtk_get_scaffold(_g);
- struct bitmap *icon_bitmap;
- GtkImage *iconImage = NULL;
+ struct bitmap *icon_bitmap = NULL;
+ GdkPixbuf *icon_pixbuf;
if (g->top_level != _g) {
return;
}
- icon_bitmap = (icon != NULL) ? content_get_bitmap(icon) : NULL;
-
- if (icon_bitmap != NULL) {
- iconImage = nsgtk_image_new_from_surface(icon_bitmap->surface, 16, 16);
- }
-
- if (iconImage == NULL) {
+
+ if (icon != NULL) {
+ icon_bitmap = content_get_bitmap(icon);
+ if (icon_bitmap != NULL) {
+ icon_pixbuf = nsgdk_pixbuf_get_from_surface(icon_bitmap->surface, 16, 16);
+ }
+ }
+
+ if (icon_pixbuf == NULL) {
char imagepath[strlen(res_dir_location) +
SLEN("favicon.png") + 1];
sprintf(imagepath, "%sfavicon.png", res_dir_location);
- iconImage = GTK_IMAGE(gtk_image_new_from_file(imagepath));
- }
-
- if (iconImage == NULL)
+ icon_pixbuf = gdk_pixbuf_new_from_file(imagepath, NULL);
+ }
+
+ if (icon_pixbuf == NULL) {
return;
-
- if (g->icoFav != NULL) {
- g_object_unref(g->icoFav);
- }
-
- g->icoFav = iconImage;
-
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(g->url_bar),
- SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(g->icoFav));
+ }
+
+ nsgtk_entry_set_icon_from_pixbuf(g->url_bar,
+ GTK_ENTRY_ICON_PRIMARY,
+ icon_pixbuf);
+
gtk_widget_show_all(GTK_WIDGET(g->buttons[URL_BAR_ITEM]->button));
+
+ g_object_unref(icon_pixbuf);
+
}
void gui_window_set_search_ico(hlcache_handle *ico)
{
- GdkPixbuf *pbico = NULL;
- GtkImage *searchico;
- struct bitmap *ico_bitmap;
+ struct bitmap *srch_bitmap;
nsgtk_scaffolding *current;
-
- if (ico == NULL && (ico = search_web_ico()) == NULL)
+ GdkPixbuf *srch_pixbuf;
+
+ if ((ico == NULL) &&
+ (ico = search_web_ico()) == NULL) {
return;
-
- ico_bitmap = content_get_bitmap(ico);
- if (ico_bitmap == NULL)
+ }
+
+ srch_bitmap = content_get_bitmap(ico);
+ if (srch_bitmap == NULL) {
return;
-
- pbico = nsgdk_pixbuf_get_from_surface(ico_bitmap->surface, 16, 16);
- if (pbico == NULL) {
+ }
+
+ srch_pixbuf = nsgdk_pixbuf_get_from_surface(srch_bitmap->surface, 16, 16);
+
+ if (srch_pixbuf == NULL) {
return;
}
-
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
/* add ico to each window's toolbar */
for (current = scaf_list; current != NULL; current = current->next) {
- if (searchico != NULL) {
- /** \todo Are we leaking webSearchIco here? */
- current->webSearchIco = searchico;
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(
- current->webSearchEntry),
- SEXY_ICON_ENTRY_PRIMARY,
- current->webSearchIco);
- }
-
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
- }
-
- g_object_unref(pbico);
-
+ nsgtk_entry_set_icon_from_pixbuf(current->webSearchEntry,
+ GTK_ENTRY_ICON_PRIMARY,
+ srch_pixbuf);
+ }
+
+ g_object_unref(srch_pixbuf);
}
bool nsgtk_scaffolding_is_busy(nsgtk_scaffolding *g)
@@ -2156,8 +2132,6 @@
{
g->url_bar = GTK_WIDGET(gtk_bin_get_child(GTK_BIN(
nsgtk_scaffolding_button(g, URL_BAR_ITEM)->button)));
- g->icoFav = sexy_icon_entry_get_icon(SEXY_ICON_ENTRY(g->url_bar),
- SEXY_ICON_ENTRY_PRIMARY);
gtk_entry_set_completion(GTK_ENTRY(g->url_bar),
g->url_bar_completion);
@@ -2172,8 +2146,6 @@
{
g->webSearchEntry = gtk_bin_get_child(GTK_BIN(
g->buttons[WEBSEARCH_ITEM]->button));
- g->webSearchIco = sexy_icon_entry_get_icon(SEXY_ICON_ENTRY(
- g->webSearchEntry), SEXY_ICON_ENTRY_PRIMARY);
}
void nsgtk_scaffolding_set_websearch(nsgtk_scaffolding *g, const char *content)
Modified: trunk/netsurf/gtk/toolbar.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/toolbar.c?rev=13356&r...
==============================================================================
--- trunk/netsurf/gtk/toolbar.c (original)
+++ trunk/netsurf/gtk/toolbar.c Fri Dec 30 17:22:18 2011
@@ -17,7 +17,12 @@
*/
#include <gtk/gtk.h>
+
#include "desktop/searchweb.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
+
#include "gtk/toolbar.h"
#include "gtk/gui.h"
#include "gtk/scaffolding.h"
@@ -25,10 +30,7 @@
#include "gtk/theme.h"
#include "gtk/throbber.h"
#include "gtk/window.h"
-#include "gtk/sexy_icon_entry.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
+#include "gtk/compat.h"
static GtkTargetEntry entry = {(char *)"nsgtk_button_data",
GTK_TARGET_SAME_APP, 0};
@@ -705,9 +707,8 @@
char imagefile[strlen(res_dir_location) + SLEN("favicon.png")
+ 1];
sprintf(imagefile, "%sfavicon.png", res_dir_location);
- GtkWidget *image = GTK_WIDGET(gtk_image_new_from_file(
- imagefile));
- GtkWidget *entry = GTK_WIDGET(sexy_icon_entry_new());
+ GdkPixbuf *iconbuf = gdk_pixbuf_new_from_file(imagefile, NULL);
+ GtkWidget *entry = nsgtk_entry_new();
GtkWidget *w = GTK_WIDGET(gtk_tool_item_new());
if ((entry == NULL) || (w == NULL)) {
@@ -715,10 +716,9 @@
return NULL;
}
- if (image != NULL)
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
- SEXY_ICON_ENTRY_PRIMARY,
- GTK_IMAGE(image));
+ if (iconbuf != NULL) {
+ nsgtk_entry_set_icon_from_pixbuf(entry, GTK_ENTRY_ICON_PRIMARY, iconbuf);
+ }
gtk_container_add(GTK_CONTAINER(w), entry);
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
@@ -754,9 +754,9 @@
gtk_image_new_from_stock("gtk-find",
GTK_ICON_SIZE_LARGE_TOOLBAR)),
"[websearch]"));
- GtkWidget *image = GTK_WIDGET(gtk_image_new_from_stock(
- "gtk-info", GTK_ICON_SIZE_LARGE_TOOLBAR));
- GtkWidget *entry = GTK_WIDGET(sexy_icon_entry_new());
+
+ GtkWidget *entry = nsgtk_entry_new();
+
GtkWidget *w = GTK_WIDGET(gtk_tool_item_new());
if ((entry == NULL) || (w == NULL)) {
@@ -764,12 +764,9 @@
return NULL;
}
- gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH,
- -1);
- if (image != NULL)
- sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
- SEXY_ICON_ENTRY_PRIMARY,
- GTK_IMAGE(image));
+ gtk_widget_set_size_request(entry, NSGTK_WEBSEARCH_WIDTH, -1);
+
+ nsgtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_PRIMARY, "gtk-info");
gtk_container_add(GTK_CONTAINER(w), entry);
return w;
11 years, 8 months
r13355 vince - /trunk/netsurf/image/ico.c
by netsurf@semichrome.net
Author: vince
Date: Fri Dec 30 13:37:15 2011
New Revision: 13355
URL: http://source.netsurf-browser.org?rev=13355&view=rev
Log:
fix icon image handler marking genrated bitmaps as modified
Modified:
trunk/netsurf/image/ico.c
Modified: trunk/netsurf/image/ico.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/ico.c?rev=13355&r1=...
==============================================================================
--- trunk/netsurf/image/ico.c (original)
+++ trunk/netsurf/image/ico.c Fri Dec 30 13:37:15 2011
@@ -32,6 +32,7 @@
#include "image/bitmap.h"
#include "image/bmp.h"
#include "image/ico.h"
+#include "image/image.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
@@ -42,7 +43,6 @@
struct ico_collection *ico; /** ICO collection data */
- struct bitmap *bitmap; /**< Created NetSurf bitmap */
} nsico_content;
@@ -131,11 +131,12 @@
content__set_title(c, title);
c->size += (ico->ico->width * ico->ico->height * 4) + 16 + 44;
- /* exit as a success */
+ /* select largest icon to ensure one can be selected */
bmp = ico_find(ico->ico, 255, 255);
- assert(bmp);
- ico->bitmap = bmp->bitmap;
- bitmap_modified(ico->bitmap);
+ if (bmp == NULL) {
+ /* return error */
+ return false;
+ }
content_set_ready(c);
content_set_done(c);
@@ -149,24 +150,23 @@
static bool nsico_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
- nsico_content *ico = (nsico_content *) c;
- struct bmp_image *bmp = ico_find(ico->ico, data->width, data->height);
- bitmap_flags_t flags = BITMAPF_NONE;
-
+ nsico_content *ico = (nsico_content *)c;
+ struct bmp_image *bmp;
+
+ /* select most appropriate sized icon for size */
+ bmp = ico_find(ico->ico, data->width, data->height);
+
+ /* ensure its decided */
if (bmp->decoded == false) {
- if (bmp_decode(bmp) != BMP_OK)
+ if (bmp_decode(bmp) != BMP_OK) {
return false;
- }
-
- ico->bitmap = bmp->bitmap;
-
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- ico->bitmap, data->background_colour, flags);
+ } else {
+ bitmap_modified(bmp->bitmap);
+ }
+
+ }
+
+ return image_bitmap_plot(bmp->bitmap, data, clip, ctx);
}
@@ -221,13 +221,14 @@
struct bmp_image *bmp = ico_find(ico->ico, 16, 16);
if (bmp->decoded == false) {
- if (bmp_decode(bmp) != BMP_OK)
+ if (bmp_decode(bmp) != BMP_OK) {
return NULL;
- }
-
- ico->bitmap = bmp->bitmap;
-
- return ico->bitmap;
+ } else {
+ bitmap_modified(bmp->bitmap);
+ }
+ }
+
+ return bmp->bitmap;
}
static content_type nsico_content_type(void)
11 years, 8 months
r13354 vince - in /trunk/netsurf: Docs/ content/ desktop/ gtk/ image/ render/
by netsurf@semichrome.net
Author: vince
Date: Thu Dec 29 18:58:35 2011
New Revision: 13354
URL: http://source.netsurf-browser.org?rev=13354&view=rev
Log:
Change GTK plotting to use cairo surfaces throughout
Added:
trunk/netsurf/gtk/gdk.c
- copied unchanged from r13353, branches/vince/netsurf-cairo/gtk/gdk.c
trunk/netsurf/gtk/gdk.h
- copied unchanged from r13353, branches/vince/netsurf-cairo/gtk/gdk.h
Modified:
trunk/netsurf/Docs/BUILDING-GTK
trunk/netsurf/content/content.h
trunk/netsurf/desktop/plot_style.h
trunk/netsurf/gtk/Makefile.target
trunk/netsurf/gtk/bitmap.c
trunk/netsurf/gtk/bitmap.h
trunk/netsurf/gtk/plotters.c
trunk/netsurf/gtk/print.c
trunk/netsurf/gtk/scaffolding.c
trunk/netsurf/gtk/thumbnail.c
trunk/netsurf/gtk/treeview.c
trunk/netsurf/gtk/window.c
trunk/netsurf/image/gif.c
trunk/netsurf/image/image.c
trunk/netsurf/image/image.h
trunk/netsurf/image/image_cache.c
trunk/netsurf/image/png.c
trunk/netsurf/render/html_redraw.c
Modified: trunk/netsurf/Docs/BUILDING-GTK
URL: http://source.netsurf-browser.org/trunk/netsurf/Docs/BUILDING-GTK?rev=133...
==============================================================================
--- trunk/netsurf/Docs/BUILDING-GTK (original)
+++ trunk/netsurf/Docs/BUILDING-GTK Thu Dec 29 18:58:35 2011
@@ -67,7 +67,7 @@
Debian-like OS:
$ apt-get install libglade2-dev libcurl3-dev libxml2-dev libmng-dev
- $ apt-get install librsvg2-dev liblcms1-dev
+ $ apt-get install librsvg2-dev liblcms1-dev libjpeg-dev
Recent OS versions might need libcurl4-dev instead of libcurl3-dev but
note that when it has not been built with OpenSSL, the SSL_CTX is not
Modified: trunk/netsurf/content/content.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content.h?rev=133...
==============================================================================
--- trunk/netsurf/content/content.h (original)
+++ trunk/netsurf/content/content.h Thu Dec 29 18:58:35 2011
@@ -112,25 +112,25 @@
struct content_rfc5988_link *rfc5988_link;
};
-
+/** parameters to content redraw */
struct content_redraw_data {
- int x; /** coordinate for top-left of redraw */
- int y; /** coordinate for top-left of redraw */
+ int x; /**< coordinate for top-left of redraw */
+ int y; /**< coordinate for top-left of redraw */
/** dimensions to render content at
* (for scaling contents with intrinsic dimensions) */
- int width; /* horizontal */
- int height; /* vertical */
-
- /** the background colour */
+ int width; /**< horizontal dimension */
+ int height; /**< vertical dimension */
+
+ /** The background colour */
colour background_colour;
/** Scale for redraw
* (for scaling contents without intrinsic dimensions) */
- float scale; /* scale factor */
-
- bool repeat_x; /* whether content is tiled in x direction */
- bool repeat_y; /* whether content is tiled in y direction */
+ float scale; /**< Scale factor for redraw */
+
+ bool repeat_x; /**< whether content is tiled in x direction */
+ bool repeat_y; /**< whether content is tiled in y direction */
};
/* The following are for hlcache */
Modified: trunk/netsurf/desktop/plot_style.h
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/plot_style.h?rev=...
==============================================================================
--- trunk/netsurf/desktop/plot_style.h (original)
+++ trunk/netsurf/desktop/plot_style.h Thu Dec 29 18:58:35 2011
@@ -64,10 +64,15 @@
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0)
+/* get a bitmap pixel (image/bitmap.h) into a plot colour */
+#define pixel_to_colour(b) \
+ b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)
+
/**
* Colour type: XBGR
*/
typedef uint32_t colour;
+
/**
* Magical transparent value
*/
Modified: trunk/netsurf/gtk/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/Makefile.target?rev=1...
==============================================================================
--- trunk/netsurf/gtk/Makefile.target (original)
+++ trunk/netsurf/gtk/Makefile.target Thu Dec 29 18:58:35 2011
@@ -71,7 +71,7 @@
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \
- treeview.c scaffolding.c completion.c login.c throbber.c \
+ treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
selection.c history.c window.c filetype.c download.c menu.c \
print.c save.c search.c tabs.c theme.c toolbar.c \
sexy_icon_entry.c compat.c cookies.c hotlist.c system_colour.c \
Modified: trunk/netsurf/gtk/bitmap.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/bitmap.c?rev=13354&r1...
==============================================================================
--- trunk/netsurf/gtk/bitmap.c (original)
+++ trunk/netsurf/gtk/bitmap.c Thu Dec 29 18:58:35 2011
@@ -25,26 +25,16 @@
#include <assert.h>
#include <stdbool.h>
#include <string.h>
-#include <gdk/gdk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include <cairo.h>
+#include <gtk/gtk.h>
#include "content/content.h"
+#include "gtk/scaffolding.h"
#include "gtk/bitmap.h"
-#include "gtk/scaffolding.h"
#include "image/bitmap.h"
#include "utils/log.h"
-
-struct bitmap {
- GdkPixbuf *primary;
- GdkPixbuf *pretile_x;
- GdkPixbuf *pretile_y;
- GdkPixbuf *pretile_xy;
- bool opaque;
-};
-
-#define MIN_PRETILE_WIDTH 256
-#define MIN_PRETILE_HEIGHT 256
/**
@@ -58,18 +48,24 @@
void *bitmap_create(int width, int height, unsigned int state)
{
- struct bitmap *bmp = malloc(sizeof(struct bitmap));
-
- bmp->primary = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true,
- 8, width, height);
-
- /* fill the pixbuf in with 100% transparent black, as the memory
- * won't have been cleared.
- */
- gdk_pixbuf_fill(bmp->primary, 0);
- bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL;
- bmp->opaque = (state & BITMAP_OPAQUE) != 0;
- return bmp;
+ struct bitmap *gbitmap;
+
+ gbitmap = calloc(1, sizeof(struct bitmap));
+ if (gbitmap != NULL) {
+ if ((state & BITMAP_OPAQUE) != 0) {
+ gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
+ } else {
+ gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+ }
+
+ if (cairo_surface_status(gbitmap->surface) != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy(gbitmap->surface);
+ free(gbitmap);
+ gbitmap = NULL;
+ }
+ }
+
+ return gbitmap;
}
@@ -81,9 +77,47 @@
*/
void bitmap_set_opaque(void *vbitmap, bool opaque)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
- bitmap->opaque = opaque;
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ cairo_format_t fmt;
+ cairo_surface_t *nsurface = NULL;
+
+ assert(gbitmap);
+
+ fmt = cairo_image_surface_get_format(gbitmap->surface);
+ if (fmt == CAIRO_FORMAT_RGB24) {
+ if (opaque == false) {
+ /* opaque to transparent */
+ nsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ cairo_image_surface_get_width(gbitmap->surface),
+ cairo_image_surface_get_height(gbitmap->surface));
+
+ }
+
+ } else {
+ if (opaque == true) {
+ /* transparent to opaque */
+ nsurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
+ cairo_image_surface_get_width(gbitmap->surface),
+ cairo_image_surface_get_height(gbitmap->surface));
+
+ }
+ }
+
+ if (nsurface != NULL) {
+ if (cairo_surface_status(nsurface) != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy(nsurface);
+ } else {
+ memcpy(cairo_image_surface_get_data(nsurface),
+ cairo_image_surface_get_data(gbitmap->surface),
+ cairo_image_surface_get_stride(gbitmap->surface) * cairo_image_surface_get_height(gbitmap->surface));
+ cairo_surface_destroy(gbitmap->surface);
+ gbitmap->surface = nsurface;
+
+ cairo_surface_mark_dirty(gbitmap->surface);
+
+ }
+
+ }
}
@@ -95,23 +129,46 @@
*/
bool bitmap_test_opaque(void *vbitmap)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
-/* todo: test if bitmap is opaque */
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ unsigned char *pixels;
+ int pcount;
+ int ploop;
+
+ assert(gbitmap);
+
+ pixels = cairo_image_surface_get_data(gbitmap->surface);
+
+ pcount = cairo_image_surface_get_stride(gbitmap->surface) *
+ cairo_image_surface_get_height(gbitmap->surface);
+
+ for (ploop = 3; ploop < pcount; ploop += 4) {
+ if (pixels[ploop] != 0xff) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Gets whether a bitmap should be plotted opaque
+ *
+ * \param vbitmap a bitmap, as returned by bitmap_create()
+ */
+bool bitmap_get_opaque(void *vbitmap)
+{
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ cairo_format_t fmt;
+
+ assert(gbitmap);
+
+ fmt = cairo_image_surface_get_format(gbitmap->surface);
+ if (fmt == CAIRO_FORMAT_RGB24) {
+ return true;
+ }
+
return false;
-}
-
-
-/**
- * Gets whether a bitmap should be plotted opaque
- *
- * \param vbitmap a bitmap, as returned by bitmap_create()
- */
-bool bitmap_get_opaque(void *vbitmap)
-{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
- return bitmap->opaque;
}
@@ -127,9 +184,12 @@
unsigned char *bitmap_get_buffer(void *vbitmap)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
- return (unsigned char *)gdk_pixbuf_get_pixels(bitmap->primary);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ cairo_surface_flush(gbitmap->surface);
+
+ return cairo_image_surface_get_data(gbitmap->surface);
}
@@ -142,9 +202,10 @@
size_t bitmap_get_rowstride(void *vbitmap)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
- return gdk_pixbuf_get_rowstride(bitmap->primary);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ return cairo_image_surface_get_stride(gbitmap->surface);
}
@@ -157,21 +218,13 @@
size_t bitmap_get_bpp(void *vbitmap)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
return 4;
}
-static void
-gtk_bitmap_free_pretiles(struct bitmap *bitmap)
-{
-#define FREE_TILE(XY) if (bitmap->pretile_##XY) g_object_unref(bitmap->pretile_##XY); bitmap->pretile_##XY = NULL
- FREE_TILE(x);
- FREE_TILE(y);
- FREE_TILE(xy);
-#undef FREE_TILE
-}
/**
* Free a bitmap.
@@ -181,11 +234,16 @@
void bitmap_destroy(void *vbitmap)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- assert(bitmap);
- gtk_bitmap_free_pretiles(bitmap);
- g_object_unref(bitmap->primary);
- free(bitmap);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ if (gbitmap->surface != NULL) {
+ cairo_surface_destroy(gbitmap->surface);
+ }
+ if (gbitmap->scsurface != NULL) {
+ cairo_surface_destroy(gbitmap->scsurface);
+ }
+ free(gbitmap);
}
@@ -200,16 +258,10 @@
bool bitmap_save(void *vbitmap, const char *path, unsigned flags)
{
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- GError *err = NULL;
-
- gdk_pixbuf_save(bitmap->primary, path, "png", &err, NULL);
-
- if (err == NULL)
- /* TODO: report an error here */
- return false;
-
- return true;
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ return false;
}
@@ -219,8 +271,52 @@
* \param bitmap a bitmap, as returned by bitmap_create()
*/
void bitmap_modified(void *vbitmap) {
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- gtk_bitmap_free_pretiles(bitmap);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ int pixel_loop;
+ int pixel_count;
+ uint32_t *pixels;
+ uint32_t pixel;
+ cairo_format_t fmt;
+
+ assert(gbitmap);
+
+ fmt = cairo_image_surface_get_format(gbitmap->surface);
+
+ pixel_count = cairo_image_surface_get_width(gbitmap->surface) *
+ cairo_image_surface_get_height(gbitmap->surface);
+ pixels = (uint32_t *)cairo_image_surface_get_data(gbitmap->surface);
+
+ if (fmt == CAIRO_FORMAT_RGB24) {
+ for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
+ pixel = pixels[pixel_loop];
+ pixels[pixel_loop] = (pixel & 0xff00ff00) |
+ ((pixel & 0xff) << 16) |
+ ((pixel & 0xff0000) >> 16);
+ }
+ } else {
+ uint8_t t, r, g, b;
+ for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
+ pixel = pixels[pixel_loop];
+ t = (pixel & 0xff000000) >> 24;
+ if (t == 0) {
+ pixels[pixel_loop] = 0;
+ } else {
+ r = (pixel & 0xff0000) >> 16;
+ g = (pixel & 0xff00) >> 8;
+ b = pixel & 0xff;
+
+ pixels[pixel_loop] = (t << 24) |
+ ((r * t) >> 8) |
+ ((g * t) >> 8) << 8 |
+ ((b * t) >> 8) << 16;
+
+ }
+ }
+ }
+
+ cairo_surface_mark_dirty(gbitmap->surface);
+
+ gbitmap->converted = true;
}
@@ -236,113 +332,17 @@
}
int bitmap_get_width(void *vbitmap){
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- return gdk_pixbuf_get_width(bitmap->primary);
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ return cairo_image_surface_get_width(gbitmap->surface);
}
int bitmap_get_height(void *vbitmap){
- struct bitmap *bitmap = (struct bitmap *)vbitmap;
- return gdk_pixbuf_get_height(bitmap->primary);
-}
-
-static GdkPixbuf *
-gtk_bitmap_generate_pretile(GdkPixbuf *primary, int repeat_x, int repeat_y)
-{
- int width = gdk_pixbuf_get_width(primary);
- int height = gdk_pixbuf_get_height(primary);
- size_t primary_stride = gdk_pixbuf_get_rowstride(primary);
- GdkPixbuf *result = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8,
- width * repeat_x, height * repeat_y);
- char *target_buffer = (char *)gdk_pixbuf_get_pixels(result);
- int x,y,row;
- /* This algorithm won't work if the strides are not multiples */
- assert((size_t)gdk_pixbuf_get_rowstride(result) ==
- (primary_stride * repeat_x));
-
- if (repeat_x == 1 && repeat_y == 1) {
- g_object_ref(primary);
- g_object_unref(result);
- return primary;
- }
-
- for (y = 0; y < repeat_y; ++y) {
- char *primary_buffer = (char *)gdk_pixbuf_get_pixels(primary);
- for (row = 0; row < height; ++row) {
- for (x = 0; x < repeat_x; ++x) {
- memcpy(target_buffer,
- primary_buffer, primary_stride);
- target_buffer += primary_stride;
- }
- primary_buffer += primary_stride;
- }
- }
- return result;
-}
-
-/**
- * The primary image associated with this bitmap object.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-GdkPixbuf *
-gtk_bitmap_get_primary(struct bitmap *bitmap)
-{
- if (bitmap != NULL)
- return bitmap->primary;
- else
- return NULL;
-}
-
-/**
- * The X-pretiled image associated with this bitmap object.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-GdkPixbuf *
-gtk_bitmap_get_pretile_x(struct bitmap* bitmap)
-{
- if (!bitmap->pretile_x) {
- int width = gdk_pixbuf_get_width(bitmap->primary);
- int xmult = (MIN_PRETILE_WIDTH + width - 1)/width;
- LOG(("Pretiling %p for X*%d", bitmap, xmult));
- bitmap->pretile_x = gtk_bitmap_generate_pretile(bitmap->primary, xmult, 1);
- }
- return bitmap->pretile_x;
-
-}
-
-/**
- * The Y-pretiled image associated with this bitmap object.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-GdkPixbuf *
-gtk_bitmap_get_pretile_y(struct bitmap* bitmap)
-{
- if (!bitmap->pretile_y) {
- int height = gdk_pixbuf_get_height(bitmap->primary);
- int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height;
- LOG(("Pretiling %p for Y*%d", bitmap, ymult));
- bitmap->pretile_y = gtk_bitmap_generate_pretile(bitmap->primary, 1, ymult);
- }
- return bitmap->pretile_y;
-}
-
-/**
- * The XY-pretiled image associated with this bitmap object.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-GdkPixbuf *
-gtk_bitmap_get_pretile_xy(struct bitmap* bitmap)
-{
- if (!bitmap->pretile_xy) {
- int width = gdk_pixbuf_get_width(bitmap->primary);
- int height = gdk_pixbuf_get_height(bitmap->primary);
- int xmult = (MIN_PRETILE_WIDTH + width - 1)/width;
- int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height;
- LOG(("Pretiling %p for X*%d Y*%d", bitmap, xmult, ymult));
- bitmap->pretile_xy = gtk_bitmap_generate_pretile(bitmap->primary, xmult, ymult);
- }
- return bitmap->pretile_xy;
-}
+ struct bitmap *gbitmap = (struct bitmap *)vbitmap;
+ assert(gbitmap);
+
+ return cairo_image_surface_get_height(gbitmap->surface);
+}
+
+
Modified: trunk/netsurf/gtk/bitmap.h
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/bitmap.h?rev=13354&r1...
==============================================================================
--- trunk/netsurf/gtk/bitmap.h (original)
+++ trunk/netsurf/gtk/bitmap.h Thu Dec 29 18:58:35 2011
@@ -19,15 +19,13 @@
#ifndef NS_GTK_BITMAP_H
#define NS_GTK_BITMAP_H
-#include <gdk/gdk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <cairo.h>
#include "image/bitmap.h"
-GdkPixbuf *gtk_bitmap_get_primary(struct bitmap*);
-GdkPixbuf *gtk_bitmap_get_pretile_x(struct bitmap*);
-GdkPixbuf *gtk_bitmap_get_pretile_y(struct bitmap*);
-GdkPixbuf *gtk_bitmap_get_pretile_xy(struct bitmap*);
-
-
+struct bitmap {
+ cairo_surface_t *surface; /* original cairo surface */
+ cairo_surface_t *scsurface; /* scaled surface */
+ bool converted; /** set if the surface data has been converted */
+};
#endif /* NS_GTK_BITMAP_H */
Modified: trunk/netsurf/gtk/plotters.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/plotters.c?rev=13354&...
==============================================================================
--- trunk/netsurf/gtk/plotters.c (original)
+++ trunk/netsurf/gtk/plotters.c Thu Dec 29 18:58:35 2011
@@ -42,7 +42,6 @@
#include "gtk/bitmap.h"
GtkWidget *current_widget;
-GdkDrawable *current_drawable;
cairo_t *current_cr;
static GdkRectangle cliprect;
@@ -281,7 +280,7 @@
static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
- GdkPixbuf *pixbuf, colour bg)
+ struct bitmap *bitmap, colour bg)
{
/* XXX: This currently ignores the background colour supplied.
* Does this matter?
@@ -289,6 +288,9 @@
int x0, y0, x1, y1;
int dsrcx, dsrcy, dwidth, dheight;
+ int bmwidth, bmheight;
+
+ cairo_surface_t *bmsurface = bitmap->surface;
/* Bail early if we can */
if (width == 0 || height == 0)
@@ -309,21 +311,20 @@
y1 = (y + height) - (cliprect.y + cliprect.height);
/* Set initial draw geometry */
- dsrcx = dsrcy = 0;
+ dsrcx = x;
+ dsrcy = y;
dwidth = width;
dheight = height;
/* Manually clip draw coordinates to area of image to be rendered */
if (x0 > 0) {
/* Clip left */
- dsrcx = x0;
- x += x0;
+ dsrcx += x0;
dwidth -= x0;
}
if (y0 > 0) {
/* Clip top */
- dsrcy = y0;
- y += y0;
+ dsrcy += y0;
dheight -= y0;
}
if (x1 > 0) {
@@ -339,40 +340,58 @@
/* Nothing to plot */
return true;
+ bmwidth = cairo_image_surface_get_width(bmsurface);
+ bmheight = cairo_image_surface_get_height(bmsurface);
+
/* Render the bitmap */
- if (gdk_pixbuf_get_width(pixbuf) == width &&
- gdk_pixbuf_get_height(pixbuf) == height) {
+ if ((bmwidth == width) && (bmheight == height)) {
/* Bitmap is not scaled */
/* Plot the bitmap */
- gdk_cairo_set_source_pixbuf(current_cr, pixbuf, x - dsrcx, y -dsrcy);
- cairo_rectangle(current_cr, x , y , dwidth, dheight);
+ cairo_set_source_surface(current_cr, bmsurface, x, y);
+ cairo_rectangle(current_cr, dsrcx, dsrcy, dwidth, dheight);
cairo_fill(current_cr);
} else {
/* Bitmap is scaled */
- /* Get scale factors */
- double sx = (double)width / gdk_pixbuf_get_width(pixbuf);
- double sy = (double)height / gdk_pixbuf_get_height(pixbuf);
-
- /* Create bitmap for scaled image portion */
- GdkPixbuf *scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8,
- dwidth, dheight);
- /* Only scale up the portion of the bitmap that we are
- * interested in rendering */
- gdk_pixbuf_scale(pixbuf, scaled,
- 0, 0, dwidth, dheight,
- -dsrcx, -dsrcy, sx, sy,
- option_render_resample ? GDK_INTERP_BILINEAR :
- GDK_INTERP_NEAREST);
- if (!scaled)
- return false;
-
+ if ((bitmap->scsurface != NULL) &&
+ ((cairo_image_surface_get_width(bitmap->scsurface) != width) ||
+ (cairo_image_surface_get_height(bitmap->scsurface) != height))){
+ cairo_surface_destroy(bitmap->scsurface);
+ bitmap->scsurface = NULL;
+ }
+
+ if (bitmap->scsurface == NULL) {
+ bitmap->scsurface = cairo_surface_create_similar(bmsurface,CAIRO_CONTENT_COLOR_ALPHA, width, height);
+ cairo_t *cr = cairo_create(bitmap->scsurface);
+
+ /* Scale *before* setting the source surface (1) */
+ cairo_scale(cr, (double)width / bmwidth, (double)height / bmheight);
+ cairo_set_source_surface(cr, bmsurface, 0, 0);
+
+ /* To avoid getting the edge pixels blended with 0
+ * alpha, which would occur with the default
+ * EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
+ */
+ cairo_pattern_set_extend(cairo_get_source(cr),
+ CAIRO_EXTEND_REFLECT);
+
+ /* Replace the destination with the source instead of
+ * overlaying
+ */
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+ /* Do the actual drawing */
+ cairo_paint(cr);
+
+ cairo_destroy(cr);
+
+ }
/* Plot the scaled bitmap */
- gdk_cairo_set_source_pixbuf(current_cr, scaled, x, y);
- cairo_rectangle(current_cr, x , y , dwidth, dheight);
+ cairo_set_source_surface(current_cr, bitmap->scsurface, x, y);
+ cairo_rectangle(current_cr, dsrcx, dsrcy, dwidth, dheight);
cairo_fill(current_cr);
- g_object_unref(scaled);
+
}
return true;
@@ -383,52 +402,46 @@
bitmap_flags_t flags)
{
int doneheight = 0, donewidth = 0;
- GdkPixbuf *primary;
- GdkPixbuf *pretiled = NULL;
-
bool repeat_x = (flags & BITMAPF_REPEAT_X);
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just pass it on */
- primary = gtk_bitmap_get_primary(bitmap);
- return nsgtk_plot_pixbuf(x, y, width, height, primary, bg);
- }
-
- if (repeat_x && !repeat_y)
- pretiled = gtk_bitmap_get_pretile_x(bitmap);
- if (repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_xy(bitmap);
- if (!repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_y(bitmap);
-
- assert(pretiled != NULL);
-
- primary = gtk_bitmap_get_primary(bitmap);
- /* use the primary and pretiled widths to scale the w/h provided */
- width *= gdk_pixbuf_get_width(pretiled);
- width /= gdk_pixbuf_get_width(primary);
- height *= gdk_pixbuf_get_height(pretiled);
- height /= gdk_pixbuf_get_height(primary);
-
- if (y > cliprect.y)
+ return nsgtk_plot_pixbuf(x, y, width, height, bitmap, bg);
+ }
+
+ width = bitmap_get_width(bitmap);
+ height = bitmap_get_height(bitmap);
+
+ /* Bail early if we can */
+ if (width == 0 || height == 0)
+ /* Nothing to plot */
+ return true;
+
+ if (y > cliprect.y) {
doneheight = (cliprect.y - height) + ((y - cliprect.y) % height);
- else
+ } else {
doneheight = y;
+ }
while (doneheight < (cliprect.y + cliprect.height)) {
- if (x > cliprect.x)
+ if (x > cliprect.x) {
donewidth = (cliprect.x - width) + ((x - cliprect.x) % width);
- else
+ } else {
donewidth = x;
+ }
+
while (donewidth < (cliprect.x + cliprect.width)) {
nsgtk_plot_pixbuf(donewidth, doneheight,
- width, height, pretiled, bg);
+ width, height, bitmap, bg);
donewidth += width;
- if (!repeat_x) break;
+ if (!repeat_x)
+ break;
}
doneheight += height;
- if (!repeat_y) break;
+
+ if (!repeat_y)
+ break;
}
return true;
Modified: trunk/netsurf/gtk/print.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/print.c?rev=13354&r1=...
==============================================================================
--- trunk/netsurf/gtk/print.c (original)
+++ trunk/netsurf/gtk/print.c Thu Dec 29 18:58:35 2011
@@ -72,40 +72,6 @@
g / 255.0, b / 255.0, 1.0);
}
-static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
- GdkPixbuf *pixbuf, colour bg)
-{
- /* XXX: This currently ignores the background colour supplied.
- * Does this matter?
- */
-
- if (width == 0 || height == 0)
- return true;
-
- if (gdk_pixbuf_get_width(pixbuf) == width &&
- gdk_pixbuf_get_height(pixbuf) == height) {
- gdk_cairo_set_source_pixbuf(gtk_print_current_cr, pixbuf, x, y);
- cairo_paint(gtk_print_current_cr);
- } else {
- GdkPixbuf *scaled;
- scaled = gdk_pixbuf_scale_simple(pixbuf,
- width, height,
- /* plotting for the printer doesn't have
- * to be fast so we can use always the
- * interp_style that gives better quality
- */
- GDK_INTERP_BILINEAR);
- if (!scaled)
- return false;
-
- gdk_cairo_set_source_pixbuf(gtk_print_current_cr, scaled, x, y);
- cairo_paint(gtk_print_current_cr);
-
- g_object_unref(scaled);
- }
-
- return true;
-}
static bool gtk_print_font_paint(int x, int y,
@@ -368,63 +334,166 @@
return true;
}
+
+static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
+ struct bitmap *bitmap, colour bg)
+{
+ int x0, y0, x1, y1;
+ int dsrcx, dsrcy, dwidth, dheight;
+ int bmwidth, bmheight;
+
+ cairo_surface_t *bmsurface = bitmap->surface;
+
+ /* Bail early if we can */
+ if (width == 0 || height == 0)
+ /* Nothing to plot */
+ return true;
+ if ((x > (cliprect.x + cliprect.width)) ||
+ ((x + width) < cliprect.x) ||
+ (y > (cliprect.y + cliprect.height)) ||
+ ((y + height) < cliprect.y)) {
+ /* Image completely outside clip region */
+ return true;
+ }
+
+ /* Get clip rectangle / image rectangle edge differences */
+ x0 = cliprect.x - x;
+ y0 = cliprect.y - y;
+ x1 = (x + width) - (cliprect.x + cliprect.width);
+ y1 = (y + height) - (cliprect.y + cliprect.height);
+
+ /* Set initial draw geometry */
+ dsrcx = x;
+ dsrcy = y;
+ dwidth = width;
+ dheight = height;
+
+ /* Manually clip draw coordinates to area of image to be rendered */
+ if (x0 > 0) {
+ /* Clip left */
+ dsrcx += x0;
+ dwidth -= x0;
+ }
+ if (y0 > 0) {
+ /* Clip top */
+ dsrcy += y0;
+ dheight -= y0;
+ }
+ if (x1 > 0) {
+ /* Clip right */
+ dwidth -= x1;
+ }
+ if (y1 > 0) {
+ /* Clip bottom */
+ dheight -= y1;
+ }
+
+ if (dwidth == 0 || dheight == 0)
+ /* Nothing to plot */
+ return true;
+
+ bmwidth = cairo_image_surface_get_width(bmsurface);
+ bmheight = cairo_image_surface_get_height(bmsurface);
+
+ /* Render the bitmap */
+ if ((bmwidth == width) && (bmheight == height)) {
+ /* Bitmap is not scaled */
+ /* Plot the bitmap */
+ cairo_set_source_surface(gtk_print_current_cr, bmsurface, x, y);
+ cairo_rectangle(gtk_print_current_cr, dsrcx, dsrcy, dwidth, dheight);
+ cairo_fill(gtk_print_current_cr);
+
+ } else {
+ /* Bitmap is scaled */
+ if ((bitmap->scsurface != NULL) &&
+ ((cairo_image_surface_get_width(bitmap->scsurface) != width) ||
+ (cairo_image_surface_get_height(bitmap->scsurface) != height))){
+ cairo_surface_destroy(bitmap->scsurface);
+ bitmap->scsurface = NULL;
+ }
+
+ if (bitmap->scsurface == NULL) {
+ bitmap->scsurface = cairo_surface_create_similar(bmsurface,CAIRO_CONTENT_COLOR_ALPHA, width, height);
+ cairo_t *cr = cairo_create(bitmap->scsurface);
+
+ /* Scale *before* setting the source surface (1) */
+ cairo_scale(cr, (double)width / bmwidth, (double)height / bmheight);
+ cairo_set_source_surface(cr, bmsurface, 0, 0);
+
+ /* To avoid getting the edge pixels blended with 0
+ * alpha, which would occur with the default
+ * EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
+ */
+ cairo_pattern_set_extend(cairo_get_source(cr),
+ CAIRO_EXTEND_REFLECT);
+
+ /* Replace the destination with the source instead of
+ * overlaying
+ */
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+ /* Do the actual drawing */
+ cairo_paint(cr);
+
+ cairo_destroy(cr);
+
+ }
+ /* Plot the scaled bitmap */
+ cairo_set_source_surface(gtk_print_current_cr, bitmap->scsurface, x, y);
+ cairo_rectangle(gtk_print_current_cr, dsrcx, dsrcy, dwidth, dheight);
+ cairo_fill(gtk_print_current_cr);
+
+ }
+
+ return true;
+}
+
+
static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
int doneheight = 0, donewidth = 0;
- GdkPixbuf *primary;
- GdkPixbuf *pretiled = NULL;
-
- bool repeat_x = (flags & BITMAPF_REPEAT_X);
- bool repeat_y = (flags & BITMAPF_REPEAT_Y);
+ bool repeat_x = (flags & BITMAPF_REPEAT_X);
+ bool repeat_y = (flags & BITMAPF_REPEAT_Y);
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just pass it on */
- primary = gtk_bitmap_get_primary(bitmap);
- return nsgtk_print_plot_pixbuf(x, y, width, height, primary, bg);
- }
-
- if (repeat_x && !repeat_y)
- pretiled = gtk_bitmap_get_pretile_x(bitmap);
- if (repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_xy(bitmap);
- if (!repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_y(bitmap);
-
- assert(pretiled != NULL);
-
- primary = gtk_bitmap_get_primary(bitmap);
-
- /* use the primary and pretiled widths to scale the w/h provided */
- width *= gdk_pixbuf_get_width(pretiled);
- width /= gdk_pixbuf_get_width(primary);
- height *= gdk_pixbuf_get_height(pretiled);
- height /= gdk_pixbuf_get_height(primary);
+ return nsgtk_print_plot_pixbuf(x, y, width, height, bitmap, bg);
+ }
+
+ width = bitmap_get_width(bitmap);
+ height = bitmap_get_height(bitmap);
+
+ /* Bail early if we can */
+ if (width == 0 || height == 0)
+ /* Nothing to plot */
+ return true;
if (y > cliprect.y) {
- doneheight = (cliprect.y - height) +
- ((y - cliprect.y) % height);
- } else
+ doneheight = (cliprect.y - height) + ((y - cliprect.y) % height);
+ } else {
doneheight = y;
+ }
while (doneheight < (cliprect.y + cliprect.height)) {
if (x > cliprect.x) {
- donewidth = (cliprect.x - width) +
- ((x - cliprect.x) % width);
- } else
+ donewidth = (cliprect.x - width) + ((x - cliprect.x) % width);
+ } else {
donewidth = x;
+ }
while (donewidth < (cliprect.x + cliprect.width)) {
nsgtk_print_plot_pixbuf(donewidth, doneheight,
- width, height, pretiled, bg);
+ width, height, bitmap, bg);
donewidth += width;
- if (!repeat_x) break;
+ if (!repeat_x)
+ break;
}
-
doneheight += height;
- if (!repeat_y) break;
+ if (!repeat_y)
+ break;
}
return true;
Modified: trunk/netsurf/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/scaffolding.c?rev=133...
==============================================================================
--- trunk/netsurf/gtk/scaffolding.c (original)
+++ trunk/netsurf/gtk/scaffolding.c Thu Dec 29 18:58:35 2011
@@ -76,6 +76,7 @@
#include "gtk/options.h"
#include "gtk/sexy_icon_entry.h"
#include "gtk/compat.h"
+#include "gtk/gdk.h"
#include "image/ico.h"
#include "render/box.h"
#include "render/font.h"
@@ -1517,9 +1518,8 @@
};
current_widget = widget;
- current_drawable = widget->window;
-
- current_cr = gdk_cairo_create(current_drawable);
+
+ current_cr = gdk_cairo_create(widget->window);
clip.x0 = event->area.x;
clip.y0 = event->area.y;
@@ -1993,6 +1993,23 @@
gtk_image_set_from_pixbuf(g->throbber, nsgtk_throbber->framedata[0]);
}
+static GtkImage *
+nsgtk_image_new_from_surface(cairo_surface_t *surface, int w, int h)
+{
+ GdkPixbuf *pixbuf;
+ GtkImage *image = NULL;
+
+ pixbuf = nsgdk_pixbuf_get_from_surface(surface, w, h);
+
+ if (pixbuf != NULL) {
+ image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
+ }
+
+ g_object_unref(pixbuf);
+
+ return image;
+}
+
/**
* set favicon
*/
@@ -2002,23 +2019,16 @@
struct bitmap *icon_bitmap;
GtkImage *iconImage = NULL;
- if (g->top_level != _g)
+ if (g->top_level != _g) {
return;
-
+ }
icon_bitmap = (icon != NULL) ? content_get_bitmap(icon) : NULL;
if (icon_bitmap != NULL) {
- GdkPixbuf *pb = gtk_bitmap_get_primary(icon_bitmap);
-
- if ((pb != NULL) &&
- (gdk_pixbuf_get_width(pb) > 0) &&
- (gdk_pixbuf_get_height(pb) > 0)) {
- pb = gdk_pixbuf_scale_simple(pb, 16, 16, GDK_INTERP_HYPER);
- iconImage = GTK_IMAGE(gtk_image_new_from_pixbuf(pb));
- }
- }
+ iconImage = nsgtk_image_new_from_surface(icon_bitmap->surface, 16, 16);
+ }
+
if (iconImage == NULL) {
- /** \todo Does pb need cleaning up? */
char imagepath[strlen(res_dir_location) +
SLEN("favicon.png") + 1];
sprintf(imagepath, "%sfavicon.png", res_dir_location);
@@ -2028,8 +2038,10 @@
if (iconImage == NULL)
return;
- if (g->icoFav != NULL)
+ if (g->icoFav != NULL) {
g_object_unref(g->icoFav);
+ }
+
g->icoFav = iconImage;
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(g->url_bar),
@@ -2039,7 +2051,7 @@
void gui_window_set_search_ico(hlcache_handle *ico)
{
- GdkPixbuf *pbico;
+ GdkPixbuf *pbico = NULL;
GtkImage *searchico;
struct bitmap *ico_bitmap;
nsgtk_scaffolding *current;
@@ -2051,16 +2063,12 @@
if (ico_bitmap == NULL)
return;
- pbico = gtk_bitmap_get_primary(ico_bitmap);
- if (pbico != NULL && gdk_pixbuf_get_width(pbico) > 0 &&
- gdk_pixbuf_get_height(pbico) > 0) {
- pbico = gdk_pixbuf_scale_simple(pbico, 20, 20,
- GDK_INTERP_HYPER);
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
- } else {
- /** \todo Does pbico need cleaning up? */
+ pbico = nsgdk_pixbuf_get_from_surface(ico_bitmap->surface, 16, 16);
+ if (pbico == NULL) {
return;
}
+
+ searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
/* add ico to each window's toolbar */
for (current = scaf_list; current != NULL; current = current->next) {
@@ -2072,11 +2080,12 @@
SEXY_ICON_ENTRY_PRIMARY,
current->webSearchIco);
}
- if (pbico != NULL)
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
- else
- searchico = NULL;
- }
+
+ searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
+ }
+
+ g_object_unref(pbico);
+
}
bool nsgtk_scaffolding_is_busy(nsgtk_scaffolding *g)
Modified: trunk/netsurf/gtk/thumbnail.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/thumbnail.c?rev=13354...
==============================================================================
--- trunk/netsurf/gtk/thumbnail.c (original)
+++ trunk/netsurf/gtk/thumbnail.c Thu Dec 29 18:58:35 2011
@@ -52,15 +52,11 @@
bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
const char *url)
{
- GdkPixbuf *pixbuf;
+ cairo_surface_t *dsurface = bitmap->surface;
+ cairo_surface_t *surface;
+ cairo_t *old_cr;
+ gint dwidth, dheight;
int cwidth, cheight;
- gint width;
- gint height;
- gint depth;
- GdkPixmap *pixmap;
- GdkPixbuf *big;
- double scale;
-
struct redraw_context ctx = {
.interactive = false,
.background_images = true,
@@ -70,11 +66,8 @@
assert(content);
assert(bitmap);
- /* Get details of required final thumbnail image */
- pixbuf = gtk_bitmap_get_primary(bitmap);
- width = gdk_pixbuf_get_width(pixbuf);
- height = gdk_pixbuf_get_height(pixbuf);
- depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
+ dwidth = cairo_image_surface_get_width(dsurface);
+ dheight = cairo_image_surface_get_height(dsurface);
/* Calculate size of buffer to render the content into */
/* We get the width from the content width, unless it exceeds 1024,
@@ -82,56 +75,54 @@
* large render buffers for huge contents, which would eat memory and
* cripple performance. */
cwidth = min(content_get_width(content), 1024);
+
/* The height is set in proportion with the width, according to the
* aspect ratio of the required thumbnail. */
- cheight = ((cwidth * height) + (width / 2)) / width;
+ cheight = ((cwidth * dheight) + (dwidth / 2)) / dwidth;
- /* Create buffer to render into */
- pixmap = gdk_pixmap_new(NULL, cwidth, cheight, depth);
-
- if (pixmap == NULL) {
- /* the creation failed for some reason: most likely because
- * we've been asked to create with with at least one dimention
- * as zero. The RISC OS thumbnail generator returns false
- * from here when it can't create a bitmap, so we assume it's
- * safe to do so here too.
- */
+ /* Create surface to render into */
+ surface = cairo_surface_create_similar(dsurface, CAIRO_CONTENT_COLOR_ALPHA, cwidth, cheight);
+
+ if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy(surface);
return false;
}
- gdk_drawable_set_colormap(pixmap, gdk_colormap_get_system());
-
- /* set to plot to pixmap */
- current_drawable = pixmap;
- current_cr = gdk_cairo_create(current_drawable);
+ old_cr = current_cr;
+ current_cr = cairo_create(surface);
/* render the content */
thumbnail_redraw(content, cwidth, cheight, &ctx);
- /* get the pixbuf we rendered the content into */
- big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
- cwidth, cheight);
+ cairo_destroy(current_cr);
+ current_cr = old_cr;
- /* resample the large plot down to the size of our thumbnail */
- scale = (double)width / (double)cwidth;
- gdk_pixbuf_scale(big, pixbuf, 0, 0, width, height, 0, 0,
- scale, scale, GDK_INTERP_TILES);
+ cairo_t *cr = cairo_create(dsurface);
- /* As a debugging aid, try this to dump out a copy of the thumbnail as
- * a PNG: gdk_pixbuf_save(pixbuf, "thumbnail.png", "png", NULL, NULL);
+ /* Scale *before* setting the source surface (1) */
+ cairo_scale (cr, (double)dwidth / cwidth, (double)dheight / cheight);
+ cairo_set_source_surface (cr, surface, 0, 0);
+
+ /* To avoid getting the edge pixels blended with 0 alpha,
+ * which would occur with the default EXTEND_NONE. Use
+ * EXTEND_PAD for 1.2 or newer (2)
*/
+ cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_REFLECT);
+
+ /* Replace the destination with the source instead of overlaying */
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+ /* Do the actual drawing */
+ cairo_paint(cr);
+
+ cairo_destroy(cr);
+
+ cairo_surface_destroy(surface);
/* register the thumbnail with the URL */
if (url)
urldb_set_thumbnail(url, bitmap);
- bitmap_modified(bitmap);
-
- cairo_destroy(current_cr);
-
- g_object_unref(pixmap);
- g_object_unref(big);
-
return true;
}
Modified: trunk/netsurf/gtk/treeview.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/treeview.c?rev=13354&...
==============================================================================
--- trunk/netsurf/gtk/treeview.c (original)
+++ trunk/netsurf/gtk/treeview.c Thu Dec 29 18:58:35 2011
@@ -182,12 +182,7 @@
height = event->area.height;
current_widget = widget;
- current_drawable = widget->window;
- current_cr = gdk_cairo_create(current_drawable);
-
- current_widget = widget;
- current_drawable = widget->window;
- current_cr = gdk_cairo_create(current_drawable);
+ current_cr = gdk_cairo_create(widget->window);
tree_set_redraw(tree, true);
tree_draw(tree, 0, 0, x, y, width, height, &ctx);
Modified: trunk/netsurf/gtk/window.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/window.c?rev=13354&r1...
==============================================================================
--- trunk/netsurf/gtk/window.c (original)
+++ trunk/netsurf/gtk/window.c Thu Dec 29 18:58:35 2011
@@ -157,10 +157,8 @@
assert(z);
assert(GTK_WIDGET(g->layout) == widget);
-
current_widget = (GtkWidget *)g->layout;
- current_drawable = g->layout->bin_window;
- current_cr = gdk_cairo_create(current_drawable);
+ current_cr = gdk_cairo_create(g->layout->bin_window);
clip.x0 = event->area.x;
clip.y0 = event->area.y;
@@ -169,8 +167,9 @@
browser_window_redraw(g->bw, 0, 0, &clip, &ctx);
- if (g->careth != 0)
+ if (g->careth != 0) {
nsgtk_plot_caret(g->caretx, g->carety, g->careth);
+ }
current_widget = NULL;
cairo_destroy(current_cr);
Modified: trunk/netsurf/image/gif.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/gif.c?rev=13354&r1=...
==============================================================================
--- trunk/netsurf/image/gif.c (original)
+++ trunk/netsurf/image/gif.c Thu Dec 29 18:58:35 2011
@@ -39,6 +39,7 @@
#include "content/hlcache.h"
#include "desktop/options.h"
#include "desktop/plotters.h"
+#include "image/image.h"
#include "image/bitmap.h"
#include "image/gif.h"
#include "utils/log.h"
@@ -337,7 +338,6 @@
const struct rect *clip, const struct redraw_context *ctx)
{
nsgif_content *gif = (nsgif_content *) c;
- bitmap_flags_t flags = BITMAPF_NONE;
if (gif->current_frame != gif->gif->decoded_frame) {
if (nsgif_get_frame(gif) != GIF_OK) {
@@ -345,16 +345,7 @@
}
}
- if ((data->width == -1) && (data->height == -1))
- return true;
-
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- gif->gif->frame_image, data->background_colour, flags);
+ return image_bitmap_plot(gif->gif->frame_image, data, clip, ctx);
}
Modified: trunk/netsurf/image/image.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.c?rev=13354&r...
==============================================================================
--- trunk/netsurf/image/image.c (original)
+++ trunk/netsurf/image/image.c Thu Dec 29 18:58:35 2011
@@ -22,8 +22,11 @@
#include <string.h>
#include "utils/errors.h"
+#include "utils/config.h"
+#include "utils/log.h"
+#include "desktop/plotters.h"
+#include "image/bitmap.h"
-#include "image/image.h"
#include "image/bmp.h"
#include "image/gif.h"
#include "image/ico.h"
@@ -35,7 +38,7 @@
#include "image/svg.h"
#include "image/webp.h"
-#include "utils/config.h"
+#include "image/image.h"
/**
* Initialise image content handlers
@@ -114,3 +117,65 @@
return NSERROR_OK;
}
+
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ const struct rect *clip,
+ const struct redraw_context *ctx)
+{
+ bitmap_flags_t flags = BITMAPF_NONE;
+
+ int width;
+ int height;
+ unsigned char *pixel;
+ plot_style_t fill_style;
+ struct rect area;
+
+ width = bitmap_get_width(bitmap);
+ if (width == 1) {
+ height = bitmap_get_height(bitmap);
+ if (height == 1) {
+ /* optimise 1x1 bitmap plot */
+ pixel = bitmap_get_buffer(bitmap);
+ fill_style.fill_colour = pixel_to_colour(pixel);
+
+ if (bitmap_get_opaque(bitmap) ||
+ ((fill_style.fill_colour & 0xff000000) == 0xff000000)) {
+
+ area = *clip;
+
+ if (data->repeat_x != true) {
+ area.x0 = data->x;
+ area.x1 = data->x + data->width;
+ }
+
+ if (data->repeat_y != true) {
+ area.y0 = data->y;
+ area.y1 = data->y + data->height;
+ }
+
+ fill_style.stroke_type = PLOT_OP_TYPE_NONE;
+ fill_style.fill_type = PLOT_OP_TYPE_SOLID;
+
+ return ctx->plot->rectangle(area.x0, area.y0,
+ area.x1, area.y1,
+ &fill_style);
+
+ } else if ((fill_style.fill_colour & 0xff000000) == 0) {
+ /* transparent pixel used as spacer, skip it */
+ return true;
+ }
+ }
+ }
+
+ /* do the plot */
+ if (data->repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (data->repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
+
+ return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
+ bitmap, data->background_colour, flags);
+
+
+}
Modified: trunk/netsurf/image/image.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.h?rev=13354&r...
==============================================================================
--- trunk/netsurf/image/image.h (original)
+++ trunk/netsurf/image/image.h Thu Dec 29 18:58:35 2011
@@ -25,6 +25,19 @@
#include "utils/errors.h"
+/** Initialise the content handlers for image types.
+ */
nserror image_init(void);
+/** Common image content handler bitmap plot call.
+ *
+ * This plots the specified bitmap controlled by the redraw context
+ * and specific content redraw data. It is a helper specifically
+ * provided for image content handlers redraw callback.
+ */
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ const struct rect *clip,
+ const struct redraw_context *ctx);
+
#endif
Modified: trunk/netsurf/image/image_cache.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image_cache.c?rev=1...
==============================================================================
--- trunk/netsurf/image/image_cache.c (original)
+++ trunk/netsurf/image/image_cache.c Thu Dec 29 18:58:35 2011
@@ -22,13 +22,12 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/errors.h"
-#include "utils/utils.h"
+#include "utils/schedule.h"
#include "utils/log.h"
-#include "utils/config.h"
-#include "utils/schedule.h"
#include "content/content_protected.h"
+
#include "image/image_cache.h"
+#include "image/image.h"
/** Age of an entry within the cache
*
@@ -712,7 +711,6 @@
const struct rect *clip,
const struct redraw_context *ctx)
{
- bitmap_flags_t flags = BITMAPF_NONE;
struct image_cache_entry_s *centry;
/* get the cache entry */
@@ -746,14 +744,7 @@
centry->redraw_count++;
centry->redraw_age = image_cache->current_age;
- /* do the plot */
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- centry->bitmap, data->background_colour, flags);
+ return image_bitmap_plot(centry->bitmap, data, clip, ctx);
}
void image_cache_destroy(struct content *content)
Modified: trunk/netsurf/image/png.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/png.c?rev=13354&r1=...
==============================================================================
--- trunk/netsurf/image/png.c (original)
+++ trunk/netsurf/image/png.c Thu Dec 29 18:58:35 2011
@@ -498,7 +498,9 @@
free((png_bytep *) row_pointers);
- return (struct bitmap *) bitmap;
+ bitmap_modified((struct bitmap *)bitmap);
+
+ return (struct bitmap *)bitmap;
}
static bool nspng_convert(struct content *c)
Modified: trunk/netsurf/render/html_redraw.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/html_redraw.c?rev=...
==============================================================================
--- trunk/netsurf/render/html_redraw.c (original)
+++ trunk/netsurf/render/html_redraw.c Thu Dec 29 18:58:35 2011
@@ -2173,6 +2173,7 @@
width = content_get_width(background->background);
height = content_get_height(background->background);
+ /* ensure clip area only as large as required */
if (!repeat_x) {
if (r.x0 < x)
r.x0 = x;
11 years, 8 months
r13353 vince - in /branches/vince/netsurf-cairo/gtk: print.c scaffolding.c
by netsurf@semichrome.net
Author: vince
Date: Thu Dec 29 18:21:26 2011
New Revision: 13353
URL: http://source.netsurf-browser.org?rev=13353&view=rev
Log:
fix final references to pixbuf
Modified:
branches/vince/netsurf-cairo/gtk/print.c
branches/vince/netsurf-cairo/gtk/scaffolding.c
Modified: branches/vince/netsurf-cairo/gtk/print.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/print....
==============================================================================
--- branches/vince/netsurf-cairo/gtk/print.c (original)
+++ branches/vince/netsurf-cairo/gtk/print.c Thu Dec 29 18:21:26 2011
@@ -72,40 +72,6 @@
g / 255.0, b / 255.0, 1.0);
}
-static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
- GdkPixbuf *pixbuf, colour bg)
-{
- /* XXX: This currently ignores the background colour supplied.
- * Does this matter?
- */
-
- if (width == 0 || height == 0)
- return true;
-
- if (gdk_pixbuf_get_width(pixbuf) == width &&
- gdk_pixbuf_get_height(pixbuf) == height) {
- gdk_cairo_set_source_pixbuf(gtk_print_current_cr, pixbuf, x, y);
- cairo_paint(gtk_print_current_cr);
- } else {
- GdkPixbuf *scaled;
- scaled = gdk_pixbuf_scale_simple(pixbuf,
- width, height,
- /* plotting for the printer doesn't have
- * to be fast so we can use always the
- * interp_style that gives better quality
- */
- GDK_INTERP_BILINEAR);
- if (!scaled)
- return false;
-
- gdk_cairo_set_source_pixbuf(gtk_print_current_cr, scaled, x, y);
- cairo_paint(gtk_print_current_cr);
-
- g_object_unref(scaled);
- }
-
- return true;
-}
static bool gtk_print_font_paint(int x, int y,
@@ -368,63 +334,166 @@
return true;
}
+
+static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
+ struct bitmap *bitmap, colour bg)
+{
+ int x0, y0, x1, y1;
+ int dsrcx, dsrcy, dwidth, dheight;
+ int bmwidth, bmheight;
+
+ cairo_surface_t *bmsurface = bitmap->surface;
+
+ /* Bail early if we can */
+ if (width == 0 || height == 0)
+ /* Nothing to plot */
+ return true;
+ if ((x > (cliprect.x + cliprect.width)) ||
+ ((x + width) < cliprect.x) ||
+ (y > (cliprect.y + cliprect.height)) ||
+ ((y + height) < cliprect.y)) {
+ /* Image completely outside clip region */
+ return true;
+ }
+
+ /* Get clip rectangle / image rectangle edge differences */
+ x0 = cliprect.x - x;
+ y0 = cliprect.y - y;
+ x1 = (x + width) - (cliprect.x + cliprect.width);
+ y1 = (y + height) - (cliprect.y + cliprect.height);
+
+ /* Set initial draw geometry */
+ dsrcx = x;
+ dsrcy = y;
+ dwidth = width;
+ dheight = height;
+
+ /* Manually clip draw coordinates to area of image to be rendered */
+ if (x0 > 0) {
+ /* Clip left */
+ dsrcx += x0;
+ dwidth -= x0;
+ }
+ if (y0 > 0) {
+ /* Clip top */
+ dsrcy += y0;
+ dheight -= y0;
+ }
+ if (x1 > 0) {
+ /* Clip right */
+ dwidth -= x1;
+ }
+ if (y1 > 0) {
+ /* Clip bottom */
+ dheight -= y1;
+ }
+
+ if (dwidth == 0 || dheight == 0)
+ /* Nothing to plot */
+ return true;
+
+ bmwidth = cairo_image_surface_get_width(bmsurface);
+ bmheight = cairo_image_surface_get_height(bmsurface);
+
+ /* Render the bitmap */
+ if ((bmwidth == width) && (bmheight == height)) {
+ /* Bitmap is not scaled */
+ /* Plot the bitmap */
+ cairo_set_source_surface(gtk_print_current_cr, bmsurface, x, y);
+ cairo_rectangle(gtk_print_current_cr, dsrcx, dsrcy, dwidth, dheight);
+ cairo_fill(gtk_print_current_cr);
+
+ } else {
+ /* Bitmap is scaled */
+ if ((bitmap->scsurface != NULL) &&
+ ((cairo_image_surface_get_width(bitmap->scsurface) != width) ||
+ (cairo_image_surface_get_height(bitmap->scsurface) != height))){
+ cairo_surface_destroy(bitmap->scsurface);
+ bitmap->scsurface = NULL;
+ }
+
+ if (bitmap->scsurface == NULL) {
+ bitmap->scsurface = cairo_surface_create_similar(bmsurface,CAIRO_CONTENT_COLOR_ALPHA, width, height);
+ cairo_t *cr = cairo_create(bitmap->scsurface);
+
+ /* Scale *before* setting the source surface (1) */
+ cairo_scale(cr, (double)width / bmwidth, (double)height / bmheight);
+ cairo_set_source_surface(cr, bmsurface, 0, 0);
+
+ /* To avoid getting the edge pixels blended with 0
+ * alpha, which would occur with the default
+ * EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
+ */
+ cairo_pattern_set_extend(cairo_get_source(cr),
+ CAIRO_EXTEND_REFLECT);
+
+ /* Replace the destination with the source instead of
+ * overlaying
+ */
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+ /* Do the actual drawing */
+ cairo_paint(cr);
+
+ cairo_destroy(cr);
+
+ }
+ /* Plot the scaled bitmap */
+ cairo_set_source_surface(gtk_print_current_cr, bitmap->scsurface, x, y);
+ cairo_rectangle(gtk_print_current_cr, dsrcx, dsrcy, dwidth, dheight);
+ cairo_fill(gtk_print_current_cr);
+
+ }
+
+ return true;
+}
+
+
static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
int doneheight = 0, donewidth = 0;
- GdkPixbuf *primary= NULL;
- GdkPixbuf *pretiled = NULL;
-
- bool repeat_x = (flags & BITMAPF_REPEAT_X);
- bool repeat_y = (flags & BITMAPF_REPEAT_Y);
+ bool repeat_x = (flags & BITMAPF_REPEAT_X);
+ bool repeat_y = (flags & BITMAPF_REPEAT_Y);
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just pass it on */
-// primary = gtk_bitmap_get_primary(bitmap);
- return nsgtk_print_plot_pixbuf(x, y, width, height, primary, bg);
- }
-#if 0
- if (repeat_x && !repeat_y)
- pretiled = gtk_bitmap_get_pretile_x(bitmap);
- if (repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_xy(bitmap);
- if (!repeat_x && repeat_y)
- pretiled = gtk_bitmap_get_pretile_y(bitmap);
-
- assert(pretiled != NULL);
-
- primary = gtk_bitmap_get_primary(bitmap);
-#endif
- /* use the primary and pretiled widths to scale the w/h provided */
- width *= gdk_pixbuf_get_width(pretiled);
- width /= gdk_pixbuf_get_width(primary);
- height *= gdk_pixbuf_get_height(pretiled);
- height /= gdk_pixbuf_get_height(primary);
+ return nsgtk_print_plot_pixbuf(x, y, width, height, bitmap, bg);
+ }
+
+ width = bitmap_get_width(bitmap);
+ height = bitmap_get_height(bitmap);
+
+ /* Bail early if we can */
+ if (width == 0 || height == 0)
+ /* Nothing to plot */
+ return true;
if (y > cliprect.y) {
- doneheight = (cliprect.y - height) +
- ((y - cliprect.y) % height);
- } else
+ doneheight = (cliprect.y - height) + ((y - cliprect.y) % height);
+ } else {
doneheight = y;
+ }
while (doneheight < (cliprect.y + cliprect.height)) {
if (x > cliprect.x) {
- donewidth = (cliprect.x - width) +
- ((x - cliprect.x) % width);
- } else
+ donewidth = (cliprect.x - width) + ((x - cliprect.x) % width);
+ } else {
donewidth = x;
+ }
while (donewidth < (cliprect.x + cliprect.width)) {
nsgtk_print_plot_pixbuf(donewidth, doneheight,
- width, height, pretiled, bg);
+ width, height, bitmap, bg);
donewidth += width;
- if (!repeat_x) break;
+ if (!repeat_x)
+ break;
}
-
doneheight += height;
- if (!repeat_y) break;
+ if (!repeat_y)
+ break;
}
return true;
Modified: branches/vince/netsurf-cairo/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/scaffo...
==============================================================================
--- branches/vince/netsurf-cairo/gtk/scaffolding.c (original)
+++ branches/vince/netsurf-cairo/gtk/scaffolding.c Thu Dec 29 18:21:26 2011
@@ -2019,9 +2019,9 @@
struct bitmap *icon_bitmap;
GtkImage *iconImage = NULL;
- if (g->top_level != _g)
+ if (g->top_level != _g) {
return;
-
+ }
icon_bitmap = (icon != NULL) ? content_get_bitmap(icon) : NULL;
if (icon_bitmap != NULL) {
@@ -2038,8 +2038,10 @@
if (iconImage == NULL)
return;
- if (g->icoFav != NULL)
+ if (g->icoFav != NULL) {
g_object_unref(g->icoFav);
+ }
+
g->icoFav = iconImage;
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(g->url_bar),
@@ -2061,16 +2063,12 @@
if (ico_bitmap == NULL)
return;
-// pbico = gtk_bitmap_get_primary(ico_bitmap);
- if (pbico != NULL && gdk_pixbuf_get_width(pbico) > 0 &&
- gdk_pixbuf_get_height(pbico) > 0) {
- pbico = gdk_pixbuf_scale_simple(pbico, 20, 20,
- GDK_INTERP_HYPER);
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
- } else {
- /** \todo Does pbico need cleaning up? */
+ pbico = nsgdk_pixbuf_get_from_surface(ico_bitmap->surface, 16, 16);
+ if (pbico == NULL) {
return;
}
+
+ searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
/* add ico to each window's toolbar */
for (current = scaf_list; current != NULL; current = current->next) {
@@ -2082,11 +2080,12 @@
SEXY_ICON_ENTRY_PRIMARY,
current->webSearchIco);
}
- if (pbico != NULL)
- searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
- else
- searchico = NULL;
- }
+
+ searchico = GTK_IMAGE(gtk_image_new_from_pixbuf(pbico));
+ }
+
+ g_object_unref(pbico);
+
}
bool nsgtk_scaffolding_is_busy(nsgtk_scaffolding *g)
11 years, 8 months
r13352 vince - in /branches/vince/netsurf-cairo/gtk: Makefile.target gdk.c gdk.h scaffolding.c
by netsurf@semichrome.net
Author: vince
Date: Thu Dec 29 11:12:21 2011
New Revision: 13352
URL: http://source.netsurf-browser.org?rev=13352&view=rev
Log:
fix icon setting
Added:
branches/vince/netsurf-cairo/gtk/gdk.c
branches/vince/netsurf-cairo/gtk/gdk.h
Modified:
branches/vince/netsurf-cairo/gtk/Makefile.target
branches/vince/netsurf-cairo/gtk/scaffolding.c
Modified: branches/vince/netsurf-cairo/gtk/Makefile.target
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/Makefi...
==============================================================================
--- branches/vince/netsurf-cairo/gtk/Makefile.target (original)
+++ branches/vince/netsurf-cairo/gtk/Makefile.target Thu Dec 29 11:12:21 2011
@@ -71,7 +71,7 @@
# S_GTK are sources purely for the GTK build
S_GTK := font_pango.c bitmap.c gui.c schedule.c thumbnail.c plotters.c \
- treeview.c scaffolding.c completion.c login.c throbber.c \
+ treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
selection.c history.c window.c filetype.c download.c menu.c \
print.c save.c search.c tabs.c theme.c toolbar.c \
sexy_icon_entry.c compat.c cookies.c hotlist.c system_colour.c \
Added: branches/vince/netsurf-cairo/gtk/gdk.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/gdk.c?...
==============================================================================
--- branches/vince/netsurf-cairo/gtk/gdk.c (added)
+++ branches/vince/netsurf-cairo/gtk/gdk.c Thu Dec 29 11:12:21 2011
@@ -1,0 +1,124 @@
+/*
+ * Copyright 2011 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+#include "utils/log.h"
+
+#include "gtk/gdk.h"
+
+static void
+convert_alpha(guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int width,
+ int height)
+{
+ int x, y;
+
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *) src_data;
+
+ for (x = 0; x < width; x++) {
+ guint alpha = src[x] >> 24;
+
+ if (alpha == 0) {
+ dest_data[x * 4 + 0] = 0;
+ dest_data[x * 4 + 1] = 0;
+ dest_data[x * 4 + 2] = 0;
+ } else {
+ dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ }
+ dest_data[x * 4 + 3] = alpha;
+ }
+
+ src_data += src_stride;
+ dest_data += dest_stride;
+ }
+}
+
+
+GdkPixbuf *
+nsgdk_pixbuf_get_from_surface(cairo_surface_t *surface, int scwidth, int scheight)
+{
+ int width, height; /* source width and height */
+ cairo_surface_t *scsurface; /* scaled surface */
+ cairo_t *cr; /* cairo context for scaled surface */
+ GdkPixbuf *pixbuf; /* The result pixel buffer */
+
+ /* create pixmap */
+ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, scwidth, scheight);
+ if (pixbuf == NULL) {
+ return NULL;
+ }
+
+ memset(gdk_pixbuf_get_pixels(pixbuf),
+ 0xff,
+ gdk_pixbuf_get_rowstride(pixbuf) * scheight);
+
+ /* scale cairo surface into new surface the target size */
+ cairo_surface_flush(surface); /* ensure source surface is ready */
+
+ /* get source surface dimensions */
+ width = cairo_image_surface_get_width(surface);
+ height = cairo_image_surface_get_height(surface);
+
+ /* scaled surface always has an alpha chanel for ease */
+ scsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scwidth, scheight);
+ if (cairo_surface_status(scsurface) != CAIRO_STATUS_SUCCESS) {
+ cairo_surface_destroy(scsurface);
+ g_object_unref(pixbuf);
+ LOG(("Surface creation failed"));
+ return NULL;
+ }
+
+ cr = cairo_create(scsurface);
+
+ /* Scale *before* setting the source surface */
+ cairo_scale(cr, (double)scwidth / width, (double)scheight / height);
+ cairo_set_source_surface(cr, surface, 0, 0);
+
+ /* To avoid getting the edge pixels blended with 0
+ * alpha, which would occur with the default
+ * EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer
+ */
+ cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT);
+
+ /* Replace the destination with the source instead of overlaying */
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+ /* Do the actual drawing */
+ cairo_paint(cr);
+
+ cairo_destroy(cr);
+
+ /* copy data from surface into pixmap */
+ convert_alpha(gdk_pixbuf_get_pixels(pixbuf),
+ gdk_pixbuf_get_rowstride(pixbuf),
+ cairo_image_surface_get_data(scsurface),
+ cairo_image_surface_get_stride(scsurface),
+ scwidth, scheight);
+
+ cairo_surface_destroy(scsurface);
+
+ return pixbuf;
+}
+
Added: branches/vince/netsurf-cairo/gtk/gdk.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/gdk.h?...
==============================================================================
--- branches/vince/netsurf-cairo/gtk/gdk.h (added)
+++ branches/vince/netsurf-cairo/gtk/gdk.h Thu Dec 29 11:12:21 2011
@@ -1,0 +1,35 @@
+/*
+ * Copyright 2011 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * GDK support functions for missing interfaces
+ */
+
+#ifndef NETSURF_GTK_GDK_H_
+#define NETSURF_GTK_GDK_H_
+
+#include <gtk/gtk.h>
+
+/** obtain a pixbuf of the specified size from a cairo surface.
+ *
+ * This is the same as the GTK+ 3 gdk_pixbuf_get_from_surface but
+ * actually works and is available on gtk 2
+ */
+GdkPixbuf *nsgdk_pixbuf_get_from_surface(cairo_surface_t *surface, int width, int height);
+
+#endif /* NETSURF_GTK_GDK_H */
Modified: branches/vince/netsurf-cairo/gtk/scaffolding.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/gtk/scaffo...
==============================================================================
--- branches/vince/netsurf-cairo/gtk/scaffolding.c (original)
+++ branches/vince/netsurf-cairo/gtk/scaffolding.c Thu Dec 29 11:12:21 2011
@@ -76,6 +76,7 @@
#include "gtk/options.h"
#include "gtk/sexy_icon_entry.h"
#include "gtk/compat.h"
+#include "gtk/gdk.h"
#include "image/ico.h"
#include "render/box.h"
#include "render/font.h"
@@ -1992,57 +1993,21 @@
gtk_image_set_from_pixbuf(g->throbber, nsgtk_throbber->framedata[0]);
}
-static GdkPixmap *
-pixmap_from_cairo_surface(cairo_surface_t *bmsurface,
- GdkDrawable *drawable,
- int width,
- int height)
-{
- int bmwidth, bmheight;
- GdkPixmap *pixmap;
- cairo_t *cr;
-
- cairo_surface_flush(bmsurface);
-
- bmwidth = cairo_image_surface_get_width(bmsurface);
- bmheight = cairo_image_surface_get_height(bmsurface);
-
- pixmap = gdk_pixmap_new(drawable, width, height, -1);
-
- cr = gdk_cairo_create(pixmap);
-
- if (cairo_status(cr) == CAIRO_STATUS_SUCCESS) {
- cairo_scale(cr,
- (double)width / bmwidth,
- (double)height / bmheight);
-
- cairo_set_source_surface(cr, bmsurface, 0, 0);
-
- /* To avoid getting the edge pixels blended with 0
- * alpha, which would occur with the default
- * EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
- */
- cairo_pattern_set_extend(cairo_get_source(cr),
- CAIRO_EXTEND_REFLECT);
-
- /* Replace the destination with the source instead of
- * overlaying
- */
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
-
- /* Do the actual drawing */
- cairo_paint(cr);
-
- cairo_surface_flush(cairo_get_target(cr));
- } else {
- LOG(("%s", cairo_status_to_string(cairo_status(cr))));
- g_object_unref(pixmap);
- pixmap = NULL;
- }
-
- cairo_destroy(cr);
-
- return pixmap;
+static GtkImage *
+nsgtk_image_new_from_surface(cairo_surface_t *surface, int w, int h)
+{
+ GdkPixbuf *pixbuf;
+ GtkImage *image = NULL;
+
+ pixbuf = nsgdk_pixbuf_get_from_surface(surface, w, h);
+
+ if (pixbuf != NULL) {
+ image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
+ }
+
+ g_object_unref(pixbuf);
+
+ return image;
}
/**
@@ -2060,12 +2025,7 @@
icon_bitmap = (icon != NULL) ? content_get_bitmap(icon) : NULL;
if (icon_bitmap != NULL) {
- GdkPixmap *pixmap;
- pixmap = pixmap_from_cairo_surface(icon_bitmap->surface, ((GtkWidget *)g->window)->window, 16, 16);
-
- iconImage = GTK_IMAGE(gtk_image_new_from_pixmap(pixmap, NULL));
- LOG(("set to %p",iconImage));
- g_object_unref(pixmap);
+ iconImage = nsgtk_image_new_from_surface(icon_bitmap->surface, 16, 16);
}
if (iconImage == NULL) {
11 years, 8 months
r13351 mono - /trunk/netsurf/atari/download.c
by netsurf@semichrome.net
Author: mono
Date: Tue Dec 27 17:30:39 2011
New Revision: 13351
URL: http://source.netsurf-browser.org?rev=13351&view=rev
Log:
Set status message on download finish.
Modified:
trunk/netsurf/atari/download.c
Modified: trunk/netsurf/atari/download.c
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/download.c?rev=1335...
==============================================================================
--- trunk/netsurf/atari/download.c (original)
+++ trunk/netsurf/atari/download.c Tue Dec 27 17:30:39 2011
@@ -48,7 +48,9 @@
#include "atari/options.h"
#include "atari/osspec.h"
-/*TODO: get filename from core. */
+/*TODO: get filename from core. */
+
+extern struct gui_window * input_window;
static void gui_download_window_destroy( struct gui_download_window * gdw );
@@ -290,7 +292,8 @@
LOG(("%s", error_msg));
strncpy((char*)&dw->lbl_file, error_msg, MAX_SLEN_LBL_FILE-1);
dw->status = NSATARI_DOWNLOAD_ERROR;
- snd_rdw( dw->form );
+ snd_rdw( dw->form );
+ gui_window_set_status(input_window, messages_get("Done") );
}
void gui_download_window_done(struct gui_download_window *dw)
@@ -316,5 +319,6 @@
snd_rdw( dw->form );
if( (tree[DOWNLOAD_CB_CLOSE_RDY].ob_state & SELECTED) != 0 ) {
ApplWrite( _AESapid, WM_CLOSED, dw->form->handle, 0,0,0,0);
- }
-}
+ }
+ gui_window_set_status(input_window, messages_get("Done") );
+}
11 years, 9 months