mirror of https://github.com/GNOME/gimp.git
app: remove bpp <-> format conversion stuff from gimp-gegl-utils.[ch]
Fix stuff by picking formats as we get data from the "outside", like a GdkPixbuf, and pass around more proper formats from where we know them.
This commit is contained in:
parent
15d1827ead
commit
3af70584d0
|
@ -23,8 +23,6 @@
|
|||
|
||||
#include "paint-funcs/subsample-region.h"
|
||||
|
||||
#include "gegl/gimp-gegl-utils.h"
|
||||
|
||||
#include "core/gimptempbuf.h"
|
||||
|
||||
#include "pixel-region.h"
|
||||
|
@ -33,6 +31,7 @@
|
|||
|
||||
|
||||
static GimpTempBuf * tile_manager_create_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint src_x,
|
||||
gint src_y,
|
||||
gint src_width,
|
||||
|
@ -43,13 +42,17 @@ static GimpTempBuf * tile_manager_create_preview (TileManager *tiles,
|
|||
|
||||
GimpTempBuf *
|
||||
tile_manager_get_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
g_return_val_if_fail (tiles != NULL, NULL);
|
||||
g_return_val_if_fail (format != NULL, NULL);
|
||||
g_return_val_if_fail (babl_format_get_bytes_per_pixel (format) ==
|
||||
tile_manager_bpp (tiles), NULL);
|
||||
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
||||
|
||||
return tile_manager_create_preview (tiles,
|
||||
return tile_manager_create_preview (tiles, format,
|
||||
0, 0,
|
||||
tile_manager_width (tiles),
|
||||
tile_manager_height (tiles),
|
||||
|
@ -58,6 +61,7 @@ tile_manager_get_preview (TileManager *tiles,
|
|||
|
||||
GimpTempBuf *
|
||||
tile_manager_get_sub_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint src_x,
|
||||
gint src_y,
|
||||
gint src_width,
|
||||
|
@ -66,6 +70,9 @@ tile_manager_get_sub_preview (TileManager *tiles,
|
|||
gint dest_height)
|
||||
{
|
||||
g_return_val_if_fail (tiles != NULL, NULL);
|
||||
g_return_val_if_fail (format != NULL, NULL);
|
||||
g_return_val_if_fail (babl_format_get_bytes_per_pixel (format) ==
|
||||
tile_manager_bpp (tiles), NULL);
|
||||
|
||||
g_return_val_if_fail (src_x >= 0 &&
|
||||
src_x < tile_manager_width (tiles), NULL);
|
||||
|
@ -80,13 +87,14 @@ tile_manager_get_sub_preview (TileManager *tiles,
|
|||
|
||||
g_return_val_if_fail (dest_width > 0 && dest_height > 0, NULL);
|
||||
|
||||
return tile_manager_create_preview (tiles,
|
||||
return tile_manager_create_preview (tiles, format,
|
||||
src_x, src_y, src_width, src_height,
|
||||
dest_width, dest_height);
|
||||
}
|
||||
|
||||
static GimpTempBuf *
|
||||
tile_manager_create_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint src_x,
|
||||
gint src_y,
|
||||
gint src_width,
|
||||
|
@ -99,8 +107,7 @@ tile_manager_create_preview (TileManager *tiles,
|
|||
PixelRegion destPR;
|
||||
gint subsample = 1;
|
||||
|
||||
preview = gimp_temp_buf_new (dest_width, dest_height,
|
||||
gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
|
||||
preview = gimp_temp_buf_new (dest_width, dest_height, format);
|
||||
|
||||
pixel_region_init (&srcPR, tiles, src_x, src_y, src_width, src_height, FALSE);
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
|
||||
|
||||
GimpTempBuf * tile_manager_get_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint width,
|
||||
gint height);
|
||||
GimpTempBuf * tile_manager_get_sub_preview (TileManager *tiles,
|
||||
const Babl *format,
|
||||
gint src_x,
|
||||
gint src_y,
|
||||
gint src_width,
|
||||
|
|
|
@ -159,6 +159,7 @@ gimp_drawable_get_sub_preview (GimpDrawable *drawable,
|
|||
dest_width, dest_height);
|
||||
|
||||
return tile_manager_get_sub_preview (gimp_drawable_get_tiles (drawable),
|
||||
gimp_drawable_get_preview_format (drawable),
|
||||
src_x, src_y, src_width, src_height,
|
||||
dest_width, dest_height);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "gimpimage.h"
|
||||
#include "gimpimage-preview.h"
|
||||
#include "gimpimage-private.h"
|
||||
#include "gimpprojectable.h"
|
||||
#include "gimpprojection.h"
|
||||
#include "gimptempbuf.h"
|
||||
|
||||
|
@ -141,7 +142,9 @@ gimp_image_get_new_preview (GimpViewable *viewable,
|
|||
level = gimp_projection_get_level (projection, scale_x, scale_y);
|
||||
tiles = gimp_projection_get_tiles_at_level (projection, level, &is_premult);
|
||||
|
||||
buf = tile_manager_get_preview (tiles, width, height);
|
||||
buf = tile_manager_get_preview (tiles,
|
||||
gimp_projectable_get_format (GIMP_PROJECTABLE (image)),
|
||||
width, height);
|
||||
|
||||
if (is_premult)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ gimp_pattern_load (GimpContext *context,
|
|||
GError **error)
|
||||
{
|
||||
GimpPattern *pattern = NULL;
|
||||
const Babl *format = NULL;
|
||||
gint fd;
|
||||
PatternHeader header;
|
||||
gint bn_size;
|
||||
|
@ -155,8 +156,15 @@ gimp_pattern_load (GimpContext *context,
|
|||
|
||||
g_free (name);
|
||||
|
||||
pattern->mask = gimp_temp_buf_new (header.width, header.height,
|
||||
gimp_bpp_to_babl_format (header.bytes));
|
||||
switch (header.bytes)
|
||||
{
|
||||
case 1: format = babl_format ("Y' u8"); break;
|
||||
case 2: format = babl_format ("Y'A u8"); break;
|
||||
case 3: format = babl_format ("R'G'B' u8"); break;
|
||||
case 4: format = babl_format ("R'G'B'A u8"); break;
|
||||
}
|
||||
|
||||
pattern->mask = gimp_temp_buf_new (header.width, header.height, format);
|
||||
|
||||
if (read (fd, gimp_temp_buf_get_data (pattern->mask),
|
||||
header.width * header.height * header.bytes) <
|
||||
|
@ -216,10 +224,9 @@ gimp_pattern_load_pixbuf (GimpContext *context,
|
|||
NULL);
|
||||
g_free (name);
|
||||
|
||||
pattern->mask =
|
||||
gimp_temp_buf_new (gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf),
|
||||
gimp_bpp_to_babl_format (gdk_pixbuf_get_n_channels (pixbuf)));
|
||||
pattern->mask = gimp_temp_buf_new (gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf),
|
||||
gimp_pixbuf_get_format (pixbuf));
|
||||
|
||||
src_buffer = gimp_pixbuf_create_buffer (pixbuf);
|
||||
dest_buffer = gimp_temp_buf_create_buffer (pattern->mask);
|
||||
|
|
|
@ -57,62 +57,6 @@ gimp_babl_format_get_image_type (const Babl *format)
|
|||
g_return_val_if_reached (-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_bpp_to_babl_format:
|
||||
* @bpp: bytes per pixel
|
||||
*
|
||||
* Return the Babl format to use for a given number of bytes per pixel.
|
||||
* This function assumes that the data is 8bit.
|
||||
*
|
||||
* Return value: the Babl format to use
|
||||
**/
|
||||
const Babl *
|
||||
gimp_bpp_to_babl_format (guint bpp)
|
||||
{
|
||||
g_return_val_if_fail (bpp > 0 && bpp <= 4, NULL);
|
||||
|
||||
switch (bpp)
|
||||
{
|
||||
case 1:
|
||||
return babl_format ("Y' u8");
|
||||
case 2:
|
||||
return babl_format ("Y'A u8");
|
||||
case 3:
|
||||
return babl_format ("R'G'B' u8");
|
||||
case 4:
|
||||
return babl_format ("R'G'B'A u8");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_bpp_to_babl_format_with_alpha:
|
||||
* @bpp: bytes per pixel
|
||||
*
|
||||
* Return the Babl format to use for a given number of bytes per pixel.
|
||||
* This function assumes that the data is 8bit.
|
||||
*
|
||||
* Return value: the Babl format to use
|
||||
**/
|
||||
const Babl *
|
||||
gimp_bpp_to_babl_format_with_alpha (guint bpp)
|
||||
{
|
||||
g_return_val_if_fail (bpp > 0 && bpp <= 4, NULL);
|
||||
|
||||
switch (bpp)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
return babl_format ("Y'A u8");
|
||||
case 3:
|
||||
case 4:
|
||||
return babl_format ("R'G'B'A u8");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
|
||||
{
|
||||
|
@ -129,24 +73,36 @@ gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
|
|||
return "nearest";
|
||||
}
|
||||
|
||||
const Babl *
|
||||
gimp_pixbuf_get_format (GdkPixbuf *pixbuf)
|
||||
{
|
||||
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
||||
|
||||
switch (gdk_pixbuf_get_n_channels (pixbuf))
|
||||
{
|
||||
case 3: return babl_format ("R'G'B' u8");
|
||||
case 4: return babl_format ("R'G'B'A u8");
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
GeglBuffer *
|
||||
gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf)
|
||||
{
|
||||
gint width;
|
||||
gint height;
|
||||
gint rowstride;
|
||||
gint channels;
|
||||
gint width;
|
||||
gint height;
|
||||
gint rowstride;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
||||
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
channels = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
|
||||
return gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
|
||||
gimp_bpp_to_babl_format (channels),
|
||||
GEGL_RECTANGLE (0,0,width,height),
|
||||
gimp_pixbuf_get_format (pixbuf),
|
||||
GEGL_RECTANGLE (0, 0, width, height),
|
||||
rowstride,
|
||||
(GDestroyNotify) g_object_unref,
|
||||
g_object_ref (pixbuf));
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
|
||||
GimpImageType gimp_babl_format_get_image_type (const Babl *format);
|
||||
|
||||
const Babl * gimp_bpp_to_babl_format (guint bpp) G_GNUC_CONST;
|
||||
const Babl * gimp_bpp_to_babl_format_with_alpha (guint bpp) G_GNUC_CONST;
|
||||
|
||||
const gchar * gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation) G_GNUC_CONST;
|
||||
|
||||
GeglBuffer * gimp_gegl_buffer_new (const GeglRectangle *rect,
|
||||
|
@ -40,6 +37,7 @@ GeglBuffer * gimp_tile_manager_create_buffer (TileManager *tm,
|
|||
const Babl *format);
|
||||
TileManager * gimp_gegl_buffer_get_tiles (GeglBuffer *buffer);
|
||||
|
||||
const Babl * gimp_pixbuf_get_format (GdkPixbuf *pixbuf);
|
||||
GeglBuffer * gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf);
|
||||
|
||||
void gimp_gegl_buffer_refetch_tiles (GeglBuffer *buffer);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "paint-types.h"
|
||||
|
||||
#include "gegl/gimp-gegl-utils.h"
|
||||
#include "gegl/gimp-babl.h"
|
||||
|
||||
#include "core/gimpbrush.h"
|
||||
#include "core/gimpdrawable.h"
|
||||
|
@ -1620,8 +1620,9 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
|
|||
gint width,
|
||||
GimpBrushApplicationMode mode)
|
||||
{
|
||||
gint pixmap_bytes;
|
||||
guchar *b;
|
||||
GimpImageBaseType pixmap_base_type;
|
||||
gint pixmap_bytes;
|
||||
guchar *b;
|
||||
|
||||
/* Make sure x, y are positive */
|
||||
while (x < 0)
|
||||
|
@ -1629,7 +1630,8 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
|
|||
while (y < 0)
|
||||
y += pixmap_mask->height;
|
||||
|
||||
pixmap_bytes = babl_format_get_bytes_per_pixel (pixmap_mask->format);
|
||||
pixmap_base_type = gimp_babl_format_get_base_type (pixmap_mask->format);
|
||||
pixmap_bytes = babl_format_get_bytes_per_pixel (pixmap_mask->format);
|
||||
|
||||
/* Point to the approriate scanline */
|
||||
b = (gimp_temp_buf_get_data (pixmap_mask) +
|
||||
|
@ -1644,7 +1646,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
|
|||
guchar *l = line_buf;
|
||||
gint i;
|
||||
|
||||
fish = babl_fish (gimp_bpp_to_babl_format_with_alpha (pixmap_bytes),
|
||||
fish = babl_fish (gimp_babl_format (pixmap_base_type, TRUE),
|
||||
gimp_drawable_get_format_with_alpha (drawable));
|
||||
|
||||
/* put the source pixmap's pixels, plus the mask's alpha, into
|
||||
|
@ -1672,7 +1674,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
|
|||
guchar *l = line_buf;
|
||||
gint i;
|
||||
|
||||
fish = babl_fish (gimp_bpp_to_babl_format (pixmap_bytes),
|
||||
fish = babl_fish (pixmap_mask->format,
|
||||
gimp_drawable_get_format_with_alpha (drawable));
|
||||
|
||||
/* put the source pixmap's pixels, into one line, so we can use
|
||||
|
|
Loading…
Reference in New Issue