2011-12-30 04:58:35 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Vincent Sanders <vince@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++) {
|
2018-09-25 16:43:24 +03:00
|
|
|
/* this cast is safe, the buffer is appropriately aligned */
|
|
|
|
guint32 *src = (void *) src_data;
|
2011-12-30 04:58:35 +04:00
|
|
|
|
|
|
|
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,
|
2022-10-22 23:31:17 +03:00
|
|
|
gdk_pixbuf_get_rowstride(pixbuf) * (size_t)scheight);
|
2011-12-30 04:58:35 +04:00
|
|
|
|
|
|
|
/* 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);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Surface creation failed");
|
2011-12-30 04:58:35 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|