Example #1
0
static void
transfer_registration_color (GeglBuffer  *src,
                             GeglBuffer **dst,
                             gint         count)
{
  GimpRGB color, test;
  GeglBufferIterator *gi;
  const Babl *src_format, *dst_format;
  gint i, src_bpp, dst_bpp;
  gdouble white;

  gimp_context_get_foreground (&color);
  white = 1.0;

  src_format = gegl_buffer_get_format (src);
  src_bpp = babl_format_get_bytes_per_pixel (src_format);

  dst_format = gegl_buffer_get_format (dst[0]);
  dst_bpp = babl_format_get_bytes_per_pixel (dst_format);

  gi = gegl_buffer_iterator_new (src, NULL, 0, NULL,
                                 GEGL_BUFFER_READ, GEGL_ABYSS_NONE);

  for (i = 0; i < count; i++)
    {
      gegl_buffer_iterator_add (gi, dst[i], NULL, 0, NULL,
                                GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);
    }

  while (gegl_buffer_iterator_next (gi))
    {
      guint j, k;
      gpointer src_data, dst_data[MAX_EXTRACT_IMAGES];

      src_data = gi->data[0];
      for (j = 0; j < count; j++)
        dst_data[j] = gi->data[j+1];

      for (k = 0; k < gi->length; k++)
        {
          gulong pos;
          pos = k * src_bpp;
          gimp_rgba_set_pixel (&test, src_format, ((guchar *)src_data) + pos);

          if (gimp_rgb_distance (&test, &color) < 1e-6)
            {
              for (j = 0; j < count; j++)
                {
                  gpointer data;
                  data = dst_data[j];
                  babl_process (babl_fish (babl_format ("Y double"), dst_format),
                                &white, (guchar *)data + (k * dst_bpp), 1);
                }
            }
        }
    }
}
Example #2
0
static gboolean
process (GeglOperation        *operation,
         GeglOperationContext *context,
         const gchar          *output_prop,
         const GeglRectangle  *roi,
         gint                  level)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);
  GeglBuffer *input;
  GeglBuffer *output;

  if (! o->input_format || ! o->output_format)
    {
      g_warning ("cast-format: input-format or output-format are not set");
      return FALSE;
    }

  if (babl_format_get_bytes_per_pixel (o->input_format) !=
      babl_format_get_bytes_per_pixel (o->output_format))
    {
      g_warning ("cast-format: input-format and output-format have different bpp");
      return FALSE;
    }

  if (strcmp (output_prop, "output"))
    {
      g_warning ("cast-format: requested processing of %s pad", output_prop);
      return FALSE;
    }

  input = gegl_operation_context_get_source (context, "input");
  if (! input)
    {
      g_warning ("cast: received NULL input");
      return FALSE;
    }

  output = gegl_buffer_new (roi, o->input_format);

  gegl_buffer_copy (input,  roi, GEGL_ABYSS_NONE,
                    output, roi);
  gegl_buffer_set_format (output, o->output_format);

  g_object_unref (input);

  gegl_operation_context_take_object (context, "output", G_OBJECT (output));

  return TRUE;
}
/* fixme: make the api of this, as well as blank be the
 * same as the downscale functions */
static inline void set_half_nearest (GeglTile   *dst_tile,
                                     GeglTile   *src_tile,
                                     gint        width,
                                     gint        height,
                                     const Babl *format,
                                     gint        i,
                                     gint        j)
{
  guchar *dst_data = gegl_tile_get_data (dst_tile);
  guchar *src_data = gegl_tile_get_data (src_tile);
  gint    bpp      = babl_format_get_bytes_per_pixel (format);
  gint    x, y;

  for (y = 0; y < height / 2; y++)
    {
      guchar *dst = dst_data +
                    (
        (
          (y + j * (height / 2)) * width
        ) + i * (width / 2)
                    ) * bpp;

      guchar *src = src_data + (y * 2 * width) * bpp;

      for (x = 0; x < width / 2; x++)
        {
          memcpy (dst, src, bpp);
          dst += bpp;
          src += bpp * 2;
        }
    }
}
Example #4
0
TileManager *
gimp_projection_get_tiles_at_level (GimpProjection *proj,
                                    gint            level,
                                    gboolean       *is_premult)
{
  g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);

  if (! proj->pyramid)
    {
      const Babl *format;
      gint        bytes;
      gint        width;
      gint        height;

      format = gimp_projection_get_format (GIMP_PICKABLE (proj));

      bytes = babl_format_get_bytes_per_pixel (format);
      gimp_projectable_get_size (proj->projectable, &width, &height);

      proj->pyramid = tile_pyramid_new (bytes, width, height);

      tile_pyramid_set_validate_proc (proj->pyramid,
                                      (TileValidateProc) gimp_projection_validate_tile,
                                      proj);
    }

  return tile_pyramid_get_tiles (proj->pyramid, level, is_premult);
}
Example #5
0
void gegl_resample_boxfilter (guchar              *dest_buf,
                              const guchar        *source_buf,
                              const GeglRectangle *dst_rect,
                              const GeglRectangle *src_rect,
                              gint                 s_rowstride,
                              gdouble              scale,
                              const Babl          *format,
                              gint                 d_rowstride)
{
  const Babl *comp_type  = babl_format_get_type (format, 0);
  const gint bpp = babl_format_get_bytes_per_pixel (format);

  if (comp_type == gegl_babl_float())
    gegl_resample_boxfilter_float (dest_buf, source_buf, dst_rect, src_rect,
                                   s_rowstride, scale, bpp, d_rowstride);
  else if (comp_type == gegl_babl_u8())
    gegl_resample_boxfilter_u8 (dest_buf, source_buf, dst_rect, src_rect,
                                s_rowstride, scale, bpp, d_rowstride);
  else if (comp_type == gegl_babl_u16())
    gegl_resample_boxfilter_u16 (dest_buf, source_buf, dst_rect, src_rect,
                                 s_rowstride, scale, bpp, d_rowstride);
  else if (comp_type == gegl_babl_u32())
    gegl_resample_boxfilter_u32 (dest_buf, source_buf, dst_rect, src_rect,
                                 s_rowstride, scale, bpp, d_rowstride);
  else if (comp_type == gegl_babl_double())
    gegl_resample_boxfilter_double (dest_buf, source_buf, dst_rect, src_rect,
                                    s_rowstride, scale, bpp, d_rowstride);
  else
    gegl_resample_nearest (dest_buf, source_buf, dst_rect, src_rect,
                           s_rowstride, scale, bpp, d_rowstride);
}
Example #6
0
static BablPalette *
make_pal (const Babl *pal_space, 
          const Babl *format, 
          const void *data, 
          int         count)
{
  BablPalette *pal = NULL;
  int bpp = babl_format_get_bytes_per_pixel (format);

  babl_assert (count > 0);

  pal = babl_malloc (sizeof (BablPalette));
  pal->count = count;
  pal->format = format;
  pal->data = babl_malloc (bpp * count);
  pal->data_double = babl_malloc (4 * sizeof(double) * count);
  pal->data_u8 = babl_malloc (4 * sizeof(char) * count);
  pal->radii = babl_malloc (sizeof (BablPaletteRadius) *
                            (pal->count - 1)           *
                            pal->count);

  memcpy (pal->data, data, bpp * count);

  babl_process (babl_fish (format, babl_format_with_space ("RGBA double", pal_space)),
                data, pal->data_double, count);
  babl_process (babl_fish (format, babl_format_with_space ("R'G'B'A u8", pal_space)),
                data, pal->data_u8, count);

  babl_palette_init_radii (pal);

  babl_palette_reset_hash (pal);

  return pal;
}
Example #7
0
static cmsUInt32Number
determine_lcms_format (const Babl *babl, cmsHPROFILE profile)
{
  cmsUInt32Number format = COLORSPACE_SH (PT_ANY);
  gint channels, bpc, alpha;
  const Babl *type;

  channels = cmsChannelsOf (cmsGetColorSpace (profile));
  alpha = babl_format_get_n_components (babl) - channels;
  bpc = babl_format_get_bytes_per_pixel (babl)
          / babl_format_get_n_components (babl);

  type = babl_format_get_type (babl, 0);
  if (type == babl_type ("half") ||
      type == babl_type ("float") ||
      type == babl_type ("double"))
    format |= FLOAT_SH (1);

  /* bpc == 8 overflows the bitfield otherwise */
  bpc &= 0x07;

  /*
   * This is needed so the alpha component lines up with RGBA float
   * for our memcpy hack later on.
   */
  if (alpha > 1 || (alpha && channels != 3))
    return 0;

  format |= EXTRA_SH (alpha) | CHANNELS_SH (channels) | BYTES_SH (bpc);
  return format;
}
Example #8
0
static GimpValueArray *
gimp_pattern_select_run_callback (GimpPdbDialog  *dialog,
                                  GimpObject     *object,
                                  gboolean        closing,
                                  GError        **error)
{
  GimpPattern    *pattern = GIMP_PATTERN (object);
  GimpArray      *array;
  GimpValueArray *return_vals;

  array = gimp_array_new (gimp_temp_buf_get_data (pattern->mask),
                          gimp_temp_buf_get_data_size (pattern->mask),
                          TRUE);

  return_vals =
    gimp_pdb_execute_procedure_by_name (dialog->pdb,
                                        dialog->caller_context,
                                        NULL, error,
                                        dialog->callback_name,
                                        G_TYPE_STRING,        gimp_object_get_name (object),
                                        GIMP_TYPE_INT32,      gimp_temp_buf_get_width  (pattern->mask),
                                        GIMP_TYPE_INT32,      gimp_temp_buf_get_height (pattern->mask),
                                        GIMP_TYPE_INT32,      babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask)),
                                        GIMP_TYPE_INT32,      array->length,
                                        GIMP_TYPE_INT8_ARRAY, array,
                                        GIMP_TYPE_INT32,      closing,
                                        G_TYPE_NONE);

  gimp_array_free (array);

  return return_vals;
}
Example #9
0
static void
gegl_affine_fast_reflect_x (GeglBuffer              *dest,
                            GeglBuffer              *src,
                            const GeglRectangle     *dest_rect,
                            const GeglRectangle     *src_rect)
{
  const Babl              *format = gegl_buffer_get_format (src);
  const gint               px_size = babl_format_get_bytes_per_pixel (format),
                           rowstride = src_rect->width * px_size;
  gint                     i;
  guchar                  *buf = (guchar *) g_malloc (src_rect->height * rowstride);

  gegl_buffer_get (src, 1.0, src_rect, format, buf, GEGL_AUTO_ROWSTRIDE);

  for (i = 0; i < src_rect->height / 2; i++)
    {
      gint      dest_offset = (src_rect->height - i - 1) * rowstride,
                src_offset = i * rowstride,
                j;

      for (j = 0; j < rowstride; j++)
        {
          const guchar      tmp = buf[src_offset];

          buf[src_offset] = buf[dest_offset];
          buf[dest_offset] = tmp;

          dest_offset++;
          src_offset++;
        }
    }

  gegl_buffer_set (dest, dest_rect, format, buf, GEGL_AUTO_ROWSTRIDE);
  g_free (buf);
}
Example #10
0
/**
 * gimp_color_frame_set_color:
 * @frame:          The #GimpColorFrame.
 * @sample_average: The set @color is the result of averaging
 * @sample_format:  The format of the #GimpDrawable or #GimpImage the @color
 *                  was picked from.
 * @pixel:          The raw pixel in @sample_format.
 * @color:          The @color to set.
 *
 * Sets the color sample to display in the #GimpColorFrame. if
 * @sample_average is %TRUE, @pixel represents the sample at the
 * center of the average area and will not be displayed.
 **/
void
gimp_color_frame_set_color (GimpColorFrame *frame,
                            gboolean        sample_average,
                            const Babl     *sample_format,
                            gpointer        pixel,
                            const GimpRGB  *color)
{
  g_return_if_fail (GIMP_IS_COLOR_FRAME (frame));
  g_return_if_fail (color != NULL);

  if (frame->sample_valid                     &&
      frame->sample_average == sample_average &&
      frame->sample_format == sample_format   &&
      gimp_rgba_distance (&frame->color, color) < 0.0001)
    {
      frame->color = *color;
      return;
    }

  frame->sample_valid   = TRUE;
  frame->sample_average = sample_average;
  frame->sample_format  = sample_format;
  frame->color          = *color;

  memcpy (frame->pixel, pixel, babl_format_get_bytes_per_pixel (sample_format));

  gimp_color_frame_update (frame);
}
Example #11
0
GimpTempBuf *
tile_manager_get_sub_preview (TileManager *tiles,
                              const Babl  *format,
                              gint         src_x,
                              gint         src_y,
                              gint         src_width,
                              gint         src_height,
                              gint         dest_width,
                              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);
  g_return_val_if_fail (src_y >= 0 &&
                        src_y < tile_manager_height (tiles), NULL);

  g_return_val_if_fail (src_width > 0 &&
                        src_x + src_width <= tile_manager_width (tiles), NULL);
  g_return_val_if_fail (src_height > 0 &&
                        src_y + src_height <= tile_manager_height (tiles),
                        NULL);

  g_return_val_if_fail (dest_width > 0 && dest_height > 0, NULL);

  return tile_manager_create_preview (tiles, format,
                                      src_x, src_y, src_width, src_height,
                                      dest_width, dest_height);
}
guchar *
gegl_buffer_introspectable_get (GeglBuffer          *buffer,
                                const GeglRectangle *rect,
                                gdouble              scale,
                                const gchar         *format_name,
                                GeglAbyssPolicy      repeat_mode,
                                guint               *data_length)
{
  const Babl *format;
  guint bpp;
  guchar *result;

  *data_length = 0;

  if (format_name)
    format = babl_format (format_name);
  else
    format = gegl_buffer_get_format (buffer);

  if (rect->width <= 0 || rect->height <= 0)
    return NULL;
  if (scale <= 0.0)
    return NULL;

  bpp = babl_format_get_bytes_per_pixel (format);
  *data_length = bpp * rect->width * rect->height;

  result = g_malloc (*data_length);

  gegl_buffer_get (buffer, rect, scale, format, result, GEGL_AUTO_ROWSTRIDE, repeat_mode);

  return result;
}
Example #13
0
gboolean
gimp_gegl_mask_is_empty (GeglBuffer *buffer)
{
  GeglBufferIterator *iter;
  const Babl         *format;
  gint                bpp;

  g_return_val_if_fail (GEGL_IS_BUFFER (buffer), FALSE);

  format = gegl_buffer_get_format (buffer);
  bpp    = babl_format_get_bytes_per_pixel (format);

  iter = gegl_buffer_iterator_new (buffer, NULL, 0, format,
                                   GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1);

  while (gegl_buffer_iterator_next (iter))
    {
      if (! gegl_memeq_zero (iter->items[0].data, bpp * iter->length))
        {
          gegl_buffer_iterator_stop (iter);

          return FALSE;
        }
    }

  return TRUE;
}
Example #14
0
static gboolean
process (GeglOperation       *operation,
         void                *in_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglProperties *o  = GEGL_PROPERTIES (operation);
  const Babl *format = gegl_operation_get_format (operation, "input");

  memcpy (out_buf, in_buf, n_pixels * babl_format_get_bytes_per_pixel (format));

  if (o->cache != (void *) operation->node->cache)
    {
      if (o->cache)
        {
          g_object_unref (o->cache);
          o->cache = NULL;
        }

      if (operation->node->cache)
        o->cache = g_object_ref (operation->node->cache);
    }

  return TRUE;
}
static inline void set_half (GeglTile   * dst_tile,
                             GeglTile   * src_tile,
                             gint         width,
                             gint         height,
                             const Babl * format,
                             gint i,
                             gint j)
{
  guchar *dst_data   = gegl_tile_get_data (dst_tile);
  guchar *src_data   = gegl_tile_get_data (src_tile);
  gint    components = babl_format_get_n_components (format);
  gint    bpp        = babl_format_get_bytes_per_pixel (format);

  if (i) dst_data += bpp * width / 2;
  if (j) dst_data += bpp * width * height / 2;

  if (babl_format_get_type (format, 0) == babl_type ("float"))
    {
      downscale_float (components, width, height, width * bpp, src_data, dst_data);
    }
  else if (babl_format_get_type (format, 0) == babl_type ("u8"))
    {
      downscale_u8 (components, width, height, width * bpp, src_data, dst_data);
    }
  else
    {
      set_half_nearest (dst_tile, src_tile, width, height, format, i, j);
    }
}
Example #16
0
static GimpValueArray *
patterns_get_pattern_data_invoker (GimpProcedure         *procedure,
                                   Gimp                  *gimp,
                                   GimpContext           *context,
                                   GimpProgress          *progress,
                                   const GimpValueArray  *args,
                                   GError               **error)
{
  gboolean success = TRUE;
  GimpValueArray *return_vals;
  const gchar *name;
  gchar *actual_name = NULL;
  gint32 width = 0;
  gint32 height = 0;
  gint32 mask_bpp = 0;
  gint32 length = 0;
  guint8 *mask_data = NULL;

  name = g_value_get_string (gimp_value_array_index (args, 0));

  if (success)
    {
      GimpPattern *pattern;

      if (name && strlen (name))
        pattern = gimp_pdb_get_pattern (gimp, name, error);
      else
        pattern = gimp_context_get_pattern (context);

      if (pattern)
        {
          actual_name = g_strdup (gimp_object_get_name (pattern));
          width       = gimp_temp_buf_get_width  (pattern->mask);
          height      = gimp_temp_buf_get_height (pattern->mask);
          mask_bpp    = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pattern->mask));
          length      = gimp_temp_buf_get_data_size (pattern->mask);
          mask_data   = g_memdup (gimp_temp_buf_get_data (pattern->mask), length);
        }
      else
        success = FALSE;
    }

  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    {
      g_value_take_string (gimp_value_array_index (return_vals, 1), actual_name);
      g_value_set_int (gimp_value_array_index (return_vals, 2), width);
      g_value_set_int (gimp_value_array_index (return_vals, 3), height);
      g_value_set_int (gimp_value_array_index (return_vals, 4), mask_bpp);
      g_value_set_int (gimp_value_array_index (return_vals, 5), length);
      gimp_value_take_int8array (gimp_value_array_index (return_vals, 6), mask_data, length);
    }

  return return_vals;
}
Example #17
0
int
gegl_buffer_iterator_add (GeglBufferIterator  *iter,
                          GeglBuffer          *buf,
                          const GeglRectangle *roi,
                          gint                 level,
                          const Babl          *format,
                          GeglAccessMode       access_mode,
                          GeglAbyssPolicy      abyss_policy)
{
  GeglBufferIteratorPriv *priv = iter->priv;
  int                     index;
  SubIterState           *sub;

  g_return_val_if_fail (priv->num_buffers < GEGL_BUFFER_MAX_ITERATORS, 0);


  index = priv->num_buffers++;
  sub = &priv->sub_iter[index];

  if (!format)
    format = gegl_buffer_get_format (buf);

  if (!roi)
    roi = &buf->extent;

  sub->buffer       = buf;
  sub->full_rect    = *roi;

  if (level)
  {
    sub->full_rect.x >>= level;
    sub->full_rect.y >>= level;
    sub->full_rect.width >>= level;
    sub->full_rect.height >>= level;
  }

  sub->access_mode  = access_mode;
  sub->abyss_policy = abyss_policy;
  sub->current_tile = NULL;
  sub->real_data    = NULL;
  sub->linear_tile  = NULL;
  sub->format       = format;
  sub->format_bpp   = babl_format_get_bytes_per_pixel (format);
  sub->level        = level;

  if (index > 0)
    {
      priv->sub_iter[index].full_rect.width  = priv->sub_iter[0].full_rect.width;
      priv->sub_iter[index].full_rect.height = priv->sub_iter[0].full_rect.height;
    }

  //if (level != 0)
  //  g_warning ("iterator level != 0");

  return index;
}
Example #18
0
gboolean
gimp_pickable_pick_color (GimpPickable *pickable,
                          gint          x,
                          gint          y,
                          gboolean      sample_average,
                          gdouble       average_radius,
                          gpointer      pixel,
                          GimpRGB      *color)
{
  const Babl *format;
  gdouble     sample[4];

  g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), FALSE);

  format = gimp_pickable_get_format (pickable);

  if (! gimp_pickable_get_pixel_at (pickable, x, y, format, sample))
    return FALSE;

  gimp_pickable_pixel_to_srgb (pickable, format, sample, color);

  if (pixel)
    memcpy (pixel, sample, babl_format_get_bytes_per_pixel (format));

  if (sample_average)
    {
      gint    count        = 0;
      gdouble color_avg[4] = { 0.0, 0.0, 0.0, 0.0 };
      gint    radius       = (gint) average_radius;
      gint    i, j;

      format = babl_format ("RaGaBaA double");

      for (i = x - radius; i <= x + radius; i++)
        for (j = y - radius; j <= y + radius; j++)
          if (gimp_pickable_get_pixel_at (pickable, i, j, format, sample))
            {
              count++;

              color_avg[RED]   += sample[RED];
              color_avg[GREEN] += sample[GREEN];
              color_avg[BLUE]  += sample[BLUE];
              color_avg[ALPHA] += sample[ALPHA];
            }

      sample[RED]   = color_avg[RED]   / count;
      sample[GREEN] = color_avg[GREEN] / count;
      sample[BLUE]  = color_avg[BLUE]  / count;
      sample[ALPHA] = color_avg[ALPHA] / count;

      gimp_pickable_pixel_to_srgb (pickable, format, sample, color);
    }

  return TRUE;
}
Example #19
0
static gint
save_contiguous(GeglOperation *operation,
                GeglBuffer    *input,
                const GeglRectangle *result,
                const Babl *format)
{
  GeglProperties *o = GEGL_PROPERTIES(operation);
  Priv *p = (Priv*) o->user_data;
  gint bytes_per_pixel, bytes_per_row;
  gint tile_width = result->width;
  gint tile_height = result->height;
  guchar *buffer;
  gint x, y;

  g_return_val_if_fail(p->tiff != NULL, -1);

  bytes_per_pixel = babl_format_get_bytes_per_pixel(format);
  bytes_per_row = bytes_per_pixel * tile_width;

  buffer = g_try_new(guchar, bytes_per_row * tile_height);

  g_assert(buffer != NULL);

  for (y = result->y; y < result->y + tile_height; y += tile_height)
    {
      for (x = result->x; x < result->x + tile_width; x += tile_width)
        {
          GeglRectangle tile = { x, y, tile_width, tile_height };
          gint row;

          gegl_buffer_get(input, &tile, 1.0, format, buffer,
                          GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

          for (row = y; row < y + tile_height; row++)
            {
              guchar *tile_row = buffer + (bytes_per_row * (row - y));
              gint written;

              written = TIFFWriteScanline(p->tiff, tile_row, row, 0);

              if (!written)
                {
                  g_critical("failed a scanline write on row %d", row);
                  continue;
                }
            }
        }
    }

  TIFFFlushData(p->tiff);

  g_free(buffer);
  return 0;
}
Example #20
0
static void
constructed (GObject *object)
{
  GeglTileBackend *backend = GEGL_TILE_BACKEND (object);

  G_OBJECT_CLASS (parent_class)->constructed (object);

  g_assert (backend->priv->tile_width > 0 && backend->priv->tile_height > 0);
  g_assert (backend->priv->format);

  backend->priv->px_size = babl_format_get_bytes_per_pixel (backend->priv->format);
  backend->priv->tile_size = backend->priv->tile_width * backend->priv->tile_height * backend->priv->px_size;
}
void
gimp_drawable_foreground_extract_siox (GimpDrawable       *mask,
                                       SioxState          *state,
                                       SioxRefinementType  refinement,
                                       gint                smoothness,
                                       const gdouble       sensitivity[3],
                                       gboolean            multiblob,
                                       GimpProgress       *progress)
{
  GeglBuffer *buffer;
  gint        x1, y1;
  gint        x2, y2;

  g_return_if_fail (GIMP_IS_DRAWABLE (mask));
  g_return_if_fail (babl_format_get_bytes_per_pixel (gimp_drawable_get_format (mask)) == 1);

  g_return_if_fail (state != NULL);

  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));

  if (progress)
    gimp_progress_start (progress, _("Foreground Extraction"), FALSE);

  if (GIMP_IS_CHANNEL (mask))
    {
      gimp_channel_bounds (GIMP_CHANNEL (mask), &x1, &y1, &x2, &y2);
    }
  else
    {
      x1 = 0;
      y1 = 0;
      x2 = gimp_item_get_width  (GIMP_ITEM (mask));
      y2 = gimp_item_get_height (GIMP_ITEM (mask));
    }

  buffer = gimp_drawable_get_buffer (mask);

  siox_foreground_extract (state, refinement,
                           gimp_gegl_buffer_get_tiles (buffer),
                           x1, y1, x2, y2,
                           smoothness, sensitivity, multiblob,
                           (SioxProgressFunc) gimp_progress_set_value,
                           progress);

  if (progress)
    gimp_progress_end (progress);

  gimp_drawable_update (mask, x1, y1, x2, y2);
}
Example #22
0
gint64
gimp_gegl_buffer_get_memsize (GeglBuffer *buffer)
{
  if (buffer)
    {
      const Babl *format = gegl_buffer_get_format (buffer);

      return (babl_format_get_bytes_per_pixel (format) *
              gegl_buffer_get_width (buffer) *
              gegl_buffer_get_height (buffer) +
              gimp_g_object_get_memsize (G_OBJECT (buffer)));
    }

  return 0;
}
Example #23
0
gint64
gimp_gegl_pyramid_get_memsize (GeglBuffer *buffer)
{
  if (buffer)
    {
      const Babl *format = gegl_buffer_get_format (buffer);

      /* The pyramid levels constitute a geometric sum with a ratio of 1/4. */
      return ((gint64) babl_format_get_bytes_per_pixel (format) *
              (gint64) gegl_buffer_get_width (buffer) *
              (gint64) gegl_buffer_get_height (buffer) * 1.33 +
              gimp_g_object_get_memsize (G_OBJECT (buffer)));
    }

  return 0;
}
Example #24
0
static inline void set_half (GeglTile   * dst_tile,
                             GeglTile   * src_tile,
                             gint         width,
                             gint         height,
                             const Babl * format,
                             gint i,
                             gint j)
{
  guchar     *dst_data   = gegl_tile_get_data (dst_tile);
  guchar     *src_data   = gegl_tile_get_data (src_tile);
  gint        bpp        = babl_format_get_bytes_per_pixel (format);

  if (i) dst_data += bpp * width / 2;
  if (j) dst_data += bpp * width * height / 2;

  gegl_downscale_2x2 (format, width, height, src_data, width * bpp, dst_data, width * bpp);
}
Example #25
0
/**
 * gimp_projection_estimate_memsize:
 * @type:      the projectable's base type
 * @precision: the projectable's precision
 * @width:     projection width
 * @height:    projection height
 *
 * Calculates a rough estimate of the memory that is required for the
 * projection of an image with the given @width and @height.
 *
 * Return value: a rough estimate of the memory requirements.
 **/
gint64
gimp_projection_estimate_memsize (GimpImageBaseType type,
                                  GimpPrecision     precision,
                                  gint              width,
                                  gint              height)
{
  const Babl *format;
  gint64      bytes;

  if (type == GIMP_INDEXED)
    type = GIMP_RGB;

  format = gimp_babl_format (type, precision, TRUE);
  bytes  = babl_format_get_bytes_per_pixel (format);

  /* The pyramid levels constitute a geometric sum with a ratio of 1/4. */
  return bytes * (gint64) width * (gint64) height * 1.33;
}
Example #26
0
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, format,
                                      0, 0,
                                      tile_manager_width (tiles),
                                      tile_manager_height (tiles),
                                      width, height);
}
Example #27
0
static GObject *
constructor (GType                  type,
             guint                  n_params,
             GObjectConstructParam *params)
{
  GObject         *object;
  GeglTileBackend *backend;

  object  = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
  backend = GEGL_TILE_BACKEND (object);

  g_assert (backend->priv->tile_width > 0 && backend->priv->tile_height > 0);
  g_assert (backend->priv->format);

  backend->priv->px_size = babl_format_get_bytes_per_pixel (backend->priv->format);
  backend->priv->tile_size = backend->priv->tile_width * backend->priv->tile_height * backend->priv->px_size;

  return object;
}
Example #28
0
static gint
save_array (GOutputStream       *stream,
            GeglBuffer          *input,
            const GeglRectangle *result,
            const Babl          *format)
{
  gint bytes_per_pixel, bytes_per_row;
  gint x = result->x, y = result->y;
  gint width = result->width - result->x;
  gint height = result->height - result->y;
  gint column_stride = 32;
  gchar *buffer;
  gint nb_components ,row;

  nb_components = babl_format_get_n_components (format);
  bytes_per_pixel = babl_format_get_bytes_per_pixel (format);

  write_header (stream, width, height, nb_components, bytes_per_pixel);

  bytes_per_row = bytes_per_pixel * width;

  buffer = g_try_new (gchar, bytes_per_row * column_stride);

  g_assert (buffer != NULL);

  for (row = 0; row < height; row += column_stride)
    {
      GeglRectangle tile = { x, 0, width, 0 };

      tile.y = y + row;
      tile.height = MIN (column_stride, height - row);

      gegl_buffer_get (input, &tile, 1.0, format, buffer,
                       GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

      write_to_stream (stream, buffer, bytes_per_row * tile.height);
    }

  g_free (buffer);
  return 0;
}
static inline void set_blank (GeglTile   *dst_tile,
                              gint        width,
                              gint        height,
                              const Babl *format,
                              gint        i,
                              gint        j)
{
  guchar *dst_data  = gegl_tile_get_data (dst_tile);
  gint    bpp       = babl_format_get_bytes_per_pixel (format);
  gint    rowstride = width * bpp;
  gint    scanline;

  gint    bytes = width * bpp / 2;
  guchar *dst   = dst_data + j * height / 2 * rowstride + i * rowstride / 2;

  for (scanline = 0; scanline < height / 2; scanline++)
    {
      memset (dst, 0x0, bytes);
      dst += rowstride;
    }
}
void
gegl_buffer_introspectable_set (GeglBuffer          *buffer,
                                const GeglRectangle *rect,
                                const gchar         *format_name,
                                const guchar        *src,
                                gint                 src_length)
{
  const Babl *format;
  guint bpp;

  format = babl_format (format_name);

  if (rect->width <= 0 || rect->height <= 0)
    return;

  bpp = babl_format_get_bytes_per_pixel (format);

  g_return_if_fail (src_length == bpp * rect->width * rect->height);

  gegl_buffer_set (buffer, rect, 0, format, src, 0);
}