Пример #1
0
static void
rotate_counterclockwise_90(GwyContainer *data, GwyRunType run)
{
    GwyDataField *dfields[3], *newfield;
    GQuark quarks[3];
    gint i, id;

    g_return_if_fail(run & BASICOPS_RUN_MODES);
    gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, dfields + 0,
                                     GWY_APP_MASK_FIELD, dfields + 1,
                                     GWY_APP_SHOW_FIELD, dfields + 2,
                                     GWY_APP_DATA_FIELD_KEY, quarks + 0,
                                     GWY_APP_MASK_FIELD_KEY, quarks + 1,
                                     GWY_APP_SHOW_FIELD_KEY, quarks + 2,
                                     GWY_APP_DATA_FIELD_ID, &id,
                                     0);
    clean_quarks(G_N_ELEMENTS(quarks), quarks, dfields);
    gwy_app_undo_qcheckpointv(data, G_N_ELEMENTS(quarks), quarks);
    for (i = 0; i < G_N_ELEMENTS(dfields); i++) {
        if (dfields[i]) {
            newfield = gwy_data_field_new_alike(dfields[i], FALSE);
            flip_xy(dfields[i], newfield, TRUE);
            gwy_container_set_object(data, quarks[i], newfield);
            g_object_unref(newfield);
        }
    }
    gwy_app_data_clear_selections(data, id);
    gwy_app_channel_log_add_proc(data, id, id);
}
Пример #2
0
variable flux_buffer_flip(opts o,interpreter *i)
{
	variable v=init_variable();
	int b=0;
	int x=0;
	int y=0;
	if (i->cast_int(&b,o,0) && i->cast_int(&x,o,1) && i->cast_int(&y,o,2))
	{
		flip_xy(b,x,y);
	}
	return v;
}
Пример #3
0
void
APITests::testBasicOperations(int width, int height) {
  const PixelFormat format = PF_R8G8B8A8;
  const int bpp = 4;

  auto_ptr<Image> image(CreateImage(width, height, format));
  CPPUNIT_ASSERT(image->getWidth()  == width);
  CPPUNIT_ASSERT(image->getHeight() == height);
  CPPUNIT_ASSERT(image->getFormat() == format);

  // verify that the image is black
  byte* pixels = (byte*)image->getPixels();
  for (int i = 0; i < width * height * bpp; ++i) {
    CPPUNIT_ASSERT(pixels[i] == 0);
  }

  // fill the image with random pixels
  for (int i = 0; i < width * height * bpp; ++i) {
    pixels[i] = rand() % 256;
  }

  auto_ptr<Image> create_clone(
      CreateImage(image->getWidth(), image->getHeight(),
                  image->getFormat(), image->getPixels()));
  CPPUNIT_ASSERT(create_clone.get() != 0);
  CPPUNIT_ASSERT(image->getWidth()  == create_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == create_clone->getHeight());
  CPPUNIT_ASSERT(image->getFormat() == create_clone->getFormat());
  CPPUNIT_ASSERT(memcmp(image->getPixels(),
                        create_clone->getPixels(),
                        width * height * bpp) == 0);

  // clone the image (use same pixel format)
  auto_ptr<Image> identical_clone(CloneImage(image.get()));
  CPPUNIT_ASSERT(image->getWidth()  == identical_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == identical_clone->getHeight());
  CPPUNIT_ASSERT(image->getFormat() == identical_clone->getFormat());
  CPPUNIT_ASSERT(memcmp(image->getPixels(),
                        identical_clone->getPixels(),
                        width * height * bpp) == 0);

  // clone the image, removing the alpha channel
  auto_ptr<Image> other_clone(CloneImage(identical_clone.get(), PF_R8G8B8));
  CPPUNIT_ASSERT(image->getWidth()  == other_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == other_clone->getHeight());
  CPPUNIT_ASSERT(other_clone->getFormat() == PF_R8G8B8);
  byte* image_p = (byte*)image->getPixels();
  byte* other_p = (byte*)other_clone->getPixels();
  for (int i = 0; i < width * height; ++i) {
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    ++image_p;  // skip alpha
  }

  // flip the image
  // clone source first, since flip frees the original
  auto_ptr<Image> flip_none(FlipImage(CloneImage(image.get()), 0));
  auto_ptr<Image> flip_x   (FlipImage(CloneImage(image.get()), CA_X));
  auto_ptr<Image> flip_y   (FlipImage(CloneImage(image.get()), CA_Y));
  auto_ptr<Image> flip_xy  (FlipImage(CloneImage(image.get()), CA_X | CA_Y));

  AssertImagesEqual("No flipping", flip_none.get(), image.get());

  CPPUNIT_ASSERT(flip_x.get() != 0);
  CPPUNIT_ASSERT(width  == flip_x->getWidth());
  CPPUNIT_ASSERT(height == flip_x->getHeight());
  CPPUNIT_ASSERT(format == flip_x->getFormat());

  CPPUNIT_ASSERT(flip_y.get() != 0);
  CPPUNIT_ASSERT(width  == flip_y->getWidth());
  CPPUNIT_ASSERT(height == flip_y->getHeight());
  CPPUNIT_ASSERT(format == flip_y->getFormat());

  CPPUNIT_ASSERT(flip_xy.get() != 0);
  CPPUNIT_ASSERT(width  == flip_xy->getWidth()); 
  CPPUNIT_ASSERT(height == flip_xy->getHeight());
  CPPUNIT_ASSERT(format == flip_xy->getFormat());

  const byte* flip_x_pixels  = (const byte*)flip_x->getPixels();
  const byte* flip_y_pixels  = (const byte*)flip_y->getPixels();
  const byte* flip_xy_pixels = (const byte*)flip_xy->getPixels();

  for (int h = 0; h < height; h++) {
    for (int w = 0; w < width; w++) {
      const int image_index = (h * width + w) * bpp;
      const int opp_w = width  - 1 - w;
      const int opp_h = height - 1 - h;
      const int flip_x_index  = (opp_h * width + w) * bpp;
      const int flip_y_index  = (h * width + opp_w) * bpp;
      const int flip_xy_index = (opp_h * width + opp_w) * bpp;
      
      for (int p = 0; p < bpp; p++) {
        CPPUNIT_ASSERT(pixels[image_index] == flip_x_pixels [flip_x_index]);
        CPPUNIT_ASSERT(pixels[image_index] == flip_y_pixels [flip_y_index]);
        CPPUNIT_ASSERT(pixels[image_index] == flip_xy_pixels[flip_xy_index]);
      }
    }
  }

}