예제 #1
0
static void
gimp_warp_tool_update_stroke (GimpWarpTool *wt,
                              GeglNode     *node)
{
  GeglPath *stroke;
  gdouble   size;

  gegl_node_get (node,
                 "stroke", &stroke,
                 "size",   &size,
                 NULL);

  if (stroke)
    {
      gdouble        min_x;
      gdouble        max_x;
      gdouble        min_y;
      gdouble        max_y;
      GeglRectangle  bbox;

      gegl_path_get_bounds (stroke, &min_x, &max_x, &min_y, &max_y);
      g_object_unref (stroke);

      bbox.x      = min_x - size * 0.5;
      bbox.y      = min_y - size * 0.5;
      bbox.width  = max_x - min_x + size;
      bbox.height = max_y - min_y + size;

      gimp_image_map_apply (wt->image_map, &bbox);
    }
}
예제 #2
0
void
gimp_gegl_mode_node_set_mode (GeglNode             *node,
                              GimpLayerModeEffects  mode,
                              gboolean              linear)
{
  const gchar *operation = "gimp:normal-mode";
  gdouble      opacity;

  g_return_if_fail (GEGL_IS_NODE (node));

  switch (mode)
    {
    case GIMP_NORMAL_MODE:        operation = "gimp:normal-mode"; break;
    case GIMP_DISSOLVE_MODE:      operation = "gimp:dissolve-mode"; break;
    case GIMP_BEHIND_MODE:        operation = "gimp:behind-mode"; break;
    case GIMP_MULTIPLY_MODE:      operation = "gimp:multiply-mode"; break;
    case GIMP_SCREEN_MODE:        operation = "gimp:screen-mode"; break;
    case GIMP_OVERLAY_MODE:       operation = "gimp:softlight-mode"; break;
    case GIMP_DIFFERENCE_MODE:    operation = "gimp:difference-mode"; break;
    case GIMP_ADDITION_MODE:      operation = "gimp:addition-mode"; break;
    case GIMP_SUBTRACT_MODE:      operation = "gimp:subtract-mode"; break;
    case GIMP_DARKEN_ONLY_MODE:   operation = "gimp:darken-only-mode"; break;
    case GIMP_LIGHTEN_ONLY_MODE:  operation = "gimp:lighten-only-mode"; break;
    case GIMP_HUE_MODE:           operation = "gimp:hue-mode"; break;
    case GIMP_SATURATION_MODE:    operation = "gimp:saturation-mode"; break;
    case GIMP_COLOR_MODE:         operation = "gimp:color-mode"; break;
    case GIMP_VALUE_MODE:         operation = "gimp:value-mode"; break;
    case GIMP_DIVIDE_MODE:        operation = "gimp:divide-mode"; break;
    case GIMP_DODGE_MODE:         operation = "gimp:dodge-mode"; break;
    case GIMP_BURN_MODE:          operation = "gimp:burn-mode"; break;
    case GIMP_HARDLIGHT_MODE:     operation = "gimp:hardlight-mode"; break;
    case GIMP_SOFTLIGHT_MODE:     operation = "gimp:softlight-mode"; break;
    case GIMP_GRAIN_EXTRACT_MODE: operation = "gimp:grain-extract-mode"; break;
    case GIMP_GRAIN_MERGE_MODE:   operation = "gimp:grain-merge-mode"; break;
    case GIMP_COLOR_ERASE_MODE:   operation = "gimp:color-erase-mode"; break;
    case GIMP_NEW_OVERLAY_MODE:   operation = "gimp:overlay-mode"; break;
    case GIMP_ERASE_MODE:         operation = "gimp:erase-mode"; break;
    case GIMP_REPLACE_MODE:       operation = "gimp:replace-mode"; break;
    case GIMP_ANTI_ERASE_MODE:    operation = "gimp:anti-erase-mode"; break;
    case GIMP_LCH_HUE_MODE:       operation = "gimp:lch-hue-mode"; break;
    case GIMP_LCH_CHROMA_MODE:    operation = "gimp:lch-chroma-mode"; break;
    case GIMP_LCH_COLOR_MODE:     operation = "gimp:lch-color-mode"; break;
    case GIMP_LCH_LIGHTNESS_MODE: operation = "gimp:lch-lightness-mode"; break;
    default:
      break;
    }

  gegl_node_get (node,
                 "opacity", &opacity,
                 NULL);

  /* setting the operation creates a new instance, so we have to set
   * all its properties
   */
  gegl_node_set (node,
                 "operation", operation,
                 "linear",    linear,
                 "opacity",   opacity,
                 NULL);
}
예제 #3
0
GeglBuffer *
gimp_applicator_get_cache_buffer (GimpApplicator  *applicator,
                                  GeglRectangle  **rectangles,
                                  gint            *n_rectangles)
{
  g_return_val_if_fail (GIMP_IS_APPLICATOR (applicator), NULL);
  g_return_val_if_fail (rectangles != NULL, NULL);
  g_return_val_if_fail (n_rectangles != NULL, NULL);

  if (applicator->output_cache_node)
    {
      GeglBuffer *cache;

      gegl_node_get (applicator->output_cache_node,
                     "cache", &cache,
                     NULL);

      if (cache)
        {
          if (gegl_buffer_list_valid_rectangles (cache, rectangles, n_rectangles))
            return cache;

          g_object_unref (cache);
        }
    }

  return NULL;
}
예제 #4
0
void
gimp_gegl_config_proxy_sync (GimpObject  *proxy,
                             GeglNode    *node)
{
  GParamSpec **pspecs;
  gchar       *operation;
  guint        n_pspecs;
  gint         i;

  g_return_if_fail (GIMP_IS_OBJECT (proxy));
  g_return_if_fail (GEGL_IS_NODE (node));

  gegl_node_get (node,
                 "operation", &operation,
                 NULL);

  g_return_if_fail (operation != NULL);

  pspecs = gegl_operation_list_properties (operation, &n_pspecs);
  g_free (operation);

  for (i = 0; i < n_pspecs; i++)
    {
      GParamSpec *gegl_pspec = pspecs[i];
      GParamSpec *gimp_pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (proxy),
                                                             gegl_pspec->name);

      if (gimp_pspec)
        {
          GValue value = { 0, };

          g_value_init (&value, gimp_pspec->value_type);

          g_object_get_property (G_OBJECT (proxy), gimp_pspec->name,
                                 &value);

          if (GEGL_IS_PARAM_SPEC_COLOR (gegl_pspec))
            {
              GimpRGB    gimp_color;
              GeglColor *gegl_color;

              gimp_value_get_rgb (&value, &gimp_color);
              g_value_unset (&value);

              gegl_color = gimp_gegl_color_new (&gimp_color);

              g_value_init (&value, gegl_pspec->value_type);
              g_value_take_object (&value, gegl_color);
            }

          gegl_node_set_property (node, gegl_pspec->name,
                                  &value);

          g_value_unset (&value);
        }
    }

  g_free (pspecs);
}
예제 #5
0
/* Loading a graph with X child nodes should result in
 * a GeglNode with X children, where the bottom-most node
 * is child 0.
 *
 * Note: Properties are not tested. */
static void
test_load_multiple_nodes (void)
{
    const gchar * const xml = \
"<?xml version='1.0' encoding='UTF-8'?>\n\
<gegl>\n\
  <node operation='gegl:invert-linear'>\n\
  </node>\n\
  <node operation='gegl:crop'>\n\
      <params>\n\
        <param name='x'>0</param>\n\
        <param name='y'>0</param>\n\
        <param name='width'>0</param>\n\
        <param name='height'>0</param>\n\
      </params>\n\
  </node>\n\
</gegl>\n";

    GeglNode *graph, *node;
	GSList *children;
    gchar *op_name;

    graph = gegl_node_new_from_xml(xml, "");
    g_assert(graph);

    children = gegl_node_get_children(graph);
    g_assert_cmpuint(g_slist_length(children), ==, 2);

    node = GEGL_NODE(g_slist_nth_data(children, 0));
    gegl_node_get(node, "operation", &op_name, NULL);
    g_assert_cmpstr(op_name, ==, "gegl:crop");
    g_free(op_name);

    node = GEGL_NODE(g_slist_nth_data(children, 1));
    gegl_node_get(node, "operation", &op_name, NULL);
    g_assert_cmpstr(op_name, ==, "gegl:invert-linear");
    g_free(op_name);

	g_slist_free(children);
    g_object_unref(graph);
}
예제 #6
0
파일: gimpcagetool.c 프로젝트: STRNG/gimp
static void
gimp_cage_tool_render_node_update (GimpCageTool *ct)
{
  GimpCageOptions *options  = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
  gboolean         option_fill, node_fill;
  GeglBuffer      *buffer;

  g_object_get (options,
                "fill-plain-color", &option_fill,
                NULL);

  gegl_node_get (ct->cage_node,
                 "fill-plain-color", &node_fill,
                 NULL);

  if (option_fill != node_fill)
    {
      gegl_node_set (ct->cage_node,
                     "fill_plain_color", option_fill,
                     NULL);
    }

  gegl_node_get (ct->coef_node,
                 "buffer", &buffer,
                 NULL);

  if (buffer != ct->coef)
    {
      gegl_node_set (ct->coef_node,
                     "buffer",  ct->coef,
                     NULL);
    }

  /* This just unref buffer, since gegl_node_get add a refcount on it */
  if (buffer)
    {
      g_object_unref (buffer);
    }
}
예제 #7
0
static gboolean
compare_values (GeglNode            *comparison,
                const CompareResult *expected_result)
{
  CompareResult actual_result;
  gint          test_result;
  /* Fetch all datas */
  gegl_node_get (comparison,
                 "max_diff",       &actual_result.max_diff,
                 "avg_diff_wrong", &actual_result.avg_diff_wrong,
                 "avg_diff_total", &actual_result.avg_diff_total,
                 "wrong_pixels",   &actual_result.wrong_pixels,
                 NULL);

  /* Check each value */
  test_result = SUCCESS;

  if (fabs (actual_result.max_diff - expected_result->max_diff)
      > GEGL_FLOAT_EPSILON)
    {
      g_printerr ("The max_diff property differs: %f instead of %f. ",
                  (gfloat) actual_result.max_diff,
                  (gfloat) expected_result->max_diff);
      test_result = FAILURE;
    }
  if (fabs (actual_result.avg_diff_wrong - expected_result->avg_diff_wrong)
      > GEGL_FLOAT_EPSILON)
    {
      g_printerr ("The avg_diff_wrong property differs: %f instead of %f. ",
                  (gfloat) actual_result.avg_diff_wrong,
                  (gfloat) expected_result->avg_diff_wrong);
      test_result = FAILURE;
    }
  if (fabs (actual_result.avg_diff_total - expected_result->avg_diff_total)
      > GEGL_FLOAT_EPSILON)
    {
      g_printerr ("The avg_diff_total property differs: %f instead of %f. ",
                  (gfloat) actual_result.avg_diff_total,
                  (gfloat) expected_result->avg_diff_total);
      test_result = FAILURE;
    }
  if (actual_result.wrong_pixels != expected_result->wrong_pixels)
    {
      g_printerr ("The wrong_pixels property differs: %d instead of %d. ",
                  actual_result.wrong_pixels,
                  expected_result->wrong_pixels);
      test_result = FAILURE;
    }

  return test_result;
}
예제 #8
0
파일: gimpwarptool.c 프로젝트: Anstep/gimp
static void
gimp_warp_tool_update_stroke (GimpWarpTool *wt,
                              GeglNode     *node)
{
  GeglPath *stroke;
  gdouble   size;

  gegl_node_get (node,
                 "stroke", &stroke,
                 "size",   &size,
                 NULL);

  if (stroke)
    {
      gdouble        min_x;
      gdouble        max_x;
      gdouble        min_y;
      gdouble        max_y;
      GeglRectangle  bbox;

      gegl_path_get_bounds (stroke, &min_x, &max_x, &min_y, &max_y);
      g_object_unref (stroke);

      bbox.x      = min_x - size * 0.5;
      bbox.y      = min_y - size * 0.5;
      bbox.width  = max_x - min_x + size;
      bbox.height = max_y - min_y + size;

#ifdef WARP_DEBUG
  g_printerr ("update stroke: (%d,%d), %dx%d\n",
              bbox.x, bbox.y,
              bbox.width, bbox.height);
#endif

      gimp_drawable_filter_apply (wt->filter, &bbox);
    }
}
예제 #9
0
GeglBuffer *
gimp_applicator_get_cache_buffer (GimpApplicator  *applicator,
                                  GeglRectangle  **rectangles,
                                  gint            *n_rectangles)
{
  if (applicator->cache_node)
    {
      GeglBuffer *cache;

      gegl_node_get (applicator->cache_node,
                     "cache", &cache,
                     NULL);

      if (cache)
        {
          if (gegl_buffer_list_valid_rectangles (cache, rectangles, n_rectangles))
            return cache;

          g_object_unref (cache);
        }
    }

  return NULL;
}
예제 #10
0
void
gimp_applicator_set_preview (GimpApplicator      *applicator,
                             gboolean             enable,
                             const GeglRectangle *rect)
{
  g_return_if_fail (GIMP_IS_APPLICATOR (applicator));
  g_return_if_fail (rect != NULL);

  if (! applicator->preview_cache_node)
    return;

  if (applicator->preview_enabled     != enable      ||
      applicator->preview_rect.x      != rect->x     ||
      applicator->preview_rect.y      != rect->y     ||
      applicator->preview_rect.width  != rect->width ||
      applicator->preview_rect.height != rect->height)
    {
      if (enable)
        {
          if (! applicator->preview_enabled)
            {
              gegl_node_set (applicator->preview_crop_node,
                             "operation", "gimp:compose-crop",
                             "x",         rect->x,
                             "y",         rect->y,
                             "width",     rect->width,
                             "height",    rect->height,
                             NULL);

              gegl_node_connect_to (applicator->input_node,        "output",
                                    applicator->preview_crop_node, "aux");
            }
          else
            {
              gegl_node_set (applicator->preview_crop_node,
                             "x",      rect->x,
                             "y",      rect->y,
                             "width",  rect->width,
                             "height", rect->height,
                             NULL);
            }
        }
      else if (applicator->preview_enabled)
        {
          GeglBuffer *cache;

          gegl_node_disconnect (applicator->preview_crop_node, "aux");
          gegl_node_set (applicator->preview_crop_node,
                         "operation", "gegl:nop",
                         NULL);

          /*  when disabling the preview, preserve the cached result
           *  by processing it into the output cache, which only
           *  involves the mode and affect nodes.
           */
          gegl_node_get (applicator->preview_cache_node,
                         "cache", &cache,
                         NULL);

          if (cache)
            {
              GeglRectangle *rectangles;
              gint           n_rectangles;

              if (gegl_buffer_list_valid_rectangles (cache, &rectangles,
                                                     &n_rectangles))
                {
                  gint i;

                  for (i = 0; i < n_rectangles; i++)
                    gegl_node_blit (applicator->output_cache_node, 1.0,
                                    &rectangles[i],
                                    NULL, NULL, 0, GEGL_BLIT_DEFAULT);

                  g_free (rectangles);
                }

              g_object_unref (cache);
            }
        }

      applicator->preview_enabled = enable;
      applicator->preview_rect    = *rect;
    }
}
예제 #11
0
void
gimp_image_map_tool_get_operation (GimpImageMapTool *image_map_tool)
{
  GimpImageMapToolClass *klass;
  gchar                 *operation_name;

  g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));

  klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);

  if (image_map_tool->image_map)
    {
      gimp_image_map_abort (image_map_tool->image_map);
      g_object_unref (image_map_tool->image_map);
      image_map_tool->image_map = NULL;
    }

  if (image_map_tool->operation)
    {
      g_object_unref (image_map_tool->operation);
      image_map_tool->operation = NULL;
    }

  if (image_map_tool->config)
    {
      g_signal_handlers_disconnect_by_func (image_map_tool->config,
                                            gimp_image_map_tool_config_notify,
                                            image_map_tool);

      g_object_unref (image_map_tool->config);
      image_map_tool->config = NULL;
    }

  if (image_map_tool->undo_desc)
    {
      g_free (image_map_tool->undo_desc);
      image_map_tool->undo_desc = NULL;
    }

  image_map_tool->operation = klass->get_operation (image_map_tool,
                                                    &image_map_tool->config,
                                                    &image_map_tool->undo_desc);

  if (! image_map_tool->undo_desc)
    image_map_tool->undo_desc =
      g_strdup (GIMP_TOOL (image_map_tool)->tool_info->blurb);

  gegl_node_get (image_map_tool->operation,
                 "operation", &operation_name,
                 NULL);

  if (operation_name &&
      gegl_operation_get_key (operation_name, "position-dependent"))
    {
      if (image_map_tool->region_combo)
        gtk_widget_show (image_map_tool->region_combo);
    }
  else
    {
      if (image_map_tool->region_combo)
        gtk_widget_show (image_map_tool->region_combo);

      g_object_set (GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (image_map_tool),
                    "region", GIMP_IMAGE_MAP_REGION_SELECTION,
                    NULL);
    }

  g_free (operation_name);

  if (image_map_tool->config)
    g_signal_connect_object (image_map_tool->config, "notify",
                             G_CALLBACK (gimp_image_map_tool_config_notify),
                             G_OBJECT (image_map_tool), 0);

  if (GIMP_TOOL (image_map_tool)->drawable)
    gimp_image_map_tool_create_map (image_map_tool);
}
예제 #12
0
gint
main (gint    argc,
      gchar **argv)
{
  GeglRectangle terrain_rect;
  if (argc < 2)
    usage();

  gegl_init (&argc, &argv);
  parse_args (argc, argv);

  gegl_decode = gegl_node_new ();

  store = gegl_node_new_child (gegl_decode,
                               "operation", "gegl:buffer-sink",
                               "buffer", &video_frame, NULL);
  load = gegl_node_new_child (gegl_decode,
                              "operation", "gegl:ff-load",
                              "frame", 0,
                              "path", video_path,
                              NULL);
  gegl_node_link_many (load, store, NULL);

  decode_frame_no (0); /* we issue a processing/decoding of a frame - to get metadata */
  {
    gegl_node_get (load, "frame-rate", &frame_rate, NULL);
    total_frames = 0; gegl_node_get (load, "frames", &total_frames, NULL);

    if (frame_end == 0)
      frame_end = total_frames;
  }

  if (horizontal)
   terrain_rect = (GeglRectangle){0, 0,
                                frame_end - frame_start + 1,
                                1024};
  else
   terrain_rect = (GeglRectangle){0, 0,
                                1024,
                                frame_end - frame_start + 1};

  if (input_analysis_path && g_file_test (input_analysis_path, G_FILE_TEST_IS_REGULAR))
  {
    GeglNode *load_graph = gegl_node_new ();
    GeglNode *load = gegl_node_new_child (load_graph, "operation", "gegl:load", "path", input_analysis_path, NULL);
    GeglNode *store = gegl_node_new_child (load_graph, "operation",
                                           "gegl:buffer-sink",
                                           "buffer", &terrain, NULL);
    gegl_node_link_many (load, store, NULL);
    gegl_node_process (store);
    g_object_unref (load_graph);

    frame_end = frame_start + gegl_buffer_get_extent (terrain)->height;
    /* the last frame aavilavle for analysis is the last one loaded rom cache,.. perhaps with some timeout */
  }
  else
  {
    terrain = gegl_buffer_new (&terrain_rect, babl_format ("RGBA u8"));
    {
      gint frame;
      gint max_buf_pos = 0;
      for (frame = frame_start; frame <= frame_end; frame++)
        {
          FrameInfo info = {{0}};
          uint8_t buffer[4096] = {0,};
          int buffer_pos = 0;
          GeglRectangle terrain_row;
          char *p = format;
          GString *word = g_string_new ("");

          if (show_progress)
          {
            double percent_full = 100.0 * (frame-frame_start) / (frame_end-frame_start);
            double percent_time = time_out?100.0 * babl_ticks()/1000.0/1000.0 / time_out:0.0;
            fprintf (stdout, "\r%2.1f%% %i/%i (%i)",
                     percent_full>percent_time?percent_full:percent_time,
                     frame-frame_start,
                     frame_end-frame_start,
                     frame);
            fflush (stdout);
          }

          if (horizontal)
            terrain_row = (GeglRectangle){frame-frame_start, 0, 1, 1024};
          else
            terrain_row = (GeglRectangle){0, frame-frame_start, 1024, 1};

          decode_frame_no (frame);

          //for (int i=0;i<(signed)sizeof(buffer);i++)buffer[i]=0;

          while (*p == ' ') p++;
          for (p= format;p==format || p[-1]!='\0';p++)
          {
            if (*p != '\0' && *p != ' ')
              {
                g_string_append_c (word, *p);
              }
            else
              {
               if (!strcmp (word->str, "histogram"))
               {
                 record_pix_stats (video_frame, previous_video_frame,
                                   &(info.rgb_hist[0]),
                                   &(info.rgb_square_diff)[0]);
                 for (int i = 0; i < NEGL_RGB_HIST_SLOTS; i++)
                 {
                  buffer[buffer_pos] = info.rgb_hist[i];
                  buffer_pos++;
                 }
                 for (int i = 0; i < 3; i++)
                 {
                   buffer[buffer_pos] = info.rgb_square_diff[i];
                   buffer_pos++;
                 }
               }
               else if (!strcmp (word->str, "mid-row"))
               {
                  int samples = NEGL_RGB_HEIGHT;
                  if (p[1] >= '0' && p[1] <= '9')
                  {
                    samples = g_strtod (&p[1], &p);
                  }
                  buffer_pos += extract_mid_row (video_frame, &(buffer)[buffer_pos], samples);
               }
               else if (!strcmp (word->str, "mid-col"))
               {
                  int samples = NEGL_RGB_HEIGHT;
                  if (p[1] >= '0' && p[1] <= '9')
                  {
                    samples = g_strtod (&p[1], &p);
                  }
                  buffer_pos += extract_mid_col (video_frame, &(buffer)[buffer_pos], samples);
               }
               else if (!strcmp (word->str, "thumb"))
               {
                  int samples  = NEGL_RGB_THEIGHT;
                  int samples2;

                  if (p[1] >= '0' && p[1] <= '9')
                  {
                    samples = g_strtod (&p[1], &p);
                  }

                  if (horizontal)
                    samples2 = samples * gegl_buffer_get_width (video_frame)/gegl_buffer_get_height(video_frame);
                  else
                    samples2 = samples * gegl_buffer_get_height (video_frame)/gegl_buffer_get_width(video_frame);

                  buffer_pos += extract_thumb (video_frame, &(buffer)[buffer_pos], samples, samples2);
               }
               else if (!strcmp (word->str, "audio"))
               {
                  int dups = 1;
                  GeglAudioFragment *audio = NULL;

                  if (p[1] >= '0' && p[1] <= '9')
                  {
                    dups = g_strtod (&p[1], &p);
                  }
                 gegl_node_get (load, "audio", &audio, NULL);
                 if (audio)
                  {
                    extract_audio_energy (audio, &buffer[buffer_pos], dups);
                    g_object_unref (audio);
                  }
                 buffer_pos+=3 * dups;
               }
               g_string_assign (word, "");
            }
          }
          max_buf_pos = buffer_pos;
          g_string_free (word, TRUE);

          gegl_buffer_set (terrain, &terrain_row, 0, babl_format("RGB u8"),
                           buffer,
                           GEGL_AUTO_ROWSTRIDE);

          if (time_out > 1.0 &&
              babl_ticks()/1000.0/1000.0 > time_out)
            {
               frame_end = frame;
               if (horizontal)
                 terrain_rect.width = frame_end - frame_start + 1;
               else
                 terrain_rect.height = frame_end - frame_start + 1;
          //     gegl_buffer_set_extent (terrain, &terrain_rect);
            }

          if (horizontal)
            terrain_rect.height = max_buf_pos/3;
          else
            terrain_rect.width = max_buf_pos/3;
          gegl_buffer_set_extent (terrain, &terrain_rect);
        }
        if (show_progress)
        {
          fprintf (stdout, "\n");
          fflush (stdout);
        }
    }

    if (output_analysis_path)
    {
      GeglNode *save_graph = gegl_node_new ();
      GeglNode *readbuf = gegl_node_new_child (save_graph, "operation", "gegl:buffer-source", "buffer", terrain, NULL);
      GeglNode *save = gegl_node_new_child (save_graph, "operation", "gegl:png-save",
        "path", output_analysis_path, NULL);
        gegl_node_link_many (readbuf, save, NULL);
      gegl_node_process (save);
      g_object_unref (save_graph);
    }
  }

  if (thumb_path)
  {
    GeglNode *save_graph = gegl_node_new ();
    find_best_thumb ();
    if (frame_thumb != 0)
      decode_frame_no (frame_thumb-1);
    decode_frame_no (frame_thumb);
    {
    GeglNode *readbuf = gegl_node_new_child (save_graph, "operation", "gegl:buffer-source", "buffer", video_frame, NULL);
    GeglNode *save = gegl_node_new_child (save_graph, "operation", "gegl:png-save",
      "path", thumb_path, NULL);
      gegl_node_link_many (readbuf, save, NULL);
    gegl_node_process (save);
    g_object_unref (save_graph);
    }
  }

  if (video_frame)
    g_object_unref (video_frame);
  video_frame = NULL;
  if (previous_video_frame)
    g_object_unref (previous_video_frame);
  previous_video_frame = NULL;
  if (terrain)
    g_object_unref (terrain);
  terrain = NULL;
  g_object_unref (gegl_decode);

  gegl_exit ();

  return 0;
}
예제 #13
0
gint
main (gint    argc,
      gchar **argv)
{
    GeglNode      *gegl, *imgA, *imgB, *comparison;
    GeglRectangle  boundsA, boundsB;
    gdouble        max_diff, avg_diff_wrong, avg_diff_total;
    gint           wrong_pixels, total_pixels;

    gegl_init (&argc, &argv);

    if (argc != 3)
    {
        g_print ("This is simple image difference detection tool for use in regression testing.\n"
                 "Exit code is non zero if images are different, if they are equal"
                 "the output will contain the string identical.\n");
        g_print ("Usage: %s <imageA> <imageB>\n", argv[0]);
        return ERROR_WRONG_ARGUMENTS;
    }

    gegl = gegl_node_new ();
    imgA = gegl_node_new_child (gegl,
                                "operation", "gegl:load",
                                "path", argv[1],
                                NULL);
    imgB = gegl_node_new_child (gegl,
                                "operation", "gegl:load",
                                "path", argv[2],
                                NULL);

    boundsA = gegl_node_get_bounding_box (imgA);
    boundsB = gegl_node_get_bounding_box (imgB);
    total_pixels = boundsA.width * boundsA.height;

    if (boundsA.width != boundsB.width || boundsA.height != boundsB.height)
    {
        g_printerr ("%s and %s differ in size\n", argv[1], argv[2]);
        g_printerr ("  %ix%i vs %ix%i\n",
                    boundsA.width, boundsA.height, boundsB.width, boundsB.height);
        return ERROR_WRONG_SIZE;
    }

    comparison = gegl_node_create_child (gegl, "gegl:image-compare");
    gegl_node_link (imgA, comparison);
    gegl_node_connect_to (imgB, "output", comparison, "aux");
    gegl_node_process (comparison);
    gegl_node_get (comparison,
                   "max diff", &max_diff,
                   "avg-diff-wrong", &avg_diff_wrong,
                   "avg-diff-total", &avg_diff_total,
                   "wrong-pixels", &wrong_pixels,
                   NULL);

    if (max_diff >= 0.1)
    {
        g_printerr ("%s and %s differ\n"
                    "  wrong pixels   : %i/%i (%2.2f%%)\n"
                    "  max Δe         : %2.3f\n"
                    "  avg Δe (wrong) : %2.3f(wrong) %2.3f(total)\n",
                    argv[1], argv[2],
                    wrong_pixels, total_pixels,
                    (wrong_pixels*100.0/total_pixels), max_diff,
                    avg_diff_wrong, avg_diff_total);

        if (!strstr (argv[2], "broken"))
        {
            GeglNode *save;
            gchar *debug_path = g_malloc (strlen (argv[2])+16);

            memcpy (debug_path, argv[2], strlen (argv[2])+1);
            memcpy (debug_path + strlen(argv[2])-4, "-diff.png", 11);

            save = gegl_node_new_child (gegl,
                                        "operation", "gegl:png-save",
                                        "path", debug_path,
                                        NULL);
            gegl_node_link (comparison, save);
            gegl_node_process (save);


            /*gegl_graph (sink=gegl_node ("gegl:png-save",
                                        "path", debug_path, NULL,
                                        gegl_node ("gegl:buffer-source", "buffer", debug_buf, NULL)));*/
            if (max_diff > 1.5)
                return ERROR_PIXELS_DIFFERENT;
        }
        if (strstr (argv[2], "broken"))
            g_print ("because the test is expected to fail ");
        else
            g_print ("because the error is small ");
        g_print ("we'll say ");
    }

    g_print ("%s and %s are identical\n", argv[1], argv[2]);

    g_object_unref (gegl);

    gegl_exit ();
    return SUCCESS;
}
예제 #14
0
static gboolean
gimp_image_map_tool_initialize (GimpTool     *tool,
                                GimpDisplay  *display,
                                GError      **error)
{
  GimpImageMapTool *im_tool   = GIMP_IMAGE_MAP_TOOL (tool);
  GimpToolInfo     *tool_info = tool->tool_info;
  GimpImage        *image     = gimp_display_get_image (display);
  GimpDrawable     *drawable  = gimp_image_get_active_drawable (image);
  GimpDisplayShell *shell     = gimp_display_get_shell (display);

  if (! drawable)
    return FALSE;

  if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
    {
      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
			   _("Cannot modify the pixels of layer groups."));
      return FALSE;
    }

  if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
    {
      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
			   _("The active layer's pixels are locked."));
      return FALSE;
    }

  if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
    {
      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
                           _("The active layer is not visible."));
      return FALSE;
    }

  if (im_tool->active_picker)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (im_tool->active_picker),
                                  FALSE);

  /*  set display so the dialog can be hidden on display destruction  */
  tool->display = display;

  if (im_tool->config)
    gimp_config_reset (GIMP_CONFIG (im_tool->config));

  if (! im_tool->gui)
    {
      GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (im_tool);
      GtkWidget             *vbox;
      GtkWidget             *hbox;
      GtkWidget             *toggle;
      gchar                 *operation_name;

      /*  disabled for at least GIMP 2.8  */
      im_tool->overlay = FALSE;

      im_tool->gui =
        gimp_tool_gui_new (tool_info,
                           im_tool->title,
                           im_tool->description,
                           im_tool->icon_name,
                           im_tool->help_id,
                           gtk_widget_get_screen (GTK_WIDGET (shell)),
                           gimp_widget_get_monitor (GTK_WIDGET (shell)),
                           im_tool->overlay,

                           GIMP_STOCK_RESET, RESPONSE_RESET,
                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                           GTK_STOCK_OK,     GTK_RESPONSE_OK,

                           NULL);

      gimp_tool_gui_set_default_response (im_tool->gui, GTK_RESPONSE_OK);

      gimp_tool_gui_set_alternative_button_order (im_tool->gui,
                                                  RESPONSE_RESET,
                                                  GTK_RESPONSE_OK,
                                                  GTK_RESPONSE_CANCEL,
                                                  -1);

      vbox = gimp_tool_gui_get_vbox (im_tool->gui);

      g_signal_connect_object (im_tool->gui, "response",
                               G_CALLBACK (gimp_image_map_tool_response),
                               G_OBJECT (im_tool), 0);

      if (im_tool->config && klass->settings_name)
        {
          GType          type = G_TYPE_FROM_INSTANCE (im_tool->config);
          GimpContainer *settings;
          GFile         *settings_file;
          GFile         *default_folder;
          GtkWidget     *settings_ui;

          settings = gimp_gegl_config_get_container (type);
          if (! gimp_list_get_sort_func (GIMP_LIST (settings)))
            gimp_list_set_sort_func (GIMP_LIST (settings),
                                     (GCompareFunc) gimp_settings_compare);

          settings_file = gimp_tool_info_get_options_file (tool_info,
                                                           ".settings");
          default_folder = gimp_directory_file (klass->settings_name, NULL);

          settings_ui = klass->get_settings_ui (im_tool,
                                                settings,
                                                settings_file,
                                                klass->import_dialog_title,
                                                klass->export_dialog_title,
                                                im_tool->help_id,
                                                default_folder,
                                                &im_tool->settings_box);

          g_object_unref (default_folder);
          g_object_unref (settings_file);

          gtk_box_pack_start (GTK_BOX (vbox), settings_ui, FALSE, FALSE, 0);
          gtk_widget_show (settings_ui);
        }

      /*  The gamma hack toggle  */
      toggle = gtk_check_button_new_with_label ("Gamma hack (temp hack, please ignore)");
      gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
      gtk_widget_show (toggle);

      g_signal_connect (toggle, "toggled",
                        G_CALLBACK (gamma_hack),
                        im_tool);

      /*  The preview and split view toggles  */
      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
      gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
      gtk_widget_show (hbox);

      toggle = gimp_prop_check_button_new (G_OBJECT (tool_info->tool_options),
                                           "preview", NULL);
      gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
      gtk_widget_show (toggle);

      toggle = gimp_prop_check_button_new (G_OBJECT (tool_info->tool_options),
                                           "preview-split", NULL);
      gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
      gtk_widget_show (toggle);

      g_object_bind_property (G_OBJECT (tool_info->tool_options), "preview",
                              toggle,                             "sensitive",
                              G_BINDING_SYNC_CREATE);

      /*  The area combo  */
      gegl_node_get (im_tool->operation,
                     "operation", &operation_name,
                     NULL);

      im_tool->region_combo =
        gimp_prop_enum_combo_box_new (G_OBJECT (tool_info->tool_options),
                                      "region",
                                      0, 0);
      gtk_box_pack_end (GTK_BOX (vbox), im_tool->region_combo,
                        FALSE, FALSE, 0);

      if (operation_name &&
          gegl_operation_get_key (operation_name, "position-dependent"))
        {
          gtk_widget_show (im_tool->region_combo);
        }

      g_free (operation_name);

      /*  Fill in subclass widgets  */
      gimp_image_map_tool_dialog (im_tool);
    }
  else
    {
      gimp_tool_gui_set_title (im_tool->gui, im_tool->title);
      gimp_tool_gui_set_description (im_tool->gui, im_tool->description);
      gimp_tool_gui_set_icon_name (im_tool->gui, im_tool->icon_name);
      gimp_tool_gui_set_help_id (im_tool->gui, im_tool->help_id);
    }

  gimp_tool_gui_set_shell (im_tool->gui, shell);
  gimp_tool_gui_set_viewable (im_tool->gui, GIMP_VIEWABLE (drawable));

  gimp_tool_gui_show (im_tool->gui);

  im_tool->drawable = drawable;
  gimp_image_map_tool_create_map (im_tool);

  gimp_image_map_tool_preview (im_tool);

  return TRUE;
}
예제 #15
0
gint layer_node_selected (gpointer host, GeglEditor* editor, gint node_id)
{
  GeglEditorLayer*	self = (GeglEditorLayer*)host;
  GeglNode*		node = NULL;
  GSList*		pair = self->pairs;
  for(;pair != NULL; pair = pair->next)
    {
      node_id_pair*	data = pair->data;
      if(data->id == node_id)
	{
	  node = data->node;
	  break;
	}
    }

  g_assert(node != NULL);

  GeglNode** nodes;
  const gchar** pads;
  gint num = gegl_node_get_consumers(node, "output", &nodes, &pads);

  int i;
  g_print("%s: %d consumer(s)\n", gegl_node_get_operation(node), num);
  for(i = 0; i < num; i++)
    {
      g_print("Connection: (%s to %s)\n", gegl_node_get_operation(node), gegl_node_get_operation(nodes[0]), pads[0]);
    }
  g_print("Input from: %s\n", gegl_node_get_operation(gegl_node_get_producer(node, "input", NULL)));

  //  g_print("selected: %s\n", gegl_node_get_operation(node));

  guint		n_props;
  GParamSpec**	properties = gegl_operation_list_properties(gegl_node_get_operation(node), &n_props);

  //TODO: only create enough columns for the properties which will actually be included (i.e. ignoring GeglBuffer props)
  GtkTable	*prop_table = GTK_TABLE(gtk_table_new(2, n_props, FALSE));

  int d;
  for(d = 0, i = 0; i < n_props; i++, d++)
    {
      GParamSpec*	prop = properties[i];
      GType		type = prop->value_type;
      const gchar*		name = prop->name;

      GtkWidget*	name_label = gtk_label_new(name);
      gtk_misc_set_alignment(GTK_MISC(name_label), 0, 0.5);


      GtkWidget*	value_entry = gtk_entry_new();

      gchar buf[256] = "*";	//can probably be smaller; In fact, can probably do this without sprintf and a buffer. TODO: look at g_string

      gint	i_value;
      gdouble	d_value;
      gchar*	str_value;
      gboolean skip = FALSE;

      switch(type)
	{
	case G_TYPE_INT:
	  gegl_node_get(node, name, &i_value, NULL);
	  sprintf(buf, "%d", i_value);
	  break;
	case G_TYPE_DOUBLE:
	  gegl_node_get(node, name, &d_value, NULL);
	  sprintf(buf, "%.3f", d_value);
	  break;
	case G_TYPE_STRING:
	  gegl_node_get(node, name, &str_value, NULL);
	  sprintf(buf, "%s", str_value);
	  break;
	}

      if(type == GEGL_TYPE_BUFFER) {
	skip = TRUE;
	d--;
      } else if( type == GEGL_TYPE_COLOR) {
	skip = TRUE;
	GtkWidget *color_button = gtk_button_new_with_label("Select");

	select_color_info* info = malloc(sizeof(select_color_info));
	info->node = node;
	info->property = name;
	info->layer = self;

	g_signal_connect(color_button, "clicked", (GCallback)select_color, info);

	gtk_table_attach(prop_table, name_label, 0, 1, d, d+1, GTK_FILL, GTK_FILL, 1, 1);
	gtk_table_attach(prop_table, color_button, 1, 2, d, d+1, GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 1, 1);
      }

      if(!skip)
	{
	  gtk_entry_set_text(GTK_ENTRY(value_entry), buf);

	  gtk_entry_set_width_chars(GTK_ENTRY(value_entry), 2);
	  struct text_prop_data	*data = malloc(sizeof(struct text_prop_data));	//TODO store this in a list and free it when the node is deselected
	  data->node		      = node;
	  data->property		      = name;
	  data->prop_type		      = type;
	  data->layer		      = self;
	  g_signal_connect(value_entry, "activate", G_CALLBACK(text_property_changed), data);

	  gtk_table_attach(prop_table, name_label, 0, 1, d, d+1, GTK_FILL, GTK_FILL, 1, 1);
	  gtk_table_attach(prop_table, value_entry, 1, 2, d, d+1, GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 1, 1);
	}
    }

  //  gegl_node_process(node);
  GeglGtkView *gtk_view = gegl_gtk_view_new_for_node(node);

  GeglRectangle rect = gegl_node_get_bounding_box(node);

  if(gegl_rectangle_is_infinite_plane(&rect))
    {
      gegl_gtk_view_set_autoscale_policy(gtk_view, GEGL_GTK_VIEW_AUTOSCALE_DISABLED);
      gegl_gtk_view_set_scale(gtk_view, 1.0);
      g_print("Disable autoscale: scale=%f, x=%f, y=%f\n", gegl_gtk_view_get_scale(gtk_view),
      gegl_gtk_view_get_x(gtk_view), gegl_gtk_view_get_y(gtk_view));
    }

  gtk_widget_show(GTK_WIDGET(gtk_view));

  //TODO: draw checkerboard under preview to indicate transparency

  gtk_box_pack_start(GTK_BOX(self->prop_box), GTK_WIDGET(prop_table), FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->prop_box), GTK_WIDGET(gtk_view), TRUE, TRUE, 10);

  GtkWidget* label = gtk_label_new("Click the image\nto open in a\nnew window");
  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
  gtk_box_pack_start(GTK_BOX(self->prop_box), label, FALSE, TRUE, 10);

  gtk_widget_show_all(self->prop_box);
}
예제 #16
0
static gboolean
test_operation (const gchar *op_name,
                const gchar *image,
                gchar       *output_path)
{
  gchar         *ref_path;
  GeglNode      *img, *ref_img, *gegl;
  GeglRectangle  ref_bounds, comp_bounds;
  gint           ref_pixels;
  gboolean       result = TRUE;

  gegl = gegl_node_new ();

  ref_path = g_build_path (G_DIR_SEPARATOR_S, reference_dir, image, NULL);
  ref_img = gegl_node_new_child (gegl,
                                 "operation", "gegl:load",
                                 "path", ref_path,
                                 NULL);
  g_free (ref_path);

  img = gegl_node_new_child (gegl,
                             "operation", "gegl:load",
                             "path", output_path,
                             NULL);

  ref_bounds  = gegl_node_get_bounding_box (ref_img);
  comp_bounds = gegl_node_get_bounding_box (img);
  ref_pixels  = ref_bounds.width * ref_bounds.height;

  if (ref_bounds.width != comp_bounds.width ||
      ref_bounds.height != comp_bounds.height)
    {
      g_printf ("FAIL\n  Reference and composition differ in size\n");
      result = FALSE;
    }
  else
    {
      GeglNode *comparison;
      gdouble   max_diff;

      comparison = gegl_node_create_child (gegl, "gegl:image-compare");
      gegl_node_link (img, comparison);
      gegl_node_connect_to (ref_img, "output", comparison, "aux");
      gegl_node_process (comparison);
      gegl_node_get (comparison, "max diff", &max_diff, NULL);

      if (max_diff < 1.0)
        {
          g_printf ("PASS\n");
          result = TRUE;
        }
      else
        {
          GeglNode *output;
          gchar    *diff_path;
          gdouble   avg_diff_wrong, avg_diff_total;
          gint      wrong_pixels;

          gegl_node_get (comparison, "avg_diff_wrong", &avg_diff_wrong,
                         "avg_diff_total", &avg_diff_total, "wrong_pixels",
                         &wrong_pixels, NULL);

          g_printf ("FAIL\n  Reference image and composition differ\n"
                    "    wrong pixels : %i/%i (%2.2f%%)\n"
                    "    max Δe       : %2.3f\n"
                    "    avg Δe       : %2.3f (wrong) %2.3f (total)\n",
                    wrong_pixels, ref_pixels,
                    (wrong_pixels * 100.0 / ref_pixels),
                    max_diff, avg_diff_wrong, avg_diff_total);

          diff_path = operation_to_path (op_name, TRUE);
          output = gegl_node_new_child (gegl,
                                        "operation", "gegl:png-save",
                                        "path", diff_path,
                                        NULL);
          gegl_node_link (comparison, output);
          gegl_node_process (output);

          g_free (diff_path);

          result = FALSE;
        }
    }

  g_object_unref (gegl);
  return result;
}
static void
gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
                                     GimpDisplay               *display)
{
  GimpTool                     *tool = GIMP_TOOL (npd_tool);
  GimpNPointDeformationOptions *npd_options;
  GimpImage                    *image;
  GeglBuffer                   *source_buffer;
  GeglBuffer                   *preview_buffer;
  NPDModel                     *model;

  npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);

  gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);

  image = gimp_display_get_image (display);

  tool->display  = display;
  tool->drawable = gimp_image_get_active_drawable (image);

  npd_tool->active = TRUE;

  /* create GEGL graph */
  source_buffer  = gimp_drawable_get_buffer (tool->drawable);

  preview_buffer = gegl_buffer_new (gegl_buffer_get_extent (source_buffer),
                                    babl_format ("cairo-ARGB32"));

  npd_tool->graph    = gegl_node_new ();

  npd_tool->source   = gegl_node_new_child (npd_tool->graph,
                                            "operation", "gegl:buffer-source",
                                            "buffer",    source_buffer,
                                            NULL);
  npd_tool->npd_node = gegl_node_new_child (npd_tool->graph,
                                            "operation", "gegl:npd",
                                            NULL);
  npd_tool->sink     = gegl_node_new_child (npd_tool->graph,
                                            "operation", "gegl:write-buffer",
                                            "buffer",    preview_buffer,
                                            NULL);

  gegl_node_link_many (npd_tool->source,
                       npd_tool->npd_node,
                       npd_tool->sink,
                       NULL);

  /* initialize some options */
  g_object_set (G_OBJECT (npd_options), "mesh-visible", TRUE, NULL);
  gimp_n_point_deformation_options_set_sensitivity (npd_options, TRUE);

  /* compute and get model */
  gegl_node_process (npd_tool->npd_node);
  gegl_node_get (npd_tool->npd_node, "model", &model, NULL);

  npd_tool->model          = model;
  npd_tool->preview_buffer = preview_buffer;
  npd_tool->selected_cp    = NULL;
  npd_tool->hovering_cp    = NULL;
  npd_tool->selected_cps   = NULL;
  npd_tool->rubber_band    = FALSE;
  npd_tool->lattice_points = g_new (GimpVector2,
                                    5 * model->hidden_model->num_of_bones);

  gimp_item_get_offset (GIMP_ITEM (tool->drawable),
                        &npd_tool->offset_x, &npd_tool->offset_y);
  gimp_npd_debug (("offset: %f %f\n", npd_tool->offset_x, npd_tool->offset_y));

  gimp_draw_tool_start (GIMP_DRAW_TOOL (npd_tool), display);

  gimp_n_point_deformation_tool_perform_deformation (npd_tool);

  /* hide original image */
  gimp_item_set_visible (GIMP_ITEM (tool->drawable), FALSE, FALSE);
  gimp_image_flush (image);

  /* create and start a deformation thread */
  npd_tool->deform_thread =
    g_thread_new ("deform thread",
                  (GThreadFunc) gimp_n_point_deformation_tool_deform_thread_func,
                  npd_tool);

  /* create and start canvas update timeout */
  npd_tool->draw_timeout_id =
    gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
                                  GIMP_NPD_DRAW_INTERVAL,
                                  (GSourceFunc) gimp_n_point_deformation_tool_canvas_update_timeout,
                                  npd_tool,
                                  NULL);
}
예제 #18
0
int main(int argc, char *argv[])
{
  int           result = SUCCESS;
  GeglNode     *graph  = NULL;
  GeglNode     *node   = NULL;
  GeglColor    *color  = NULL;
  double        x      = -5;
  double        y      = -5;
  char         *name   = NULL;
  gboolean      cache  = TRUE;

  /* Init */
  gegl_init (&argc, &argv);

  color = gegl_color_new ("rgb(0.0, 1.0, 0.0)");

  graph = gegl_node_new ();
  node  = gegl_node_new_child (graph,
                               "operation", "gegl:color",
                               "value",     color,
                               NULL);

  gegl_node_get (node, "operation", &name, NULL);
  
  if (!(!strcmp (name, "gegl:color")))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      goto abort;
    }

  gegl_node_set (node,
                 "operation", "gegl:translate",
                 "x", 50.0,
                 "y", 100.0,
                 NULL);
  
  gegl_node_get (node,
                 "operation", &name,
                 "x", &x,
                 "y", &y,
                 NULL);

  if (!(!strcmp (name, "gegl:translate") &&
        (int)x == 50 && (int)y == 100))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      printf ("x, y: %f, %f\n", x, y);
      goto abort;
    }

  gegl_node_set (node,
                 "x", 5.0,
                 "y", 10.0,
                 NULL);
  
  gegl_node_get (node,
                 "y", &y,
                 "operation", &name,
                 "x", &x,
                 NULL);
  
  if (!(!strcmp (name, "gegl:translate") &&
        (int)x == 5 && (int)y == 10))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      printf ("x, y: %f, %f\n", x, y);
      goto abort;
    }

  gegl_node_set (node,
                 "operation", "gegl:doesnt-exist",
                 NULL);

  gegl_node_get (node, "operation", &name, NULL);
  
  if (!(!strcmp (name, "gegl:nop")))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      goto abort;
    }
  
  gegl_node_set (node,
                 "operation", "gegl:nop",
                 NULL);

  gegl_node_get (node, "operation", &name, NULL);
  
  if (!(!strcmp (name, "gegl:nop")))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      goto abort;
    }



  gegl_node_set (node,
                 "operation", "gegl:translate",
                 NULL);
  
  gegl_node_get (node,
                 "operation", &name,
                 "x", &x,
                 "y", &y,
                 NULL);

  if (!(!strcmp (name, "gegl:translate") &&
        (int)x == 0 && (int)y == 0))
    {
      result = FAILURE;
      printf ("operation: %s\n", name); 
      printf ("x, y: %f, %f\n", x, y);
      goto abort;
    }
  
  gegl_node_set (node,
                 "operation", "gegl:translate",
                 "name", "Brian",
                 "dont-cache", FALSE,
                 NULL);
  
  gegl_node_get (node,
                 "name", &name,
                 "dont-cache", &cache,
                 NULL);

  if (!(!strcmp (name, "Brian") &&
        cache == FALSE))
    {
      result = FAILURE;
      printf ("name:  %s\n", name);
      printf ("cache: %d\n", cache); 
      goto abort;
    }

  gegl_node_set (node,
                 "dont-cache", TRUE,
                 "name", "Steve",
                 NULL);

  gegl_node_get (node,
                 "name", &name,
                 "dont-cache", &cache,
                 NULL);

  if (!(!strcmp (name, "Steve") &&
        cache == TRUE))
    {
      result = FAILURE;
      printf ("name: %s\n", name);
      printf ("cache: %d\n", cache);
      goto abort;
    }

abort:
  /* Cleanup */
  g_object_unref (graph);
  g_object_unref (color);
  gegl_exit ();

  return result;
}
예제 #19
0
static GeglBuffer *
gradient_precalc_shapeburst (GimpImage           *image,
                             GimpDrawable        *drawable,
                             const GeglRectangle *region,
                             gdouble              dist,
                             GimpProgress        *progress)
{
  GimpChannel *mask;
  GeglBuffer  *dist_buffer;
  GeglBuffer  *temp_buffer;
  GeglNode    *shapeburst;
  gdouble      max;
  gfloat       max_iteration;

  gimp_progress_set_text (progress, _("Calculating distance map"));

  /*  allocate the distance map  */
  dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
                                                 region->width, region->height),
                                 babl_format ("Y float"));

  /*  allocate the selection mask copy
   *  XXX: its format should be the same of gimp:shapeburst input buffer
   *       porting the op to 'float' should be reflected here as well
   */
  temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
                                                 region->width, region->height),
                                 babl_format ("Y u8"));

  mask = gimp_image_get_mask (image);

  /*  If the image mask is not empty, use it as the shape burst source  */
  if (! gimp_channel_is_empty (mask))
    {
      gint x, y, width, height;
      gint off_x, off_y;

      gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height);
      gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);

      /*  copy the mask to the temp mask  */
      gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)),
                        GEGL_RECTANGLE (x + off_x, y + off_y, width, height),
                        temp_buffer,
                        GEGL_RECTANGLE (0, 0, 0, 0));
    }
  else
    {
      /*  If the intended drawable has an alpha channel, use that  */
      if (gimp_drawable_has_alpha (drawable))
        {
          const Babl *component_format;

          component_format = babl_format ("A u8");

          /*  extract the aplha into the temp mask  */
          gegl_buffer_set_format (temp_buffer, component_format);
          gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
                            GEGL_RECTANGLE (region->x, region->y,
                                            region->width, region->height),
                            temp_buffer,
                            GEGL_RECTANGLE (0, 0, 0, 0));
          gegl_buffer_set_format (temp_buffer, NULL);
        }
      else
        {
          GeglColor *white = gegl_color_new ("white");

          /*  Otherwise, just fill the shapeburst to white  */
          gegl_buffer_set_color (temp_buffer, NULL, white);
          g_object_unref (white);
        }
    }

  shapeburst = gegl_node_new_child (NULL,
                                    "operation", "gimp:shapeburst",
                                    NULL);

  gimp_gegl_progress_connect (shapeburst, progress, NULL);

  gimp_gegl_apply_operation (temp_buffer, NULL, NULL,
                             shapeburst,
                             dist_buffer, NULL);

  gegl_node_get (shapeburst, "max-iterations", &max, NULL);

  g_object_unref (shapeburst);

  max_iteration = max;

  g_object_unref (temp_buffer);

  /*  normalize the shapeburst with the max iteration  */
  if (max_iteration > 0)
    {
      GeglBufferIterator *iter;

      iter = gegl_buffer_iterator_new (dist_buffer, NULL, 0, NULL,
                                       GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);

      while (gegl_buffer_iterator_next (iter))
        {
          gint    count = iter->length;
          gfloat *data  = iter->data[0];

          while (count--)
            *data++ /= max_iteration;
        }
    }

  return dist_buffer;
}
예제 #20
0
gint
main (gint argc,
      gchar **argv)
{
  
  if (argv[1])
  {
    input_path = argv[1];
    if (argv[2])
      output_path = argv[2];
  }


  gegl_init (&argc, &argv);

  gegl_dec  = gegl_node_new ();
  decode = gegl_node_new_child (gegl_dec, "operation", "gegl:ff-load", "path", input_path, NULL);
  store_buf = gegl_node_new_child (gegl_dec, "operation", "gegl:buffer-sink", "buffer", &buffer, NULL);
  gegl_node_link_many (decode, store_buf, NULL);
  
  gegl_enc = gegl_node_new ();
  load_buf = gegl_node_new_child (gegl_enc, "operation", "gegl:buffer-source", NULL);
  invert = gegl_node_new_child (gegl_enc,   "operation", "gegl:gray", NULL);
  encode = gegl_node_new_child (gegl_dec,   "operation", "gegl:ff-save", "path", output_path, NULL);

  gegl_node_link_many (load_buf, invert, /*invert2, invert3,*/ encode, NULL);

  {
    gint frame_no;
    gint frame_count = 100;
    gint audio_sample_rate = 44100;
    gint audio_channels = 0;

    for (frame_no = 0; frame_no < frame_count; frame_no++)
    {
      GeglAudioFragment *audio;
      fprintf (stderr, "\r%i/%i", frame_no, frame_count);
      gegl_node_set (decode, "frame", frame_no, NULL);
      if (buffer){
        g_object_unref (buffer);
        buffer = NULL;
      }
      gegl_node_process (store_buf);
      if (buffer)
      {
        if (frame_no == 0)
        {
          gegl_node_get (decode, "frame-rate", &fps, 
                                 "frames", &frame_count, 
                                 "audio-sample-rate", &audio_sample_rate, 
                                 "audio-channels", &audio_channels,
                                 NULL);
          fprintf (stderr, "frame-rate: %f\n", fps);
          gegl_node_set (encode, "frame-rate", fps, NULL);
        }
        gegl_node_get (decode, "audio", &audio, NULL);
        gegl_node_set (encode, "audio", audio, NULL);
        gegl_node_set (load_buf, "buffer", buffer, NULL);
        gegl_node_process (encode);
      }
    }
  }
  fprintf (stderr, "\n");
  g_object_unref (gegl_enc);
  g_object_unref (gegl_dec);
  g_object_unref (buffer);

  gegl_exit ();
  return 0;
}