예제 #1
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;
}
예제 #2
0
파일: n_components.c 프로젝트: GNOME/babl
static int
test (void)
{
  int   components;
  int   OK = 1;

  for (components = 1; components < 2048; components ++)
  {
    const Babl *fish;
    const Babl *src_fmt;
    const Babl *dst_fmt;
    int   i;

    src_fmt = babl_format_n (babl_type ("float"), components);
    dst_fmt = babl_format_n (babl_type ("u8"), components);

    fish = babl_fish (src_fmt, dst_fmt);

    babl_process (fish, source_buf, destination_buf, PIXELS);

    for (i = 0; i < PIXELS * components; i++)
      {
        if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
          {
            babl_log ("%i-components, pixel %i component %i is %i should be %i",
                      components, i / components, i % components, destination_buf[i], reference_buf[i]);
            OK = 0;
          }
      }
  }
  if (!OK)
    return -1;
  return 0;
}
예제 #3
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    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);
    }
}
예제 #4
0
static void
load_buffer (GeglProperties *op_raw_load)
{
  if (!op_raw_load->user_data)
    {
      FILE  *pfp;
      gchar *command;
      gint   width, height, val_max;
      gchar  newline;

      command = g_strdup_printf ("dcraw -4 -c '%s'\n", op_raw_load->path);
      pfp = popen (command, PIPE_MODE);
      g_free (command);

      if (fscanf (pfp, "P6 %d %d %d %c",
         &width, &height, &val_max, &newline) != 4)
        {
          pclose (pfp);
          g_warning ("not able to aquire raw data");
          return;
        }

        {
          GeglRectangle extent = { 0, 0, 0, 0 };
          extent.width = width;
          extent.height = height;
          op_raw_load->user_data = (gpointer) gegl_buffer_new (&extent,
                                                   babl_format_new (
                                                     babl_model ("RGB"),
                                                     babl_type ("u16"),
                                                     babl_component ("G"),
                                                     babl_component ("B"),
                                                     babl_component ("R"),
                                                     NULL));
        }
         {

           guint16 *buf = g_new (guint16, width * height * 3);
           fread (buf, 1, width * height * 3 * 2, pfp);
           gegl_buffer_set (GEGL_BUFFER (op_raw_load->user_data),
                            NULL,
                            0,
                            babl_format_new (
                                        babl_model ("RGB"),
                                        babl_type ("u16"),
                                        babl_component ("G"),
                                        babl_component ("B"),
                                        babl_component ("R"),
                                        NULL),
                            buf,
                            GEGL_AUTO_ROWSTRIDE
                           );
           g_free (buf);
         }
       fclose (pfp);
    }
}
예제 #5
0
static void
gimp_operation_cage_transform_prepare (GeglOperation *operation)
{
  GimpOperationCageTransform *oct    = GIMP_OPERATION_CAGE_TRANSFORM (operation);
  GimpCageConfig             *config = GIMP_CAGE_CONFIG (oct->config);

  gegl_operation_set_format (operation, "input",
                             babl_format_n (babl_type ("float"),
                                            2 * gimp_cage_config_get_n_points (config)));
  gegl_operation_set_format (operation, "output",
                             babl_format_n (babl_type ("float"), 2));
}
예제 #6
0
MyPaintGeglTiledSurface *
mypaint_gegl_tiled_surface_new(void)
{
    MyPaintGeglTiledSurface *self = (MyPaintGeglTiledSurface *)malloc(sizeof(MyPaintGeglTiledSurface));

    mypaint_tiled_surface_init(&self->parent, tile_request_start, tile_request_end);

    // MyPaintSurface vfuncs
    self->parent.parent.destroy = free_gegl_tiledsurf;
    self->parent.parent.save_png = save_png;

    self->parent.threadsafe_tile_requests = TRUE;

    self->buffer = NULL;

    gegl_rectangle_set(&self->extent_rect, 0, 0, 0, 0);

    self->format = babl_format_new(babl_model ("R'aG'aB'aA"), babl_type ("u15"),
                             babl_component("R'a"), babl_component("G'a"), babl_component("B'a"), babl_component("A"),
                             NULL);
    g_assert(self->format);

    mypaint_gegl_tiled_surface_set_buffer(self, NULL);

    return self;
}
예제 #7
0
static int
test_buffer_cast (void)
{
  gint result = SUCCESS;
  GeglBuffer *buffer = gegl_buffer_new (GEGL_RECTANGLE (0,0,1,1),
                                         babl_format ("R'G'B'A u8"));
  GeglBuffer *cbuffer = gegl_buffer_new (GEGL_RECTANGLE (0,0,1,1),
                                         babl_format ("Y u8"));
  guchar srcpix[4] = {1,2,3,4};
  guchar dstpix[4] = {0};

  gegl_buffer_set (buffer, NULL, 0, NULL, srcpix, GEGL_AUTO_ROWSTRIDE);

  gegl_buffer_set_format (cbuffer, 
       babl_format_new ("name", "B' u8",
                          babl_model ("R'G'B'A"),
                          babl_type ("u8"),
                          babl_component ("B'"),
                          NULL));
  gegl_buffer_copy (buffer, NULL, cbuffer, NULL);
  gegl_buffer_set_format (cbuffer, NULL);

  gegl_buffer_get (cbuffer, NULL, 1.0, NULL,
      dstpix, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

  if (dstpix[0] != 3)
    result = FAILURE;
  
  g_object_unref (buffer);
  g_object_unref (cbuffer);
  return result;
}
예제 #8
0
파일: gimpcagetool.c 프로젝트: STRNG/gimp
static void
gimp_cage_tool_compute_coef (GimpCageTool *ct)
{
  GimpCageConfig *config = ct->config;
  GimpProgress   *progress;
  const Babl     *format;
  GeglNode       *gegl;
  GeglNode       *input;
  GeglNode       *output;
  GeglProcessor  *processor;
  GeglBuffer     *buffer;
  gdouble         value;

  progress = gimp_progress_start (GIMP_PROGRESS (ct),
                                  _("Computing Cage Coefficients"), FALSE);

  if (ct->coef)
    {
      g_object_unref (ct->coef);
      ct->coef = NULL;
    }

  format = babl_format_n (babl_type ("float"),
                          gimp_cage_config_get_n_points (config) * 2);


  gegl = gegl_node_new ();

  input = gegl_node_new_child (gegl,
                               "operation", "gimp:cage-coef-calc",
                               "config",    ct->config,
                               NULL);

  output = gegl_node_new_child (gegl,
                                "operation", "gegl:buffer-sink",
                                "buffer",    &buffer,
                                "format",    format,
                                NULL);

  gegl_node_connect_to (input, "output",
                        output, "input");

  processor = gegl_node_new_processor (output, NULL);

  while (gegl_processor_work (processor, &value))
    {
      if (progress)
        gimp_progress_set_value (progress, value);
    }

  if (progress)
    gimp_progress_end (progress);

  g_object_unref (processor);

  ct->coef = buffer;
  g_object_unref (gegl);

  ct->dirty_coef = FALSE;
}
예제 #9
0
static void
gimp_warp_tool_start (GimpWarpTool *wt,
                      GimpDisplay  *display)
{
  GimpTool      *tool     = GIMP_TOOL (wt);
  GimpImage     *image    = gimp_display_get_image (display);
  GimpDrawable  *drawable = gimp_image_get_active_drawable (image);
  const Babl    *format;
  GeglRectangle  bbox;

  tool->display  = display;
  tool->drawable = drawable;

  /* Create the coords buffer, with the size of the selection */
  format = babl_format_n (babl_type ("float"), 2);

  gimp_item_mask_intersect (GIMP_ITEM (drawable), &bbox.x, &bbox.y,
                            &bbox.width, &bbox.height);

#ifdef WARP_DEBUG
  g_printerr ("Initialize coordinate buffer (%d,%d) at %d,%d\n",
              bbox.width, bbox.height, bbox.x, bbox.y);
#endif

  wt->coords_buffer = gegl_buffer_new (&bbox, format);

  gimp_warp_tool_create_image_map (wt, drawable);

  if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (wt)))
    gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display);
}
예제 #10
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         const GeglRectangle *result,
         gint                 level)
{
  GeglChantO   *o = GEGL_CHANT_PROPERTIES (operation);
  SDLState     *state = NULL;

  if(!o->chant_data)
      o->chant_data = g_new0 (SDLState, 1);
  state = o->chant_data;

  init_sdl ();

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

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

      state->width  = result->width ;
      state->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?
   *
   */
  gegl_buffer_get (input,
       NULL,
       1.0,
       babl_format_new (babl_model ("R'G'B'A"),
                        babl_type ("u8"),
                        babl_component ("B'"),
                        babl_component ("G'"),
                        babl_component ("R'"),
                        babl_component ("A"),
                        NULL),
       state->screen->pixels, GEGL_AUTO_ROWSTRIDE,
       GEGL_ABYSS_NONE);

  SDL_UpdateRect (state->screen, 0, 0, 0, 0);
  SDL_WM_SetCaption (o->window_title, o->icon_title);

  state->width = result->width ;
  state->height = result->height;

  return  TRUE;
}
예제 #11
0
static void
prepare (GeglOperation *operation)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);
  const Babl *src_format   = gegl_operation_get_source_format (operation, "input");
  const Babl *input_format = babl_format ("RGB double");
  gint        n_components = 3;
  const Babl *output_format;

  if (src_format)
    {
      const Babl *model = babl_format_get_model (src_format);

      if (model == babl_model ("RGB") || model == babl_model ("R'G'B'") ||
          model == babl_model ("RGBA") || model == babl_model ("R'G'B'A"))
        {
          input_format = babl_format ("RGB double");
          n_components = 3;
        }
      else if (model == babl_model ("Y") || model == babl_model ("Y'") ||
               model == babl_model ("YA") || model == babl_model ("Y'A"))
        {
          input_format = babl_format ("Y double");
          n_components = 1;
        }
    }

  if (o->squared)
    n_components *= 2;

  output_format = babl_format_n (babl_type ("double"), n_components);

  gegl_operation_set_format (operation, "input", input_format);
  gegl_operation_set_format (operation, "output", output_format);
}
예제 #12
0
파일: two-table.c 프로젝트: Distrotech/babl
int
init (void)
{
  int   testint  = 23;
  char *testchar = (char*) &testint;
  int   littleendian = (testchar[0] == 23);

  if (littleendian)
    {
      const Babl *f24 = babl_format_new (
        "name", "cairo-RGB24",
        babl_model ("R'G'B'"),
        babl_type ("u8"),
        babl_component ("B'"),
        babl_component ("G'"),
        babl_component ("R'"),
        babl_component ("PAD"),
        NULL
      );

      babl_conversion_new (babl_format ("RGB float"),
                           f24,
                           "linear",
                           conv_rgbfloat_linear_cairo24_le,
                           NULL);

      babl_conversion_new (babl_format ("RGBA float"),
                           f24,
                           "linear",
                           conv_rgbafloat_linear_cairo24_le,
                           NULL);
    }

  babl_conversion_new (babl_format ("RGBA float"),
                       babl_format ("R'G'B' u8"),
                       "linear",
                       conv_rgbafloat_linear_rgbu8_gamma,
                       NULL);

  babl_conversion_new (babl_format ("RGB float"),
                       babl_format ("R'G'B' u8"),
                       "linear",
                       conv_rgbfloat_linear_rgbu8_gamma,
                       NULL);

  babl_conversion_new (babl_format ("Y float"),
                       babl_format ("Y' u8"),
                       "linear",
                       conv_yfloat_linear_yu8_gamma,
                       NULL);

  babl_conversion_new (babl_format ("YA float"),
                       babl_format ("Y'A u8"),
                       "linear",
                       conv_yafloat_linear_yau8_gamma,
                       NULL);

  return 0;
}
예제 #13
0
static void
prepare (GeglOperation *operation)
{
  const Babl *format = babl_format ("RGBA float");

  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "aux", babl_format_n (babl_type ("float"), 2));
  gegl_operation_set_format (operation, "output", format);
}
예제 #14
0
static void
init_path_instrumentation (FishPathInstrumentation *fpi,
                           Babl                    *fmt_source,
                           Babl                    *fmt_destination)
{
  long   ticks_start = 0;
  long   ticks_end   = 0;

  if (!fpi->fmt_rgba_double)
    {
      fpi->fmt_rgba_double = babl_format_new (
        babl_model ("RGBA"),
        babl_type ("double"),
        babl_component ("R"),
        babl_component ("G"),
        babl_component ("B"),
        babl_component ("A"),
        NULL);
    }

  if (!fpi->test)
    fpi->test = test_create (); // <- test_create utiliza var static dentro de la función

  fpi->fish_rgba_to_source      = babl_fish_reference (fpi->fmt_rgba_double,
                                                  fmt_source);
  fpi->fish_reference           = babl_fish_reference (fmt_source,
                                                  fmt_destination);
  fpi->fish_destination_to_rgba = babl_fish_reference (fmt_destination,
                                                  fpi->fmt_rgba_double);

  fpi->source                      = babl_calloc (NUM_TEST_PIXELS,
                                             fmt_source->format.bytes_per_pixel);
  fpi->destination                 = babl_calloc (NUM_TEST_PIXELS,
                                             fmt_destination->format.bytes_per_pixel);
  fpi->ref_destination             = babl_calloc (NUM_TEST_PIXELS,
                                             fmt_destination->format.bytes_per_pixel);
  fpi->destination_rgba_double     = babl_calloc (NUM_TEST_PIXELS,
                                             fpi->fmt_rgba_double->format.bytes_per_pixel);
  fpi->ref_destination_rgba_double = babl_calloc (NUM_TEST_PIXELS,
                                             fpi->fmt_rgba_double->format.bytes_per_pixel);

  /* create sourcebuffer from testbuffer in the correct format */
  babl_process (fpi->fish_rgba_to_source,
                fpi->test, fpi->source, NUM_TEST_PIXELS);

  /* calculate the reference buffer of how it should be */
  ticks_start = babl_ticks ();
  babl_process (fpi->fish_reference,
                fpi->source, fpi->ref_destination, NUM_TEST_PIXELS);
  ticks_end = babl_ticks ();
  fpi->reference_cost = babl_process_cost (ticks_start, ticks_end);

  /* transform the reference destination buffer to RGBA */
  babl_process (fpi->fish_destination_to_rgba,
                fpi->ref_destination, fpi->ref_destination_rgba_double, NUM_TEST_PIXELS);
}
예제 #15
0
파일: rawbayer-load.c 프로젝트: GNOME/gegl
static void
load_buffer (GeglProperties *op_raw_load)
{
  if (!op_raw_load->user_data)
    {
      FILE  *pfp;
      gchar *command;

      gint width, height, val_max;
      char newline;

      command = g_strdup_printf ("dcraw -j -d -4 -c '%s'\n", op_raw_load->path);
      pfp = popen (command, PIPE_MODE);
      g_free (command);

      if (fscanf (pfp, "P6 %d %d %d %c",
                  &width, &height, &val_max, &newline) != 4)
        {
          pclose (pfp);
          g_warning ("not able to aquire raw data");
          return;
        }

      {
        GeglRectangle extent = { 0, 0, width, height };
        op_raw_load->user_data = (void*)gegl_buffer_new (&extent, babl_format ("Y u16"));
      }
         {
           guchar *buf = g_new (guchar, width * height * 3 * 2);
           fread (buf, 1, width * height * 3 * 2, pfp);
           if(strstr (op_raw_load->path, "rawbayerS")){
             gint i;
             for (i=0;i<width*height*3;i++)
               {
                guchar tmp = buf[i*2];
                buf[i*2] = buf[i*2+1];
                buf[i*2+1] = tmp;
               }
           }
           gegl_buffer_set (GEGL_BUFFER (op_raw_load->user_data),
                            NULL,
                            0,
                            babl_format_new (
                                 babl_model ("RGB"),
                                 babl_type ("u16"),
                                 babl_component ("R"),
                                 babl_component ("G"),
                                 babl_component ("B"),
                                 NULL),
                            buf,
                            GEGL_AUTO_ROWSTRIDE);
           g_free (buf);
         }
       fclose (pfp);
    }
}
예제 #16
0
static int
test (void)
{
  const Babl *fish;
  int   i;
  int   OK = 1;


  fish = babl_fish (
    babl_format_new (
      babl_model ("Y"),
      babl_type ("float"),
      babl_component ("Y"),
      NULL
    ),
    babl_format_new (
      babl_model ("RGB"),
      babl_type ("float"),
      babl_component ("R"),
      babl_component ("G"),
      babl_component ("B"),
      NULL
    )
         );

  babl_process (fish,
                grayscale_buf, rgb_buf,
                PIXELS);

  for (i = 0; i < PIXELS * 3; i++)
    {
      if (rgb_buf[i] != rgb_buf_ref[i])
        {
          babl_log ("index %i is problematic : %f instead of %f",
                    i, rgb_buf[i], rgb_buf_ref[i]);
          OK = 0;
        }
    }
  if (!OK)
    return -1;
  return 0;
}
예제 #17
0
static void
gimp_operation_cage_coef_calc_prepare (GeglOperation *operation)
{
  GimpOperationCageCoefCalc *occc   = GIMP_OPERATION_CAGE_COEF_CALC (operation);
  GimpCageConfig            *config = GIMP_CAGE_CONFIG (occc->config);

  gegl_operation_set_format (operation,
                             "output",
                             babl_format_n (babl_type ("float"),
                                            2 * gimp_cage_config_get_n_points (config)));
}
static void
gimp_operation_scalar_multiply_prepare (GeglOperation *operation)
{
  GimpOperationScalarMultiply *self = GIMP_OPERATION_SCALAR_MULTIPLY (operation);
  const Babl                  *format;

  format = babl_format_n (babl_type ("float"), self->n_components);

  gegl_operation_set_format (operation, "input",  format);
  gegl_operation_set_format (operation, "output", format);
}
예제 #19
0
파일: CIE.c 프로젝트: Distrotech/babl
static void
types_u16 (void)
{
  babl_type_new (
    "CIE u16 L",
    "integer",
    "unsigned",
    "bits", 16,
    "min_val", 0.0,
    "max_val", 100.0,
    NULL
  );

  babl_type_new (
    "CIE u16 ab",
    "id", "CIE u8 ab",
    "integer",
    "unsigned",
    "bits", 16,
    "min_val", -128.0,
    "max_val", 127.0,
    NULL
  );


  babl_conversion_new (
    babl_type ("CIE u16 L"),
    babl_type ("double"),
    "plane", convert_u16_l_double,
    NULL
  );
  babl_conversion_new (
    babl_type ("double"),
    babl_type ("CIE u16 L"),
    "plane", convert_double_u16_l,
    NULL
  );

  babl_conversion_new (
    babl_type ("CIE u16 ab"),
    babl_type ("double"),
    "plane", convert_u16_ab_double,
    NULL
  );
  babl_conversion_new (
    babl_type ("double"),
    babl_type ("CIE u16 ab"),
    "plane", convert_double_u16_ab,
    NULL
  );
}
예제 #20
0
파일: rgb_to_bgr.c 프로젝트: GNOME/babl
static int
test (void)
{
  const Babl *fish;
  int   i;
  int   OK = 1;

  fish = babl_fish (
    babl_format_new (
      babl_model ("RGB"),
      babl_type ("u8"),
      babl_component ("R"),
      babl_component ("G"),
      babl_component ("B"),
      NULL
    ),
    babl_format_new (
      babl_model ("RGB"),
      babl_type ("u8"),
      babl_component ("B"),
      babl_component ("G"),
      babl_component ("R"),
      NULL
    )
         );

  babl_process (fish, source_buf, destination_buf, PIXELS);

  for (i = 0; i < PIXELS * 3; i++)
    {
      if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
        {
          babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
                    i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
          OK = 0;
        }
    }
  if (!OK)
    return -1;
  return 0;
}
예제 #21
0
static void
prepare (GeglOperation *operation)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);

  const Babl *format = babl_format_n (babl_type ("float"), 2);
  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "output", format);

  if (!o->user_data)
    o->user_data = g_slice_new0 (WarpPrivate);
}
예제 #22
0
파일: ycbcr.c 프로젝트: GNOME/babl
static void
formats (void)
{
  babl_format_new (
    babl_model ("Y'CbCrA709"),
    babl_type ("float"),
    babl_component ("Y'"),
    babl_type ("float"),
    babl_component ("Cb"),
    babl_component ("Cr"),
    babl_component ("alpha"),
    NULL);

  babl_format_new (
    babl_model ("Y'CbCr709"),
    babl_type ("float"),
    babl_component ("Y'"),
    babl_type ("float"),
    babl_component ("Cb"),
    babl_component ("Cr"),
    NULL);
}
예제 #23
0
GimpPrecision
gimp_babl_format_get_precision (const Babl *format)
{
  const Babl *type;

  g_return_val_if_fail (format != NULL, -1);

  type = babl_format_get_type (format, 0);

  if (type == babl_type ("u8"))
    return GIMP_PRECISION_U8;
  else if (type == babl_type ("u16"))
    return GIMP_PRECISION_U16;
  else if (type == babl_type ("u32"))
    return GIMP_PRECISION_U32;
  else if (type == babl_type ("half"))
    return GIMP_PRECISION_HALF;
  else if (type == babl_type ("float"))
    return GIMP_PRECISION_FLOAT;

  g_return_val_if_reached (-1);
}
예제 #24
0
파일: HSV.c 프로젝트: GNOME/babl
static void
formats (void)
{
  babl_format_new (
    "name", "HSVA float",
    babl_model ("HSVA"),
    babl_type ("float"),
    babl_component ("hue"),
    babl_component ("saturation"),
    babl_component ("value"),
    babl_component ("alpha"),
    NULL
  );

  babl_format_new (
    "name", "HSV float",
    babl_model ("HSV"),
    babl_type ("float"),
    babl_component ("hue"),
    babl_component ("saturation"),
    babl_component ("value"),
    NULL
  );
}
예제 #25
0
static gboolean
operation_source_process (GeglOperation       *operation,
                          GeglBuffer          *output,
                          const GeglRectangle *result,
                          gint                 level)
{
  const Babl *out_format = gegl_operation_get_format (operation, "output");

  if ((result->width > 0) && (result->height > 0))
    {
      GeglBufferIterator *iter;
      if (gegl_operation_use_opencl (operation) &&
          babl_format_get_n_components (out_format) == 4 &&
          babl_format_get_type (out_format, 0) == babl_type ("float"))
        {
          GeglBufferClIterator *cl_iter;
          gboolean err;

          GEGL_NOTE (GEGL_DEBUG_OPENCL, "GEGL_OPERATION_POINT_RENDER: %s", GEGL_OPERATION_GET_CLASS (operation)->name);

          cl_iter = gegl_buffer_cl_iterator_new (output, result, out_format, GEGL_CL_BUFFER_WRITE);

          while (gegl_buffer_cl_iterator_next (cl_iter, &err) && !err)
            {
              err = checkerboard_cl_process (operation, cl_iter->tex[0], cl_iter->size[0], &cl_iter->roi[0], level);

              if (err)
                {
                  gegl_buffer_cl_iterator_stop (cl_iter);
                  break;
                }
            }

          if (err)
            GEGL_NOTE (GEGL_DEBUG_OPENCL, "Error: %s", GEGL_OPERATION_GET_CLASS (operation)->name);
          else
            return TRUE;
        }

      iter = gegl_buffer_iterator_new (output, result, level, out_format,
                                       GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);

      while (gegl_buffer_iterator_next (iter))
        checkerboard_process (operation, iter->data[0], iter->length, &iter->roi[0], level);
    }
  return TRUE;
}
예제 #26
0
static void
copy_one_component (GeglBuffer      *src,
                    GeglBuffer      *dst,
                    const gchar     *model,
                    const COMPONENT  component,
                    gboolean         clamp)
{
  const Babl *component_format, *dst_format;
  GeglBuffer *temp;
  const GeglRectangle *extent;

  /* We are working in linear double precison*/
  component_format = babl_format_new (babl_model (model),
                                      babl_type ("double"),
                                      babl_component (component.babl_name),
                                      NULL);

  /* We need to enforce linearity here
   * If the output is "Y'", the ouput of temp is already ok
   * If the output is "Y" , it will enforce gamma-decoding.
   * A bit tricky and suboptimal...
   */
  if (component.perceptual_channel)
    dst_format = babl_format ("Y' double");
  else
    dst_format = babl_format ("Y double");

  extent = gegl_buffer_get_extent (src);
  temp = gegl_buffer_new (extent, dst_format);

  /* we want to copy the component as is */
  gegl_buffer_set_format (temp, component_format);
  gegl_buffer_copy (src, NULL, temp, NULL);

  if (component.range_min != 0.0 || component.range_max != 1.0 || clamp)
    cpn_affine_transform_clamp (temp, component.range_min, component.range_max);

  /* This is our new "Y(') double" component buffer */
  gegl_buffer_set_format (temp, NULL);

  /* Now we let babl convert it back to the format that dst needs */
  gegl_buffer_copy (temp, NULL, dst, NULL);

  g_object_unref (temp);
}
예제 #27
0
파일: palette.c 프로젝트: snapr-org/babl
int
main (int    argc,
      char **argv)
{
    int OK = 1;
    babl_init ();
    OK = ! babl_format_is_palette (babl_format_n (babl_type ("double"), 3));
    if(1) {
        unsigned char in[][1]   = {{        0},{          1},{          2},{15}};
        unsigned char out[][4]  = {{0,0,0,255},{127,0,0,255},{0,127,0,255},{255,255,255,255}};
        const Babl *palA;// = babl_new_palette (NULL, 0);
        //Babl *palB = babl_new_palette (NULL, 0);
        //
        babl_new_palette (NULL, &palA, NULL);
        assert (palA);

        CHECK_CONV("pal to rgba", unsigned char,
                   palA, babl_format("RGBA u8"),
                   in, out);
    }
예제 #28
0
파일: warp.c 프로젝트: AjayRamanathan/gegl
static void
prepare (GeglOperation *operation)
{
  GeglChantO  *o = GEGL_CHANT_PROPERTIES (operation);
  WarpPrivate *priv;

  const Babl *format = babl_format_n (babl_type ("float"), 2);
  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "output", format);

  if (!o->chant_data)
    {
      o->chant_data = g_slice_new (WarpPrivate);
    }

  priv = (WarpPrivate*) o->chant_data;
  priv->last_point_set = FALSE;
  priv->lookup = NULL;
  priv->buffer = NULL;
}
예제 #29
0
static void
gimp_warp_tool_start (GimpWarpTool *wt,
                      GimpDisplay  *display)
{
  GimpTool        *tool     = GIMP_TOOL (wt);
  GimpWarpOptions *options  = GIMP_WARP_TOOL_GET_OPTIONS (wt);
  GimpImage       *image    = gimp_display_get_image (display);
  GimpDrawable    *drawable = gimp_image_get_active_drawable (image);
  const Babl      *format;
  GeglRectangle    bbox;

  tool->display  = display;
  tool->drawable = drawable;

  /* Create the coords buffer, with the size of the selection */
  format = babl_format_n (babl_type ("float"), 2);

  gimp_item_mask_intersect (GIMP_ITEM (drawable), &bbox.x, &bbox.y,
                            &bbox.width, &bbox.height);

#ifdef WARP_DEBUG
  g_printerr ("Initialize coordinate buffer (%d,%d) at %d,%d\n",
              bbox.width, bbox.height, bbox.x, bbox.y);
#endif

  wt->coords_buffer = gegl_buffer_new (&bbox, format);

  gimp_warp_tool_create_image_map (wt, drawable);

  if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (wt)))
    gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display);

  if (options->animate_button)
    {
      g_signal_connect_swapped (options->animate_button, "clicked",
                                G_CALLBACK (gimp_warp_tool_animate),
                                wt);

      gtk_widget_set_sensitive (options->animate_button, TRUE);
    }
}
예제 #30
0
파일: babl-palette.c 프로젝트: GNOME/babl
const Babl *
babl_new_palette_with_space (const char  *name,
                             const Babl  *space,
                             const Babl **format_u8,
                             const Babl **format_u8_with_alpha)
{
  const Babl *model;
  const Babl *model_no_alpha;
  Babl *f_pal_u8;
  Babl *f_pal_a_u8;
  const Babl *component;
  const Babl *alpha;
  BablPalette **palptr;

  char  cname[64];

  if (!space)
    space = babl_space ("sRGB");

  if (!name)
    {
      static int cnt = 0;
      snprintf (cname, sizeof (cname), "_babl-int-%i", cnt++);
      name = cname;
    }
  else
    {
      snprintf (cname, sizeof (cname), "%s-%p", name, space);
      name = cname;

      if ((model = babl_db_exist_by_name (babl_model_db (), name)))
        {
          cname[0] = ')';
          if (format_u8)
            *format_u8 = babl_db_exist_by_name (babl_format_db (), name);
          cname[0] = '\\';
          if (format_u8_with_alpha)
            *format_u8_with_alpha = babl_db_exist_by_name (babl_format_db (), name);
          return model;
        }
    }

  /* re-registering is a no-op */
  component = babl_component_new (
    "I",
    "luma",
    "chroma",
    NULL);
  alpha = babl_component ("A");
  model = babl_model_new ("name", name, component, alpha, NULL);
  palptr = malloc (sizeof (void*));
  *palptr = default_palette ();;
  cname[0] = 'v';
  model_no_alpha = babl_model_new ("name", name, component, NULL);
  cname[0] = '\\';
  f_pal_a_u8 = (void*) babl_format_new ("name", name, model, space,
                                babl_type ("u8"),
                                component, alpha, NULL);
  cname[0] = ')';
  f_pal_u8  = (void*) babl_format_new ("name", name, model_no_alpha, space,
                               babl_type ("u8"),
                               component, NULL);

  f_pal_a_u8->format.palette = 1;
  f_pal_u8->format.palette = 1;

  babl_conversion_new (
     model,
     babl_model ("RGBA"),
     "linear", pala_to_rgba,
     "data", palptr,
     NULL
  );

  babl_conversion_new (
     babl_model ("RGBA"),
     model,
     "linear", rgba_to_pala,
     "data", palptr,
     NULL
  );

  babl_conversion_new (
     model_no_alpha,
     babl_model ("RGBA"),
     "linear", pal_to_rgba,
     "data", palptr,
     NULL
  );
  babl_conversion_new (
     babl_model ("RGBA"),
     model_no_alpha,
     "linear", rgba_to_pal,
     "data", palptr,
     NULL
  );
  babl_conversion_new (
     f_pal_u8,
     f_pal_a_u8,
     "linear", conv_pal8_pala8,
     NULL
  );
  babl_conversion_new (
     f_pal_a_u8,
     f_pal_u8,
     "linear", conv_pala8_pal8,
     NULL
  );
  babl_conversion_new (
     f_pal_u8,
     babl_format ("R'G'B'A u8"),
     "linear", pal_u8_to_rgba_u8,
     "data", palptr,
     NULL);
  babl_conversion_new (
     f_pal_a_u8,
     babl_format ("R'G'B'A u8"),
     "linear", pala_u8_to_rgba_u8,
     "data", palptr,
     NULL);

  babl_conversion_new (
     babl_format ("R'G'B'A u8"),
     f_pal_a_u8,
     "linear", rgba_u8_to_pal_a,
     "data", palptr,
     NULL);
  babl_conversion_new (
     babl_format ("R'G'B'A u8"),
     f_pal_u8,
     "linear", rgba_u8_to_pal,
     "data", palptr,
     NULL);

  babl_conversion_new (
     babl_format ("RGBA float"),
     f_pal_a_u8,
     "linear", rgba_float_to_pal_a,
     "data", palptr,
     NULL);
  babl_conversion_new (
     babl_format ("RGBA float"),
     f_pal_u8,
     "linear", rgba_float_to_pal,
     "data", palptr,
     NULL);

  babl_set_user_data (model, palptr);
  babl_set_user_data (model_no_alpha, palptr);

  if (format_u8)
    *format_u8 = f_pal_u8;
  if (format_u8_with_alpha)
    *format_u8_with_alpha = f_pal_a_u8;
  babl_sanity ();
  return model;
}