Commit 001bd332 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

some code cleanup.

2005-05-08  Sven Neumann  <sven@gimp.org>

	* app/base/tile-manager.[ch]: some code cleanup.
parent 46951bd8
2005-05-08 Sven Neumann <sven@gimp.org>
* app/base/tile-manager.[ch]: some code cleanup.
2005-05-08 Michael Natterer <mitch@gimp.org> 2005-05-08 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimppropwidgets.c (gimp_prop_entry_new) * libgimpwidgets/gimppropwidgets.c (gimp_prop_entry_new)
......
...@@ -48,7 +48,7 @@ tile_manager_new (gint toplevel_width, ...@@ -48,7 +48,7 @@ tile_manager_new (gint toplevel_width,
g_return_val_if_fail (toplevel_width > 0, NULL); g_return_val_if_fail (toplevel_width > 0, NULL);
g_return_val_if_fail (toplevel_height > 0, NULL); g_return_val_if_fail (toplevel_height > 0, NULL);
g_return_val_if_fail (bpp > 0, NULL); g_return_val_if_fail (bpp > 0 && bpp <= 4, NULL);
tm = g_new0 (TileManager, 1); tm = g_new0 (TileManager, 1);
...@@ -318,16 +318,15 @@ tile_manager_invalidate_tiles (TileManager *tm, ...@@ -318,16 +318,15 @@ tile_manager_invalidate_tiles (TileManager *tm,
col = toplevel_tile->tlink->tile_num % tm->ntile_cols; col = toplevel_tile->tlink->tile_num % tm->ntile_cols;
row = toplevel_tile->tlink->tile_num / tm->ntile_cols; row = toplevel_tile->tlink->tile_num / tm->ntile_cols;
x = ((col * TILE_WIDTH + toplevel_tile->ewidth / 2.0) / x = (col * TILE_WIDTH + toplevel_tile->ewidth / 2.0) / (gdouble) tm->width;
(gdouble) tm->width); y = (row * TILE_HEIGHT + toplevel_tile->eheight / 2.0) / (gdouble) tm->height;
y = ((row * TILE_HEIGHT + toplevel_tile->eheight / 2.0) /
(gdouble) tm->height);
if (tm->tiles) if (tm->tiles)
{ {
col = x * tm->width / TILE_WIDTH; col = x * tm->width / TILE_WIDTH;
row = y * tm->height / TILE_HEIGHT; row = y * tm->height / TILE_HEIGHT;
num = row * tm->ntile_cols + col; num = row * tm->ntile_cols + col;
tile_invalidate (&tm->tiles[num], tm, num); tile_invalidate (&tm->tiles[num], tm, num);
} }
} }
...@@ -377,6 +376,7 @@ tile_invalidate (Tile **tile_ptr, ...@@ -377,6 +376,7 @@ tile_invalidate (Tile **tile_ptr,
tile_init (newtile, tile->bpp); tile_init (newtile, tile->bpp);
newtile->ewidth = tile->ewidth; newtile->ewidth = tile->ewidth;
newtile->eheight = tile->eheight; newtile->eheight = tile->eheight;
tile_detach (tile, tm, tile_num); tile_detach (tile, tm, tile_num);
TILE_MUTEX_LOCK (newtile); TILE_MUTEX_LOCK (newtile);
tile_attach (newtile, tm, tile_num); tile_attach (newtile, tm, tile_num);
...@@ -411,24 +411,18 @@ tile_manager_map_tile (TileManager *tm, ...@@ -411,24 +411,18 @@ tile_manager_map_tile (TileManager *tm,
gint ypixel, gint ypixel,
Tile *srctile) Tile *srctile)
{ {
gint tile_row;
gint tile_col;
gint tile_num; gint tile_num;
g_return_if_fail (tm != NULL); g_return_if_fail (tm != NULL);
g_return_if_fail (srctile != NULL); g_return_if_fail (srctile != NULL);
if ((xpixel < 0) || (xpixel >= tm->width) || tile_num = tile_manager_get_tile_num (tm, xpixel, ypixel);
(ypixel < 0) || (ypixel >= tm->height)) if (tile_num < 0)
{ {
g_warning ("tile_manager_map_tile: tile co-ord out of range."); g_warning ("tile_manager_map_tile: tile coordinates out of range.");
return; return;
} }
tile_row = ypixel / TILE_HEIGHT;
tile_col = xpixel / TILE_WIDTH;
tile_num = tile_row * tm->ntile_cols + tile_col;
tile_manager_map (tm, tile_num, srctile); tile_manager_map (tm, tile_num, srctile);
} }
...@@ -533,21 +527,11 @@ tile_manager_get_tile_num (TileManager *tm, ...@@ -533,21 +527,11 @@ tile_manager_get_tile_num (TileManager *tm,
gint xpixel, gint xpixel,
gint ypixel) gint ypixel)
{ {
gint tile_row;
gint tile_col;
gint tile_num;
g_return_val_if_fail (tm != NULL, -1);
if ((xpixel < 0) || (xpixel >= tm->width) || if ((xpixel < 0) || (xpixel >= tm->width) ||
(ypixel < 0) || (ypixel >= tm->height)) (ypixel < 0) || (ypixel >= tm->height))
return -1; return -1;
tile_row = ypixel / TILE_HEIGHT; return (ypixel / TILE_HEIGHT) * tm->ntile_cols + (xpixel / TILE_WIDTH);
tile_col = xpixel / TILE_WIDTH;
tile_num = tile_row * tm->ntile_cols + tile_col;
return tile_num;
} }
void void
...@@ -596,7 +580,8 @@ tile_manager_get_offsets (const TileManager *tm, ...@@ -596,7 +580,8 @@ tile_manager_get_offsets (const TileManager *tm,
gint *x, gint *x,
gint *y) gint *y)
{ {
g_return_if_fail (x!= NULL && y != NULL); g_return_if_fail (tm != NULL);
g_return_if_fail (x != NULL && y != NULL);
*x = tm->x; *x = tm->x;
*y = tm->y; *y = tm->y;
...@@ -694,7 +679,8 @@ tile_manager_map_over_tile (TileManager *tm, ...@@ -694,7 +679,8 @@ tile_manager_map_over_tile (TileManager *tm,
for (tl = tile->tlink; tl; tl = tl->next) for (tl = tile->tlink; tl; tl = tl->next)
{ {
if (tl->tm == tm) break; if (tl->tm == tm)
break;
} }
if (tl == NULL) if (tl == NULL)
...@@ -720,15 +706,16 @@ request_pixel_data (TileManager *tm, ...@@ -720,15 +706,16 @@ request_pixel_data (TileManager *tm,
guint w, h; guint w, h;
pdh = g_new (PixelDataHandlePrivate, 1); pdh = g_new (PixelDataHandlePrivate, 1);
pdh->tm = tm;
pdh->readable = wantread; pdh->tm = tm;
pdh->writeable = wantwrite; pdh->readable = wantread;
pdh->x1 = x1; pdh->writeable = wantwrite;
pdh->y1 = y1; pdh->x1 = x1;
pdh->x2 = x2; pdh->y1 = y1;
pdh->y2 = y2; pdh->x2 = x2;
pdh->public.width = w = (x2-x1)+1; pdh->y2 = y2;
pdh->public.height = h = (y2-y1)+1; pdh->public.width = w = (x2 - x1) + 1;
pdh->public.height = h = (y2 - y1) + 1;
tile_num_1 = tile_manager_get_tile_num (tm, x1, y1); tile_num_1 = tile_manager_get_tile_num (tm, x1, y1);
tile_num_2 = tile_manager_get_tile_num (tm, x2, y2); tile_num_2 = tile_manager_get_tile_num (tm, x2, y2);
...@@ -759,7 +746,7 @@ request_pixel_data (TileManager *tm, ...@@ -759,7 +746,7 @@ request_pixel_data (TileManager *tm,
void void
release_pixel_data (PixelDataHandle *xpdh) release_pixel_data (PixelDataHandle *xpdh)
{ {
PixelDataHandlePrivate *pdh = (PixelDataHandlePrivate *)(xpdh); PixelDataHandlePrivate *pdh = (PixelDataHandlePrivate *) xpdh;
if (pdh->local_buffer) if (pdh->local_buffer)
{ {
...@@ -797,6 +784,7 @@ read_pixel_data (TileManager *tm, ...@@ -797,6 +784,7 @@ read_pixel_data (TileManager *tm,
t = tile_manager_get_tile (tm, x, y, TRUE, FALSE); t = tile_manager_get_tile (tm, x, y, TRUE, FALSE);
s = tile_data_pointer (t, x % TILE_WIDTH, y % TILE_HEIGHT); s = tile_data_pointer (t, x % TILE_WIDTH, y % TILE_HEIGHT);
d = buffer + stride * (y - y1) + tm->bpp * (x - x1); d = buffer + stride * (y - y1) + tm->bpp * (x - x1);
rows = tile_eheight (t) - y % TILE_HEIGHT; rows = tile_eheight (t) - y % TILE_HEIGHT;
if (rows > (y2 - y + 1)) if (rows > (y2 - y + 1))
rows = y2 - y + 1; rows = y2 - y + 1;
...@@ -819,19 +807,20 @@ read_pixel_data (TileManager *tm, ...@@ -819,19 +807,20 @@ read_pixel_data (TileManager *tm,
} }
void void
write_pixel_data (TileManager *tm, write_pixel_data (TileManager *tm,
gint x1, gint x1,
gint y1, gint y1,
gint x2, gint x2,
gint y2, gint y2,
guchar *buffer, const guchar *buffer,
guint stride) guint stride)
{ {
Tile *t; Tile *t;
guchar *s, *d; const guchar *s;
guint x, y; guchar *d;
guint rows, cols; guint x, y;
guint dststride; guint rows, cols;
guint dststride;
for (y = y1; y <= y2; y += TILE_HEIGHT - (y % TILE_HEIGHT)) for (y = y1; y <= y2; y += TILE_HEIGHT - (y % TILE_HEIGHT))
for (x = x1; x <= x2; x += TILE_WIDTH - (x % TILE_WIDTH)) for (x = x1; x <= x2; x += TILE_WIDTH - (x % TILE_WIDTH))
...@@ -881,36 +870,52 @@ read_pixel_data_1 (TileManager *tm, ...@@ -881,36 +870,52 @@ read_pixel_data_1 (TileManager *tm,
if (tm->cached_tile) if (tm->cached_tile)
{ {
guchar *data = tile_data_pointer (tm->cached_tile, const guchar *src = tile_data_pointer (tm->cached_tile,
x % TILE_WIDTH, y % TILE_HEIGHT); x % TILE_WIDTH,
y % TILE_HEIGHT);
switch (tm->bpp) switch (tm->bpp)
{ {
case 4: case 4:
*(guint32*)buffer = *(guint32*)data; *(guint32 *) buffer = *(const guint32 *) src;
break;
default:
{
gint i;
for (i = 0; i < tm->bpp; i++)
buffer[i] = data[i];
}
break; break;
case 3:
*buffer++ = *src++;
case 2:
*buffer++ = *src++;
case 1:
*buffer++ = *src++;
} }
} }
} }
} }
void void
write_pixel_data_1 (TileManager *tm, write_pixel_data_1 (TileManager *tm,
gint x, gint x,
gint y, gint y,
guchar *buffer) const guchar *buffer)
{ {
Tile *t; Tile *tile;
guchar *d; guchar *dest;
tile = tile_manager_get_tile (tm, x, y, TRUE, TRUE);
dest = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
switch (tm->bpp)
{
case 4:
*(guint32 *) dest = *(const guint32 *) buffer;
break;
case 3:
*dest++ = *buffer++;
case 2:
*dest++ = *buffer++;
case 1:
*dest++ = *buffer++;
}
t = tile_manager_get_tile (tm, x, y, TRUE, TRUE); tile_release (tile, TRUE);
d = tile_data_pointer (t, x % TILE_WIDTH, y % TILE_HEIGHT);
memcpy (d, buffer, tm->bpp);
tile_release (t, TRUE);
} }
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
struct _PixelDataHandle struct _PixelDataHandle
{ {
guchar *data; guchar *data;
gint width; gint width;
gint height; gint height;
gint stride; gint stride;
gint bpp; gint bpp;
}; };
/* Creates a new tile manager with the specified /* Creates a new tile manager with the specified
...@@ -145,33 +145,33 @@ PixelDataHandle * request_pixel_data (TileManager *tm, ...@@ -145,33 +145,33 @@ PixelDataHandle * request_pixel_data (TileManager *tm,
void release_pixel_data (PixelDataHandle *pdh); void release_pixel_data (PixelDataHandle *pdh);
void read_pixel_data (TileManager *tm, void read_pixel_data (TileManager *tm,
gint x1, gint x1,
gint y1, gint y1,
gint x2, gint x2,
gint y2, gint y2,
guchar *buffer, guchar *buffer,
guint stride); guint stride);
void write_pixel_data (TileManager *tm, void write_pixel_data (TileManager *tm,
gint x1, gint x1,
gint y1, gint y1,
gint x2, gint x2,
gint y2, gint y2,
guchar *buffer, const guchar *buffer,
guint stride); guint stride);
/* Fill buffer with the pixeldata for the pixel at coordinates x,y /* Fill buffer with the pixeldata for the pixel at coordinates x,y
* if x,y is outside the area of the tilemanger, nothing is done. * if x,y is outside the area of the tilemanger, nothing is done.
*/ */
void read_pixel_data_1 (TileManager *tm, void read_pixel_data_1 (TileManager *tm,
gint x, gint x,
gint y, gint y,
guchar *buffer); guchar *buffer);
void write_pixel_data_1 (TileManager *tm, void write_pixel_data_1 (TileManager *tm,
gint x, gint x,
gint y, gint y,
guchar *buffer); const guchar *buffer);
#endif /* __TILE_MANAGER_H__ */ #endif /* __TILE_MANAGER_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment