Example #1
0
TEST ()
{
  GeglBuffer    *buffer, *sub, *subsub, *foo;
  GeglRectangle  subrect =    {5, 5, 10, 10};
  GeglRectangle  foor =  {0, 0, 10, 10};
  GeglRectangle  rect =  {0, 0, 20, 20};
  test_start ();
  buffer = gegl_buffer_new (&rect, babl_format ("Y float"));

  sub = gegl_buffer_create_sub_buffer (buffer, &subrect);
  vgrad (buffer);
  vgrad (sub);
  subsub = g_object_new (GEGL_TYPE_BUFFER,
                         "source", sub,
                         "x", 0,
                         "y", 0,
                         "width", 40,
                         "height", 40,
                         "shift-x", 0,
                         "shift-y", 0,
                         NULL);
  foo = gegl_buffer_create_sub_buffer (subsub, &foor);

  /*fill (subsub, 0.2);*/
  print_buffer (buffer);
  print_buffer (foo);
  g_object_unref (sub);
  g_object_unref (subsub);
  g_object_unref (buffer);
  g_object_unref (foo);
  test_end ();
}
TEST ()
{
  GeglBuffer    *buffer, *sub1, *sub2, *sub3;
  GeglRectangle  subrect1 = {5, 5, 10, 10};
  GeglRectangle  subrect2 = {8, 8, 30, 30};
  GeglRectangle  subrect3 = {-2, -2, 24, 24};
  GeglRectangle  rect = {0, 0, 20, 20};
  test_start ();
  buffer = gegl_buffer_new (&rect, babl_format ("Y float"));
  sub1 = gegl_buffer_create_sub_buffer (buffer, &subrect1);
  sub2 = gegl_buffer_create_sub_buffer (buffer, &subrect2);
  sub3 = gegl_buffer_create_sub_buffer (buffer, &subrect3);

  fill (sub1, 0.5);
  print (("root with sub1 filled in:\n"));
  print_buffer (buffer);

  print (("sub2 before fill:\n"));
  print_buffer (sub2);
  fill (sub2, 1.0);
  print (("final root:\n"));
  print_buffer (buffer);
  print (("final sub1:\n"));
  print_buffer (sub1);
  print (("final sub3:\n"));
  print_buffer (sub3);

  gegl_buffer_destroy (sub1);
  gegl_buffer_destroy (sub2);
  gegl_buffer_destroy (sub3);
  gegl_buffer_destroy (buffer);
  test_end ();
}
Example #3
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *aux,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
  GeglBuffer            *temp_in;
  GeglBuffer            *temp_aux;

  /* FIXME: just pass the originals buffers if the result rectangle does not
   * include both input buffers
   */

  temp_in = gegl_buffer_create_sub_buffer (input, result);
  temp_aux = gegl_buffer_create_sub_buffer (aux, result);

    {
      gfloat *buf  = g_new0 (gfloat, result->width * result->height * 4);
      gfloat *bufB = g_new0 (gfloat, result->width * result->height * 4);

      gegl_buffer_get (temp_in,  NULL, 1.0, babl_format ("RGBA float"), buf,
                       GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
      gegl_buffer_get (temp_aux, NULL, 1.0, babl_format ("RGBA float"), bufB,
                       GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
        {
          gint offset=0;
          gint x,y;
          for (y=0;y<gegl_buffer_get_height (output);y++)
            for (x=0;x<gegl_buffer_get_width (output);x++)
              {
                if (x + result->x >= gegl_buffer_get_width (input))
                  {
                    buf[offset+0]=bufB[offset+0];
                    buf[offset+1]=bufB[offset+1];
                    buf[offset+2]=bufB[offset+2];
                    buf[offset+3]=bufB[offset+3];
                  }
                offset+=4;
              }
        }
      gegl_buffer_set (output, NULL, 0, babl_format ("RGBA float"), buf,
                       GEGL_AUTO_ROWSTRIDE);

      g_free (buf);
      g_free (bufB);
    }
  g_object_unref (temp_in);
  g_object_unref (temp_aux);

  return  TRUE;
}
Example #4
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result)
{
    GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);
    GeglBuffer   *temp_in;
    GeglRectangle compute  = gegl_operation_get_required_for_output (operation, "input", result);

    if (result->width == 0 ||
            result->height== 0 ||
            o->radius < 1.0)
    {
        output = g_object_ref (input);
    }
    else
    {
        temp_in = gegl_buffer_create_sub_buffer (input, &compute);
        snn_percentile (temp_in, output, o->radius, o->percentile, o->pairs);
        g_object_unref (temp_in);
    }

    return  TRUE;
}
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
  GeglChantO          *o = GEGL_CHANT_PROPERTIES (operation);
  GeglBuffer          *temp_in;
  GeglRectangle        compute;

  if (gegl_cl_is_accelerated ())
    if (cl_process (operation, input, output, result))
      return TRUE;

  compute  = gegl_operation_get_required_for_output (
                   operation, "input", result);

  if (o->radius < 1.0)
    {
      output = g_object_ref (input);
    }
  else
    {
      temp_in = gegl_buffer_create_sub_buffer (input, &compute);

      snn_mean (temp_in, output, result, o->radius, o->pairs);
      g_object_unref (temp_in);
    }

  return  TRUE;
}
Example #6
0
GeglBuffer*
gegl_buffer_open (const gchar *uri)
{
  /* only supports local addresses for now */
  guint process; /* self */
  guint handle;

  process = 0;
  handle = 0;

  if (!pool)
    pool = gegl_id_pool_new (16);

  if (!g_str_has_prefix (uri, "buffer://"))
   {
     g_warning ("'%s' does not start like a valid buffer handle", uri);
     return NULL;
   }
  if (g_str_has_prefix (uri, "buffer:////"))
   {
     /* local buffer */
     handle = atoi (uri + 11);
     g_print ("got %i, %p\n", handle, gegl_id_pool_lookup (pool, handle));
     return gegl_buffer_create_sub_buffer (gegl_id_pool_lookup (pool, handle), NULL);
   }
  g_warning ("don't know how to handle buffer path: %s", uri);
  return NULL;
}
TEST ()
{
  GeglBuffer    *buffer, *sub, *subsub;
  GeglRectangle  subrect =    {5, 5, 10, 10};
  GeglRectangle  rect =       {0, 0, 20, 20};
  test_start ();
  buffer = gegl_buffer_new (&rect, babl_format ("Y float"));

  sub = gegl_buffer_create_sub_buffer (buffer, &subrect);
  fill (sub, 0.5);
  subsub = g_object_new (GEGL_TYPE_BUFFER,
                         "source", sub,
                         "x", 3,
                         "y", 3,
                         "width", 4,
                         "height", 4,
                         "shift-x", 6,
                         "shift-y", 6,
                         NULL);

  fill (subsub, 0.2);
  print_buffer (buffer);
  gegl_buffer_destroy (sub);
  gegl_buffer_destroy (subsub);
  gegl_buffer_destroy (buffer);
  test_end ();
}
Example #8
0
void rectangle (GeglBuffer *buffer,
                gint        x,
                gint        y,
                gint        width,
                gint        height,
                gfloat      value)
{
  GeglBuffer *sub_buf;
  GeglRectangle rect={x,y,width,height};

  sub_buf = gegl_buffer_create_sub_buffer (buffer, &rect);
  fill (sub_buf, value);
  g_object_unref (sub_buf);
}
TEST ()
{
  GeglBuffer   *buffer;
  GeglBuffer   *sub;
  GeglRectangle extent = {0,0,20,20};
  GeglRectangle sextent = {2,2,20,20};
  GeglRectangle roi = {5,5,10,10};
  test_start();
  buffer = gegl_buffer_new (&extent, babl_format ("Y float"));
  sub = gegl_buffer_create_sub_buffer (buffer, &sextent);
  fill_rect (sub, &roi, 0.5);
  print_buffer (buffer);
  g_object_unref (sub);
  g_object_unref (buffer);
  test_end ();
}
Example #10
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result)
{
  GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);
  GeglBuffer   *temp_in;
  GeglRectangle compute = gegl_operation_get_required_for_output (operation, "input", result);

  temp_in = gegl_buffer_create_sub_buffer (input, &compute);

  kuwahara (temp_in, output, o->radius);
  g_object_unref (temp_in);

  return  TRUE;
}
Example #11
0
static gboolean
gegl_crop_process (GeglOperation        *operation,
                   GeglOperationContext *context,
                   const gchar          *output_prop,
                   const GeglRectangle  *result,
                   gint                  level)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);
  GeglBuffer     *input;
  gboolean        success = FALSE;
  GeglRectangle   extent;

  extent.x      = o->x;
  extent.y      = o->y;
  extent.width  = o->width;
  extent.height = o->height;

  input = gegl_operation_context_get_source (context, "input");

  if (input)
    {
      GeglBuffer *output = gegl_buffer_create_sub_buffer (input, &extent);

      if (gegl_object_get_has_forked (G_OBJECT (input)))
        gegl_object_set_has_forked (G_OBJECT (output));

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

      g_object_unref (input);
      success = TRUE;
    }
  else
    {
      g_warning ("%s got NULL input pad", gegl_node_get_operation (operation->node));
    }

  return success;
}
Example #12
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         const GeglRectangle *result)
{
  GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);
  GeglBuffer   *source;
  SDL_Surface **sdl_outwin = NULL;      /*op_sym (op, "sdl_outwin");*/

  init_sdl ();
  if (!handle)
    handle = g_timeout_add (500, idle, NULL);

  if (!o->screen ||
       o->width  != result->width ||
       o->height != result->height)
    {
      if (sdl_outwin)
        {
          if (o->screen)
            {
              SDL_FreeSurface (o->screen);
              o->screen = NULL;
            }

          o->screen = SDL_CreateRGBSurface (SDL_SWSURFACE,
                                            result->width, result->height, 32, 0xff0000,
                                            0x00ff00, 0x0000ff, 0x000000);

          *sdl_outwin = o->screen;
          if (!o->screen)
            {
              fprintf (stderr, "CreateRGBSurface failed: %s\n",
                       SDL_GetError ());
              return -1;
            }
        }
      else
        {
          o->screen = SDL_SetVideoMode (result->width, result->height, 32, SDL_SWSURFACE);
          if (!o->screen)
            {
              fprintf (stderr, "Unable to set SDL mode: %s\n",
                       SDL_GetError ());
              return -1;
            }
        }
      o->width  = result->width ;
      o->height = result->height;
    }

  /*
   * There seems to be a valid faster path to the SDL desired display format
   * in B'G'R'A, perhaps babl should have been able to figure this out ito?
   *
   */
  source = gegl_buffer_create_sub_buffer (input, result);
  gegl_buffer_get (source,
       1.0,
       NULL,
       babl_format_new (babl_model ("RGBA"),
                        babl_type ("u8"),
                        babl_component ("B"),
                        babl_component ("G"),
                        babl_component ("R"),
                        babl_component ("A"),
                        NULL),
       ((SDL_Surface*)o->screen)->pixels, GEGL_AUTO_ROWSTRIDE);
  g_object_unref (source);

  if (!sdl_outwin)
    {
      SDL_UpdateRect (o->screen, 0, 0, 0, 0);
      SDL_WM_SetCaption (o->window_title, o->icon_title);
    }

  o->width = result->width ;
  o->height = result->height;

  return  TRUE;
}