2004-12-25 14:37:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2004-12-25 14:37:35 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Generic bitmap handling (GDK / GTK+ implementation).
|
|
|
|
*
|
|
|
|
* This implements the interface given by desktop/bitmap.h using GdkPixbufs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2011-12-30 04:58:35 +04:00
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <gtk/gtk.h>
|
2011-01-30 02:40:22 +03:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/scaffolding.h"
|
2011-12-30 04:58:35 +04:00
|
|
|
#include "gtk/bitmap.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "utils/log.h"
|
2004-12-25 14:37:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a bitmap.
|
|
|
|
*
|
|
|
|
* \param width width of image in pixels
|
|
|
|
* \param height width of image in pixels
|
2006-02-22 04:58:19 +03:00
|
|
|
* \param state a flag word indicating the initial state
|
2004-12-25 14:37:35 +03:00
|
|
|
* \return an opaque struct bitmap, or NULL on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
void *bitmap_create(int width, int height, unsigned int state)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
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;
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether a bitmap should be plotted opaque
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
|
|
|
* \param opaque whether the bitmap should be plotted opaque
|
2004-12-25 14:37:35 +03:00
|
|
|
*/
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
void bitmap_set_opaque(void *vbitmap, bool opaque)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether a bitmap has an opaque alpha channel
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2004-12-25 14:37:35 +03:00
|
|
|
* \return whether the bitmap is opaque
|
|
|
|
*/
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
bool bitmap_test_opaque(void *vbitmap)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
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;
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether a bitmap should be plotted opaque
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2004-12-25 14:37:35 +03:00
|
|
|
*/
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
bool bitmap_get_opaque(void *vbitmap)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
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;
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the pixel data in a bitmap.
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2004-12-25 14:37:35 +03:00
|
|
|
* \return pointer to the pixel buffer
|
|
|
|
*
|
|
|
|
* The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end
|
|
|
|
* of rows. The width of a row in bytes is given by bitmap_get_rowstride().
|
|
|
|
*/
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
unsigned char *bitmap_get_buffer(void *vbitmap)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
2013-05-20 16:07:40 +04:00
|
|
|
int pixel_loop;
|
|
|
|
int pixel_count;
|
2014-02-16 04:00:21 +04:00
|
|
|
uint8_t *pixels;
|
|
|
|
uint32_t t, r, g, b;
|
2013-05-20 16:07:40 +04:00
|
|
|
cairo_format_t fmt;
|
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
assert(gbitmap);
|
|
|
|
|
|
|
|
cairo_surface_flush(gbitmap->surface);
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels = cairo_image_surface_get_data(gbitmap->surface);
|
2013-05-20 16:07:40 +04:00
|
|
|
|
|
|
|
if (!gbitmap->converted)
|
2014-02-16 04:00:21 +04:00
|
|
|
return pixels;
|
2013-05-20 16:07:40 +04:00
|
|
|
|
|
|
|
fmt = cairo_image_surface_get_format(gbitmap->surface);
|
|
|
|
pixel_count = cairo_image_surface_get_width(gbitmap->surface) *
|
|
|
|
cairo_image_surface_get_height(gbitmap->surface);
|
|
|
|
|
|
|
|
if (fmt == CAIRO_FORMAT_RGB24) {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Opaque image */
|
2013-05-20 16:07:40 +04:00
|
|
|
for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Cairo surface is ARGB, written in native endian */
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2014-02-16 04:00:21 +04:00
|
|
|
b = pixels[4 * pixel_loop + 0];
|
2014-02-16 04:54:07 +04:00
|
|
|
g = pixels[4 * pixel_loop + 1];
|
2014-02-16 04:00:21 +04:00
|
|
|
r = pixels[4 * pixel_loop + 2];
|
2014-02-16 04:54:07 +04:00
|
|
|
t = pixels[4 * pixel_loop + 3];
|
|
|
|
#else
|
|
|
|
t = pixels[4 * pixel_loop + 0];
|
|
|
|
r = pixels[4 * pixel_loop + 1];
|
|
|
|
g = pixels[4 * pixel_loop + 2];
|
|
|
|
b = pixels[4 * pixel_loop + 3];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Core bitmaps always have a component order of rgba,
|
|
|
|
* regardless of system endianness */
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels[4 * pixel_loop + 0] = r;
|
2014-02-16 04:54:07 +04:00
|
|
|
pixels[4 * pixel_loop + 1] = g;
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels[4 * pixel_loop + 2] = b;
|
2014-02-16 04:54:07 +04:00
|
|
|
pixels[4 * pixel_loop + 3] = t;
|
2013-05-20 16:07:40 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Alpha image: de-multiply alpha */
|
2013-05-20 16:07:40 +04:00
|
|
|
for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
|
2014-02-16 04:54:07 +04:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2014-02-16 04:00:21 +04:00
|
|
|
b = pixels[4 * pixel_loop + 0];
|
|
|
|
g = pixels[4 * pixel_loop + 1];
|
|
|
|
r = pixels[4 * pixel_loop + 2];
|
|
|
|
t = pixels[4 * pixel_loop + 3];
|
2014-02-16 04:54:07 +04:00
|
|
|
#else
|
|
|
|
t = pixels[4 * pixel_loop + 0];
|
|
|
|
r = pixels[4 * pixel_loop + 1];
|
|
|
|
g = pixels[4 * pixel_loop + 2];
|
|
|
|
b = pixels[4 * pixel_loop + 3];
|
|
|
|
#endif
|
2014-02-16 04:00:21 +04:00
|
|
|
|
|
|
|
if (t != 0) {
|
|
|
|
r = (r << 8) / t;
|
|
|
|
g = (g << 8) / t;
|
|
|
|
b = (b << 8) / t;
|
2013-05-20 16:07:40 +04:00
|
|
|
|
|
|
|
r = (r > 255) ? 255 : r;
|
|
|
|
g = (g > 255) ? 255 : g;
|
|
|
|
b = (b > 255) ? 255 : b;
|
2014-02-16 04:00:21 +04:00
|
|
|
} else {
|
|
|
|
r = g = b = 0;
|
2013-05-20 16:07:40 +04:00
|
|
|
}
|
2014-02-16 04:00:21 +04:00
|
|
|
|
|
|
|
pixels[4 * pixel_loop + 0] = r;
|
|
|
|
pixels[4 * pixel_loop + 1] = g;
|
|
|
|
pixels[4 * pixel_loop + 2] = b;
|
|
|
|
pixels[4 * pixel_loop + 3] = t;
|
2013-05-20 16:07:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gbitmap->converted = false;
|
2011-12-30 04:58:35 +04:00
|
|
|
|
2013-05-20 16:07:40 +04:00
|
|
|
return (unsigned char *) pixels;
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the width of a pixel row in bytes.
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2004-12-25 14:37:35 +03:00
|
|
|
* \return width of a pixel row in the bitmap
|
|
|
|
*/
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
size_t bitmap_get_rowstride(void *vbitmap)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
assert(gbitmap);
|
|
|
|
|
|
|
|
return cairo_image_surface_get_stride(gbitmap->surface);
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
/**
|
|
|
|
* Find the bytes per pixel of a bitmap
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
* \return bytes per pixel
|
|
|
|
*/
|
|
|
|
|
|
|
|
size_t bitmap_get_bpp(void *vbitmap)
|
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
assert(gbitmap);
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-09 19:06:14 +04:00
|
|
|
|
2004-12-25 14:37:35 +03:00
|
|
|
/**
|
|
|
|
* Free a bitmap.
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2004-12-25 14:37:35 +03:00
|
|
|
*/
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
void bitmap_destroy(void *vbitmap)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
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);
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a bitmap in the platform's native format.
|
|
|
|
*
|
2008-09-07 23:08:57 +04:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
|
|
|
* \param path pathname for file
|
|
|
|
* \param flags modify the behaviour of the save
|
2004-12-25 14:37:35 +03:00
|
|
|
* \return true on success, false on error and error reported
|
|
|
|
*/
|
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
bool bitmap_save(void *vbitmap, const char *path, unsigned flags)
|
2004-12-25 14:37:35 +03:00
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
assert(gbitmap);
|
2007-08-08 20:16:03 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
return false;
|
2004-12-25 14:37:35 +03:00
|
|
|
}
|
2005-06-23 21:22:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The bitmap image has changed, so flush any persistant cache.
|
|
|
|
*
|
2014-11-13 02:27:13 +03:00
|
|
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
2005-06-23 21:22:28 +04:00
|
|
|
*/
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
void bitmap_modified(void *vbitmap) {
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
int pixel_loop;
|
|
|
|
int pixel_count;
|
2014-02-16 04:00:21 +04:00
|
|
|
uint8_t *pixels;
|
|
|
|
uint32_t t, r, g, b;
|
2011-12-30 04:58:35 +04:00
|
|
|
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);
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels = cairo_image_surface_get_data(gbitmap->surface);
|
2011-12-30 04:58:35 +04:00
|
|
|
|
2013-05-20 16:07:40 +04:00
|
|
|
if (gbitmap->converted) {
|
|
|
|
cairo_surface_mark_dirty(gbitmap->surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
if (fmt == CAIRO_FORMAT_RGB24) {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Opaque image */
|
2011-12-30 04:58:35 +04:00
|
|
|
for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Core bitmaps always have a component order of rgba,
|
|
|
|
* regardless of system endianness */
|
2014-02-16 04:00:21 +04:00
|
|
|
r = pixels[4 * pixel_loop + 0];
|
2014-02-16 04:54:07 +04:00
|
|
|
g = pixels[4 * pixel_loop + 1];
|
2014-02-16 04:00:21 +04:00
|
|
|
b = pixels[4 * pixel_loop + 2];
|
2014-02-16 04:54:07 +04:00
|
|
|
t = pixels[4 * pixel_loop + 3];
|
|
|
|
|
|
|
|
/* Cairo surface is ARGB, written in native endian */
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels[4 * pixel_loop + 0] = b;
|
2014-02-16 04:54:07 +04:00
|
|
|
pixels[4 * pixel_loop + 1] = g;
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels[4 * pixel_loop + 2] = r;
|
2014-02-16 04:54:07 +04:00
|
|
|
pixels[4 * pixel_loop + 3] = t;
|
|
|
|
#else
|
|
|
|
pixels[4 * pixel_loop + 0] = t;
|
|
|
|
pixels[4 * pixel_loop + 1] = r;
|
|
|
|
pixels[4 * pixel_loop + 2] = g;
|
|
|
|
pixels[4 * pixel_loop + 3] = b;
|
|
|
|
#endif
|
2011-12-30 04:58:35 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-16 04:54:07 +04:00
|
|
|
/* Alpha image: pre-multiply alpha */
|
2011-12-30 04:58:35 +04:00
|
|
|
for (pixel_loop=0; pixel_loop < pixel_count; pixel_loop++) {
|
2014-02-16 04:00:21 +04:00
|
|
|
r = pixels[4 * pixel_loop + 0];
|
|
|
|
g = pixels[4 * pixel_loop + 1];
|
|
|
|
b = pixels[4 * pixel_loop + 2];
|
|
|
|
t = pixels[4 * pixel_loop + 3];
|
|
|
|
|
|
|
|
if (t != 0) {
|
2014-02-16 04:24:11 +04:00
|
|
|
r = ((r * (t + 1)) >> 8) & 0xff;
|
|
|
|
g = ((g * (t + 1)) >> 8) & 0xff;
|
|
|
|
b = ((b * (t + 1)) >> 8) & 0xff;
|
2011-12-30 04:58:35 +04:00
|
|
|
} else {
|
2014-02-16 04:00:21 +04:00
|
|
|
r = g = b = 0;
|
2011-12-30 04:58:35 +04:00
|
|
|
}
|
2014-02-16 04:00:21 +04:00
|
|
|
|
2014-02-16 04:54:07 +04:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2014-02-16 04:00:21 +04:00
|
|
|
pixels[4 * pixel_loop + 0] = b;
|
|
|
|
pixels[4 * pixel_loop + 1] = g;
|
|
|
|
pixels[4 * pixel_loop + 2] = r;
|
|
|
|
pixels[4 * pixel_loop + 3] = t;
|
2014-02-16 04:54:07 +04:00
|
|
|
#else
|
|
|
|
pixels[4 * pixel_loop + 0] = t;
|
|
|
|
pixels[4 * pixel_loop + 1] = r;
|
|
|
|
pixels[4 * pixel_loop + 2] = g;
|
|
|
|
pixels[4 * pixel_loop + 3] = b;
|
|
|
|
#endif
|
2011-12-30 04:58:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_mark_dirty(gbitmap->surface);
|
|
|
|
|
|
|
|
gbitmap->converted = true;
|
2005-06-23 21:22:28 +04:00
|
|
|
}
|
2006-02-22 04:58:19 +03:00
|
|
|
|
Merged revisions 4345-4346,4350-4351,4389,4391,4395,4401-4403,4423,4485-4486 via svnmerge from
svn://semichrome.net/branches/dynis/netsurf
........
r4345 | dynis | 2008-06-15 18:37:23 -0500 (Sun, 15 Jun 2008) | 1 line
Move NetSurf's gifread.h to libnsgif
........
r4346 | dynis | 2008-06-15 18:38:38 -0500 (Sun, 15 Jun 2008) | 1 line
Remove NetSurf's gifread.c (replaced by libnsgif)
........
r4350 | dynis | 2008-06-15 18:57:17 -0500 (Sun, 15 Jun 2008) | 1 line
Added references to libnsgif where necessary; corrected function calls where callbacks were implemented
........
r4351 | dynis | 2008-06-15 19:00:33 -0500 (Sun, 15 Jun 2008) | 1 line
Updated Makefile to compile with libnsgif
........
r4389 | dynis | 2008-06-18 13:58:51 -0500 (Wed, 18 Jun 2008) | 1 line
Altered bitmap callback table name for gif images to avoid ambiguity when bmp image library is created
........
r4391 | dynis | 2008-06-18 14:08:39 -0500 (Wed, 18 Jun 2008) | 1 line
Updated netsurf branch to use new bitmap callback table structure name that was altered in libnsgif
........
r4395 | dynis | 2008-06-18 14:54:51 -0500 (Wed, 18 Jun 2008) | 1 line
Corrected param comments for bitmap_set_suspendable()
........
r4401 | dynis | 2008-06-18 18:39:50 -0500 (Wed, 18 Jun 2008) | 1 line
Added references to libnsbmp where necessary; corrected function calls where callbacks were implemented
........
r4402 | dynis | 2008-06-18 18:40:47 -0500 (Wed, 18 Jun 2008) | 1 line
Updated Makefile to compile with libnsbmp
........
r4403 | dynis | 2008-06-18 18:41:53 -0500 (Wed, 18 Jun 2008) | 1 line
Remove NetSurf's bmpread.c and bmpread.h (replaced by libnsbmp)
........
r4423 | dynis | 2008-06-22 14:21:30 -0500 (Sun, 22 Jun 2008) | 1 line
Correct a silly mistake in nsbmp_bitmap_create
........
r4485 | dynis | 2008-07-01 04:13:48 -0500 (Tue, 01 Jul 2008) | 1 line
Integrated the latest versions of libnsgif and libnsbmp into NetSurf
........
r4486 | dynis | 2008-07-01 05:27:10 -0500 (Tue, 01 Jul 2008) | 1 line
Altered bitmap functions to receive void pointers for proper utilisation of libnsgif and libnsbmp
........
svn path=/trunk/netsurf/; revision=5071
2008-08-12 07:49:34 +04:00
|
|
|
int bitmap_get_width(void *vbitmap){
|
2011-12-30 04:58:35 +04:00
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
assert(gbitmap);
|
2006-08-09 19:06:14 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
return cairo_image_surface_get_width(gbitmap->surface);
|
2006-08-09 19:06:14 +04:00
|
|
|
}
|
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
int bitmap_get_height(void *vbitmap){
|
|
|
|
struct bitmap *gbitmap = (struct bitmap *)vbitmap;
|
|
|
|
assert(gbitmap);
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
return cairo_image_surface_get_height(gbitmap->surface);
|
2006-08-09 19:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|