Commit 7441a1f6 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: turn the TempBuf's "bytes" into "format" and port everything to it

parent b4e3843b
......@@ -10,7 +10,8 @@ INCLUDES = \
-I$(top_srcdir)/app \
$(BABL_CFLAGS) \
$(CAIRO_CFLAGS) \
$(GLIB_CFLAGS) \
$(GEGL_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
-I$(includedir)
noinst_LIBRARIES = libappbase.a
......
......@@ -20,6 +20,7 @@
#include <stdarg.h>
#include <string.h>
#include <babl/babl.h>
#include <glib-object.h>
#include "base-types.h"
......@@ -95,8 +96,8 @@ pixel_region_init_temp_buf (PixelRegion *PR,
PR->curtile = NULL;
PR->offx = 0;
PR->offy = 0;
PR->bytes = temp_buf->bytes;
PR->rowstride = temp_buf->width * temp_buf->bytes;
PR->bytes = babl_format_get_bytes_per_pixel (temp_buf->format);
PR->rowstride = temp_buf->width * PR->bytes;
PR->x = x;
PR->y = y;
PR->w = w;
......
......@@ -34,24 +34,26 @@
TempBuf *
temp_buf_new (gint width,
gint height,
gint bytes)
temp_buf_new (gint width,
gint height,
const Babl *format)
{
TempBuf *temp;
g_return_val_if_fail (width > 0 && height > 0, NULL);
g_return_val_if_fail (bytes > 0, NULL);
g_return_val_if_fail (format != NULL, NULL);
temp = g_slice_new (TempBuf);
temp->bytes = bytes;
temp->format = format;
temp->width = width;
temp->height = height;
temp->x = 0;
temp->y = 0;
temp->data = g_new (guchar, width * height * bytes);
temp->data = g_new (guchar,
width * height *
babl_format_get_bytes_per_pixel (format));
return temp;
}
......@@ -63,7 +65,7 @@ temp_buf_copy (TempBuf *src)
g_return_val_if_fail (src != NULL, NULL);
dest = temp_buf_new (src->width, src->height, src->bytes);
dest = temp_buf_new (src->width, src->height, src->format);
if (! dest)
return NULL;
......@@ -85,6 +87,7 @@ temp_buf_scale (TempBuf *src,
guchar *dest_data;
gdouble x_ratio;
gdouble y_ratio;
gint bytes;
gint loop1;
gint loop2;
......@@ -93,7 +96,7 @@ temp_buf_scale (TempBuf *src,
dest = temp_buf_new (new_width,
new_height,
src->bytes);
src->format);
src_data = temp_buf_get_data (src);
dest_data = temp_buf_get_data (dest);
......@@ -101,6 +104,8 @@ temp_buf_scale (TempBuf *src,
x_ratio = (gdouble) src->width / (gdouble) new_width;
y_ratio = (gdouble) src->height / (gdouble) new_height;
bytes = babl_format_get_bytes_per_pixel (src->format);
for (loop1 = 0 ; loop1 < new_height ; loop1++)
{
for (loop2 = 0 ; loop2 < new_width ; loop2++)
......@@ -110,13 +115,13 @@ temp_buf_scale (TempBuf *src,
gint i;
src_pixel = src_data +
(gint) (loop2 * x_ratio) * src->bytes +
(gint) (loop1 * y_ratio) * src->bytes * src->width;
(gint) (loop2 * x_ratio) * bytes +
(gint) (loop1 * y_ratio) * bytes * src->width;
dest_pixel = dest_data +
(loop2 + loop1 * new_width) * src->bytes;
(loop2 + loop1 * new_width) * bytes;
for (i = 0 ; i < src->bytes; i++)
for (i = 0 ; i < bytes; i++)
*dest_pixel++ = *src_pixel++;
}
}
......@@ -138,7 +143,7 @@ temp_buf_demultiply (TempBuf *buf)
g_return_if_fail (buf != NULL);
switch (buf->bytes)
switch (babl_format_get_bytes_per_pixel (buf->format))
{
case 1:
break;
......@@ -196,13 +201,13 @@ temp_buf_get_data (const TempBuf *buf)
gsize
temp_buf_get_data_size (TempBuf *buf)
{
return buf->bytes * buf->width * buf->height;
return babl_format_get_bytes_per_pixel (buf->format) * buf->width * buf->height;
}
guchar *
temp_buf_data_clear (TempBuf *buf)
{
memset (buf->data, 0, buf->height * buf->width * buf->bytes);
memset (buf->data, 0, temp_buf_get_data_size (buf));
return buf->data;
}
......
......@@ -21,12 +21,12 @@
struct _TempBuf
{
gint bytes; /* number of bytes per pixel (1,2,3 or 4) */
gint width;
gint height;
gint x, y; /* origin of data source */
guchar *data; /* The data buffer. Do never access this field
directly, use temp_buf_get_data() instead !! */
const Babl *format; /* pixel format */
gint width;
gint height;
gint x, y; /* origin of data source */
guchar *data; /* The data buffer. Do never access this field
directly, use temp_buf_get_data() instead !! */
};
......@@ -34,7 +34,7 @@ struct _TempBuf
TempBuf * temp_buf_new (gint width,
gint height,
gint bytes);
const Babl *fomat);
TempBuf * temp_buf_copy (TempBuf *src);
TempBuf * temp_buf_scale (TempBuf *buf,
gint width,
......
......@@ -17,12 +17,14 @@
#include "config.h"
#include <glib-object.h>
#include <gegl.h>
#include "base-types.h"
#include "core/core-types.h" /* eek, but this file is cruft anyway */
#include "paint-funcs/subsample-region.h"
#include "gegl/gimp-gegl-utils.h"
#include "pixel-region.h"
#include "temp-buf.h"
#include "tile-manager.h"
......@@ -97,7 +99,7 @@ tile_manager_create_preview (TileManager *tiles,
gint subsample = 1;
preview = temp_buf_new (dest_width, dest_height,
tile_manager_bpp (tiles));
gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
pixel_region_init (&srcPR, tiles, src_x, src_y, src_width, src_height, FALSE);
......
......@@ -469,7 +469,7 @@ gimp_edit_fill_full (GimpImage *image,
return TRUE; /* nothing to do, but the fill succeded */
if (pattern &&
(pattern->mask->bytes == 2 || pattern->mask->bytes == 4) &&
babl_format_has_alpha (pattern->mask->format) &&
! gimp_drawable_has_alpha (drawable))
{
format = gimp_drawable_get_format_with_alpha (drawable);
......
......@@ -48,9 +48,7 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
GimpBoundSeg *bound_segs;
gint n_bound_segs;
buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask,
babl_format ("Y u8"),
FALSE);
buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask, FALSE);
bound_segs = gimp_boundary_find (buffer, NULL,
GIMP_BOUNDARY_WITHIN_BOUNDS,
......
......@@ -34,7 +34,7 @@
#define _O_BINARY 0
#endif
#include <glib-object.h>
#include <gegl.h>
#include <glib/gstdio.h>
#include "libgimpbase/gimpbase.h"
......@@ -291,7 +291,8 @@ gimp_brush_load_brush (GimpContext *context,
NULL);
g_free (name);
brush->mask = temp_buf_new (header.width, header.height, 1);
brush->mask = temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
size = header.width * header.height * header.bytes;
......@@ -345,7 +346,8 @@ gimp_brush_load_brush (GimpContext *context,
{
guchar buf[8 * 1024];
brush->pixmap = temp_buf_new (header.width, header.height, 3);
brush->pixmap = temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = temp_buf_get_data (brush->pixmap);
for (i = 0; success && i < size;)
......@@ -648,7 +650,7 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = temp_buf_new (width, height, 1);
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
size = width * height * bytes;
......@@ -755,7 +757,7 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = temp_buf_new (width, height, 1);
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
......
......@@ -190,7 +190,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = temp_buf_new (dest_width, dest_height, 1);
result = temp_buf_new (dest_width, dest_height, babl_format ("Y u8"));
dest = temp_buf_get_data (result);
src = temp_buf_get_data (source);
......@@ -342,10 +342,9 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
blur_src = temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, babl_format ("Y u8"),
TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, babl_format ("Y u8"),
FALSE);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
gimp_gegl_convolve (src_buffer,
GEGL_RECTANGLE (0, 0,
blur_src->width,
......@@ -486,7 +485,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = temp_buf_new (dest_width, dest_height, 3);
result = temp_buf_new (dest_width, dest_height, babl_format ("R'G'B' u8"));
dest = temp_buf_get_data (result);
src = temp_buf_get_data (source);
......@@ -643,8 +642,8 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
blur_src = temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, NULL, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, NULL, FALSE);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
gimp_gegl_convolve (src_buffer,
GEGL_RECTANGLE (0, 0,
......
......@@ -17,8 +17,8 @@
#include "config.h"
#include <glib-object.h>
#include <cairo.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
......@@ -314,7 +314,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
if (! mask_buf)
{
mask_buf = temp_buf_new (1, 1, 1);
mask_buf = temp_buf_new (1, 1, babl_format ("Y u8"));
temp_buf_data_clear ((TempBuf *) mask_buf);
free_mask = TRUE;
}
......@@ -330,7 +330,8 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
}
}
return_buf = temp_buf_new (mask_width, mask_height, 4);
return_buf = temp_buf_new (mask_width, mask_height,
babl_format ("R'G'B'A u8"));
temp_buf_data_clear (return_buf);
mask = temp_buf_get_data (mask_buf);
......
......@@ -203,16 +203,15 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = MIN (gimp_buffer_get_width (gimp->global_buffer), 512);
height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512);
brush->mask = temp_buf_new (width, height, 1);
brush->pixmap = temp_buf_new (width, height, 3);
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
brush->pixmap = temp_buf_new (width, height, babl_format ("R'G'B' u8"));
/* copy the alpha channel into the brush's mask */
if (babl_format_has_alpha (format))
{
dest_buffer = gimp_temp_buf_create_buffer (brush->mask,
babl_format ("A u8"),
FALSE);
dest_buffer = gimp_temp_buf_create_buffer (brush->mask, FALSE);
gegl_buffer_set_format (dest_buffer, babl_format ("A u8"));
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
g_object_unref (dest_buffer);
......@@ -224,7 +223,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
}
/* copy the color channels into the brush's pixmap */
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, NULL, FALSE);
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, FALSE);
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
......@@ -235,7 +234,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = 17;
height = 17;
brush->mask = temp_buf_new (width, height, 1);
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
temp_buf_data_clear (brush->mask);
}
......
......@@ -27,7 +27,7 @@
#include <unistd.h>
#endif
#include <glib-object.h>
#include <gegl.h>
#include <glib/gstdio.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -27,7 +27,7 @@
#include <unistd.h>
#endif
#include <glib-object.h>
#include <gegl.h>
#include <glib/gstdio.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -19,7 +19,7 @@
#include "config.h"
#include <glib-object.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
......@@ -483,7 +483,8 @@ gimp_brush_generated_calc (GimpBrushGenerated *brush,
&s, &c, &x_axis, &y_axis);
mask = temp_buf_new (half_width * 2 + 1,
half_height * 2 + 1, 1);
half_height * 2 + 1,
babl_format ("Y u8"));
centerp = temp_buf_get_data (mask) + half_height * mask->width + half_width;
......
......@@ -33,7 +33,7 @@
#define _O_BINARY 0
#endif
#include <glib-object.h>
#include <gegl.h>
#include <glib/gstdio.h>
#ifdef G_OS_WIN32
......
......@@ -18,7 +18,7 @@
#include "config.h"
#include <glib-object.h>
#include <gegl.h>
#include "libgimpmath/gimpmath.h"
......
......@@ -196,11 +196,9 @@ gimp_buffer_get_new_preview (GimpViewable *viewable,
gint height)
{
GimpBuffer *buffer = GIMP_BUFFER (viewable);
const Babl *format = gimp_buffer_get_format (buffer);
TempBuf *preview;
preview = temp_buf_new (width, height,
babl_format_get_bytes_per_pixel (format));
preview = temp_buf_new (width, height, gimp_buffer_get_format (buffer));
gegl_buffer_get (buffer->buffer, NULL,
MIN ((gdouble) width / (gdouble) gimp_buffer_get_width (buffer),
......
......@@ -33,6 +33,8 @@
#include "config/gimpcoreconfig.h"
#include "gegl/gimp-gegl-utils.h"
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpimage.h"
......@@ -218,7 +220,8 @@ gimp_drawable_indexed_preview (GimpDrawable *drawable,
src_x, src_y, src_width, src_height,
FALSE);
preview_buf = temp_buf_new (dest_width, dest_height, bytes);
preview_buf = temp_buf_new (dest_width, dest_height,
gimp_bpp_to_babl_format (bytes));
pixel_region_init_temp_buf (&destPR, preview_buf,
0, 0, dest_width, dest_height);
......
......@@ -220,7 +220,7 @@ gimp_gradient_get_new_preview (GimpViewable *viewable,
cur_x += dx;
}
temp_buf = temp_buf_new (width, height, 4);
temp_buf = temp_buf_new (width, height, babl_format ("R'G'B'A u8"));
buf = temp_buf_get_data (temp_buf);
......
......@@ -211,7 +211,7 @@ gimp_palette_get_new_preview (GimpViewable *viewable,
gint cell_size;
gint x, y;
temp_buf = temp_buf_new (width, height, 3);
temp_buf = temp_buf_new (width, height, babl_format ("R'G'B' u8"));
memset (temp_buf_get_data (temp_buf), 255, width * height * 3);
if (palette->n_columns > 1)
......
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