2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-06-08 02:43:22 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2000-06-08 02:43:22 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "pixel-region.h"
|
2005-09-04 01:16:58 +08:00
|
|
|
#include "temp-buf.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "tile-manager.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tile.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-01-23 07:46:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/*********************/
|
|
|
|
/* Local Functions */
|
|
|
|
|
2002-08-22 17:48:56 +08:00
|
|
|
static gint get_portion_width (PixelRegionIterator *PRI);
|
|
|
|
static gint get_portion_height (PixelRegionIterator *PRI);
|
|
|
|
static PixelRegionIterator * pixel_regions_configure (PixelRegionIterator *PRI);
|
2003-09-29 04:13:59 +08:00
|
|
|
static void pixel_region_configure (PixelRegionHolder *PRH,
|
2002-08-22 17:48:56 +08:00
|
|
|
PixelRegionIterator *PRI);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/* Function definitions */
|
|
|
|
|
|
|
|
void
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_region_init (PixelRegion *PR,
|
2006-04-12 20:49:29 +08:00
|
|
|
TileManager *tiles,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gboolean dirty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PR->data = NULL;
|
|
|
|
PR->tiles = tiles;
|
|
|
|
PR->curtile = NULL;
|
|
|
|
PR->offx = 0;
|
|
|
|
PR->offy = 0;
|
|
|
|
PR->bytes = tile_manager_bpp (tiles);
|
|
|
|
PR->rowstride = PR->bytes * TILE_WIDTH;
|
|
|
|
PR->x = x;
|
|
|
|
PR->y = y;
|
|
|
|
PR->w = w;
|
|
|
|
PR->h = h;
|
|
|
|
PR->dirty = dirty;
|
|
|
|
PR->process_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixel_region_init_temp_buf (PixelRegion *PR,
|
|
|
|
TempBuf *temp_buf,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
2008-12-13 18:35:53 +08:00
|
|
|
PR->data = temp_buf_get_data (temp_buf);
|
2005-09-04 01:16:58 +08:00
|
|
|
PR->tiles = NULL;
|
|
|
|
PR->curtile = NULL;
|
|
|
|
PR->offx = 0;
|
|
|
|
PR->offy = 0;
|
|
|
|
PR->bytes = temp_buf->bytes;
|
|
|
|
PR->rowstride = temp_buf->width * temp_buf->bytes;
|
|
|
|
PR->x = x;
|
|
|
|
PR->y = y;
|
|
|
|
PR->w = w;
|
|
|
|
PR->h = h;
|
|
|
|
PR->dirty = FALSE;
|
|
|
|
PR->process_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixel_region_init_data (PixelRegion *PR,
|
|
|
|
guchar *data,
|
|
|
|
gint bytes,
|
|
|
|
gint rowstride,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
|
|
|
PR->data = data;
|
|
|
|
PR->tiles = NULL;
|
|
|
|
PR->curtile = NULL;
|
|
|
|
PR->offx = 0;
|
|
|
|
PR->offy = 0;
|
|
|
|
PR->bytes = bytes;
|
|
|
|
PR->rowstride = rowstride;
|
|
|
|
PR->x = x;
|
|
|
|
PR->y = y;
|
|
|
|
PR->w = w;
|
|
|
|
PR->h = h;
|
|
|
|
PR->dirty = FALSE;
|
|
|
|
PR->process_count = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_region_resize (PixelRegion *PR,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PR->x = x;
|
|
|
|
PR->y = y;
|
|
|
|
PR->w = w;
|
|
|
|
PR->h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_region_get_row (PixelRegion *PR,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
guchar *data,
|
|
|
|
gint subsample)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-06-08 02:43:22 +08:00
|
|
|
Tile *tile;
|
|
|
|
guchar *tile_data;
|
2001-05-14 21:39:45 +08:00
|
|
|
gint inc;
|
|
|
|
gint end;
|
|
|
|
gint boundary;
|
|
|
|
gint b;
|
|
|
|
gint npixels;
|
2006-07-06 18:58:44 +08:00
|
|
|
gint bpp;
|
2001-05-14 21:39:45 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
end = x + w;
|
|
|
|
|
2007-01-16 05:54:51 +08:00
|
|
|
bpp = PR->bytes;
|
2006-07-06 18:58:44 +08:00
|
|
|
inc = subsample * bpp;
|
1998-07-25 19:24:09 +08:00
|
|
|
|
2001-11-29 09:06:44 +08:00
|
|
|
if (subsample == 1)
|
|
|
|
{
|
2007-01-16 05:54:51 +08:00
|
|
|
if (PR->tiles)
|
|
|
|
read_pixel_data (PR->tiles, x, y, end - 1, y, data, PR->bytes);
|
|
|
|
else
|
|
|
|
memcpy (data, PR->data + x * bpp + y * PR->rowstride, w * bpp);
|
2001-11-29 09:06:44 +08:00
|
|
|
}
|
2003-09-29 04:13:59 +08:00
|
|
|
else
|
2001-11-29 09:06:44 +08:00
|
|
|
{
|
|
|
|
while (x < end)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
tile = tile_manager_get_tile (PR->tiles, x, y, TRUE, FALSE);
|
2007-09-13 02:29:11 +08:00
|
|
|
tile_data = tile_data_pointer (tile, x, y);
|
2006-04-12 20:49:29 +08:00
|
|
|
npixels = tile_ewidth (tile) - (x % TILE_WIDTH);
|
|
|
|
|
|
|
|
if ((x + npixels) > end) /* make sure we don't write past the end */
|
|
|
|
npixels = end - x;
|
|
|
|
|
|
|
|
boundary = x + npixels;
|
|
|
|
for ( ; x < boundary; x += subsample)
|
|
|
|
{
|
2006-07-06 18:58:44 +08:00
|
|
|
for (b = 0; b < bpp; b++)
|
2006-04-12 20:49:29 +08:00
|
|
|
*data++ = tile_data[b];
|
|
|
|
|
|
|
|
tile_data += inc;
|
|
|
|
}
|
|
|
|
tile_release (tile, FALSE);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-06 18:58:44 +08:00
|
|
|
pixel_region_set_row (PixelRegion *PR,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
const guchar *data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-01-16 05:54:51 +08:00
|
|
|
if (PR->tiles)
|
|
|
|
{
|
|
|
|
gint end = x + w;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-01-16 05:54:51 +08:00
|
|
|
write_pixel_data (PR->tiles, x, y, end - 1, y, data, PR->bytes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy (PR->data + x * PR->bytes + y * PR->rowstride, data, w * PR->bytes);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_region_get_col (PixelRegion *PR,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint h,
|
|
|
|
guchar *data,
|
|
|
|
gint subsample)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-06-08 02:43:22 +08:00
|
|
|
Tile *tile;
|
|
|
|
guchar *tile_data;
|
2006-07-06 18:58:44 +08:00
|
|
|
gint bpp;
|
2001-05-14 21:39:45 +08:00
|
|
|
gint inc;
|
|
|
|
gint end;
|
|
|
|
gint boundary;
|
|
|
|
gint b;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
end = y + h;
|
2007-01-16 05:54:51 +08:00
|
|
|
bpp = PR->bytes;
|
2001-11-29 09:06:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
while (y < end)
|
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
tile = tile_manager_get_tile (PR->tiles, x, y, TRUE, FALSE);
|
2007-09-13 02:29:11 +08:00
|
|
|
tile_data = tile_data_pointer (tile, x, y);
|
1998-08-12 01:35:34 +08:00
|
|
|
boundary = y + (tile_eheight(tile) - (y % TILE_HEIGHT));
|
2000-06-08 02:43:22 +08:00
|
|
|
|
1998-07-25 19:24:09 +08:00
|
|
|
if (boundary > end) /* make sure we don't write past the end */
|
2006-04-12 20:49:29 +08:00
|
|
|
boundary = end;
|
1998-07-25 19:24:09 +08:00
|
|
|
|
2006-07-06 18:58:44 +08:00
|
|
|
inc = subsample * bpp * tile_ewidth (tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-25 19:24:09 +08:00
|
|
|
for ( ; y < boundary; y += subsample)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2006-07-06 18:58:44 +08:00
|
|
|
for (b = 0; b < bpp; b++)
|
2006-04-12 20:49:29 +08:00
|
|
|
*data++ = tile_data[b];
|
2000-06-08 02:43:22 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
tile_data += inc;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-07-06 18:58:44 +08:00
|
|
|
pixel_region_set_col (PixelRegion *PR,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint h,
|
|
|
|
const guchar *data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-07 17:58:17 +08:00
|
|
|
gint end = y + h;
|
2007-01-16 05:54:51 +08:00
|
|
|
gint bpp = PR->bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-07-06 18:58:44 +08:00
|
|
|
write_pixel_data (PR->tiles, x, y, x, end-1, data, bpp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
gboolean
|
|
|
|
pixel_region_has_alpha (PixelRegion *PR)
|
1999-08-20 18:06:54 +08:00
|
|
|
{
|
|
|
|
if (PR->bytes == 2 || PR->bytes == 4)
|
2000-06-08 02:43:22 +08:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
1999-08-20 18:06:54 +08:00
|
|
|
}
|
|
|
|
|
2002-08-22 17:48:56 +08:00
|
|
|
PixelRegionIterator *
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_regions_register (gint num_regions,
|
2006-04-12 20:49:29 +08:00
|
|
|
...)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegionIterator *PRI;
|
2001-05-14 21:39:45 +08:00
|
|
|
gboolean found;
|
|
|
|
va_list ap;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (num_regions < 1)
|
2000-06-08 02:43:22 +08:00
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-23 02:29:33 +08:00
|
|
|
PRI = g_slice_new0 (PixelRegionIterator);
|
2005-09-04 01:16:58 +08:00
|
|
|
PRI->dirty_tiles = 1;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
va_start (ap, num_regions);
|
|
|
|
|
|
|
|
found = FALSE;
|
2006-11-05 02:18:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
while (num_regions --)
|
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH;
|
|
|
|
PixelRegion *PR;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
PR = va_arg (ap, PixelRegion *);
|
2002-08-22 17:48:56 +08:00
|
|
|
|
2007-05-23 02:29:33 +08:00
|
|
|
PRH = g_slice_new0 (PixelRegionHolder);
|
1997-11-25 06:05:25 +08:00
|
|
|
PRH->PR = PR;
|
|
|
|
|
|
|
|
if (PR != NULL)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* If there is a defined value for data, make sure tiles is NULL */
|
|
|
|
if (PR->data)
|
|
|
|
PR->tiles = NULL;
|
|
|
|
|
|
|
|
PRH->original_data = PR->data;
|
|
|
|
PRH->startx = PR->x;
|
|
|
|
PRH->starty = PR->y;
|
|
|
|
PRH->PR->process_count = 0;
|
|
|
|
|
2006-11-05 02:18:32 +08:00
|
|
|
if (! found)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
found = TRUE;
|
2006-11-05 02:18:32 +08:00
|
|
|
|
|
|
|
PRI->region_width = PR->w;
|
2006-04-12 20:49:29 +08:00
|
|
|
PRI->region_height = PR->h;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Add the pixel region holder to the list */
|
1998-01-29 16:03:27 +08:00
|
|
|
PRI->pixel_regions = g_slist_prepend (PRI->pixel_regions, PRH);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return pixel_regions_configure (PRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 17:48:56 +08:00
|
|
|
PixelRegionIterator *
|
2001-08-17 22:27:31 +08:00
|
|
|
pixel_regions_process (PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
GSList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
PRI->process_count++;
|
|
|
|
|
|
|
|
/* Unref all referenced tiles and increment the offsets */
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH = list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((PRH->PR != NULL) && (PRH->PR->process_count != PRI->process_count))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* This eliminates the possibility of incrementing the
|
|
|
|
* same region twice
|
|
|
|
*/
|
|
|
|
PRH->PR->process_count++;
|
|
|
|
|
|
|
|
/* Unref the last referenced tile if the underlying region
|
|
|
|
is a tile manager */
|
|
|
|
if (PRH->PR->tiles)
|
|
|
|
{
|
|
|
|
/* only set the dirty flag if PRH->dirty_tiles == TRUE */
|
|
|
|
tile_release (PRH->PR->curtile,
|
|
|
|
PRH->PR->dirty && PRI->dirty_tiles);
|
|
|
|
PRH->PR->curtile = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRH->PR->x += PRI->portion_width;
|
|
|
|
|
|
|
|
if ((PRH->PR->x - PRH->startx) >= PRI->region_width)
|
|
|
|
{
|
|
|
|
PRH->PR->x = PRH->startx;
|
|
|
|
PRH->PR->y += PRI->portion_height;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pixel_regions_configure (PRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-08-17 22:27:31 +08:00
|
|
|
pixel_regions_process_stop (PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
GSList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
PRI->process_count++;
|
|
|
|
|
|
|
|
/* Unref all referenced tiles and increment the offsets */
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH = list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((PRH->PR != NULL) && (PRH->PR->process_count != PRI->process_count))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* This eliminates the possibility of incrementing the
|
|
|
|
* same region twice
|
|
|
|
*/
|
|
|
|
PRH->PR->process_count++;
|
|
|
|
|
|
|
|
/* Unref the last referenced tile if the underlying region
|
|
|
|
is a tile manager */
|
|
|
|
if (PRH->PR->tiles)
|
|
|
|
{
|
|
|
|
tile_release (PRH->PR->curtile, PRH->PR->dirty);
|
|
|
|
PRH->PR->curtile = NULL;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PRI->pixel_regions)
|
|
|
|
{
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
2007-05-23 02:29:33 +08:00
|
|
|
g_slice_free (PixelRegionHolder, list->data);
|
2000-06-08 02:43:22 +08:00
|
|
|
|
1998-01-29 16:03:27 +08:00
|
|
|
g_slist_free (PRI->pixel_regions);
|
2007-05-23 02:29:33 +08:00
|
|
|
|
|
|
|
g_slice_free (PixelRegionIterator, PRI);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************/
|
|
|
|
/* Static Function Definitions */
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
static gint
|
1999-07-20 03:46:05 +08:00
|
|
|
get_portion_height (PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
GSList *list;
|
|
|
|
gint min_height = G_MAXINT;
|
|
|
|
gint height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-29 04:13:59 +08:00
|
|
|
/* Find the minimum height to the next vertical tile
|
|
|
|
* (in the case of a tile manager) or to the end of the
|
2000-06-08 02:43:22 +08:00
|
|
|
* pixel region (in the case of no tile manager)
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH = list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (PRH->PR)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* Check if we're past the point of no return */
|
|
|
|
if ((PRH->PR->y - PRH->starty) >= PRI->region_height)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (PRH->PR->tiles)
|
|
|
|
{
|
|
|
|
height = TILE_HEIGHT - (PRH->PR->y % TILE_HEIGHT);
|
|
|
|
height = CLAMP (height,
|
|
|
|
0,
|
|
|
|
(PRI->region_height - (PRH->PR->y - PRH->starty)));
|
|
|
|
}
|
|
|
|
else
|
2005-09-04 01:16:58 +08:00
|
|
|
{
|
|
|
|
height = (PRI->region_height - (PRH->PR->y - PRH->starty));
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (height < min_height)
|
|
|
|
min_height = height;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return min_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
static gint
|
1999-07-20 03:46:05 +08:00
|
|
|
get_portion_width (PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
GSList *list;
|
|
|
|
gint min_width = G_MAXINT;
|
|
|
|
gint width;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-29 04:13:59 +08:00
|
|
|
/* Find the minimum width to the next vertical tile
|
|
|
|
* (in the case of a tile manager) or to the end of
|
2000-06-08 02:43:22 +08:00
|
|
|
* the pixel region (in the case of no tile manager)
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH = list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (PRH->PR)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* Check if we're past the point of no return */
|
|
|
|
if ((PRH->PR->x - PRH->startx) >= PRI->region_width)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (PRH->PR->tiles)
|
|
|
|
{
|
|
|
|
width = TILE_WIDTH - (PRH->PR->x % TILE_WIDTH);
|
|
|
|
width = CLAMP (width,
|
|
|
|
0,
|
|
|
|
(PRI->region_width - (PRH->PR->x - PRH->startx)));
|
|
|
|
}
|
|
|
|
else
|
2005-09-04 01:16:58 +08:00
|
|
|
{
|
|
|
|
width = (PRI->region_width - (PRH->PR->x - PRH->startx));
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (width < min_width)
|
|
|
|
min_width = width;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return min_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 17:48:56 +08:00
|
|
|
static PixelRegionIterator *
|
1999-07-20 03:46:05 +08:00
|
|
|
pixel_regions_configure (PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
GSList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Determine the portion width and height */
|
2002-08-22 17:48:56 +08:00
|
|
|
PRI->portion_width = get_portion_width (PRI);
|
1997-11-25 06:05:25 +08:00
|
|
|
PRI->portion_height = get_portion_height (PRI);
|
|
|
|
|
2006-11-05 02:18:32 +08:00
|
|
|
if (PRI->portion_width == 0 || PRI->portion_height == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* free the pixel regions list */
|
|
|
|
if (PRI->pixel_regions)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
2007-05-23 02:29:33 +08:00
|
|
|
g_slice_free (PixelRegionHolder, list->data);
|
2000-06-08 02:43:22 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
g_slist_free (PRI->pixel_regions);
|
2007-05-23 02:29:33 +08:00
|
|
|
g_slice_free (PixelRegionIterator, PRI);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRI->process_count++;
|
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
for (list = PRI->pixel_regions; list; list = g_slist_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PixelRegionHolder *PRH = list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((PRH->PR != NULL) && (PRH->PR->process_count != PRI->process_count))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
PRH->PR->process_count++;
|
|
|
|
pixel_region_configure (PRH, PRI);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return PRI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-29 04:13:59 +08:00
|
|
|
pixel_region_configure (PixelRegionHolder *PRH,
|
2006-04-12 20:49:29 +08:00
|
|
|
PixelRegionIterator *PRI)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* Configure the rowstride and data pointer for the pixel region
|
|
|
|
* based on the current offsets into the region and whether the
|
|
|
|
* region is represented by a tile manager or not
|
|
|
|
*/
|
|
|
|
if (PRH->PR->tiles)
|
|
|
|
{
|
2003-09-29 04:13:59 +08:00
|
|
|
PRH->PR->curtile = tile_manager_get_tile (PRH->PR->tiles,
|
2006-04-12 20:49:29 +08:00
|
|
|
PRH->PR->x,
|
|
|
|
PRH->PR->y,
|
|
|
|
TRUE,
|
|
|
|
PRH->PR->dirty);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
PRH->PR->offx = PRH->PR->x % TILE_WIDTH;
|
|
|
|
PRH->PR->offy = PRH->PR->y % TILE_HEIGHT;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-06-08 02:43:22 +08:00
|
|
|
PRH->PR->rowstride = tile_ewidth (PRH->PR->curtile) * PRH->PR->bytes;
|
2003-09-29 04:13:59 +08:00
|
|
|
PRH->PR->data = tile_data_pointer (PRH->PR->curtile,
|
2006-04-12 20:49:29 +08:00
|
|
|
PRH->PR->offx,
|
|
|
|
PRH->PR->offy);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-04 01:16:58 +08:00
|
|
|
PRH->PR->data = (PRH->original_data +
|
|
|
|
PRH->PR->y * PRH->PR->rowstride +
|
|
|
|
PRH->PR->x * PRH->PR->bytes);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRH->PR->w = PRI->portion_width;
|
|
|
|
PRH->PR->h = PRI->portion_height;
|
|
|
|
}
|