Example #1
0
static PyObject *
pygimp_bilinear_color(PyObject *self, PyObject *args, PyObject *kwargs, gboolean with_alpha)
{
    gdouble x, y;
    GimpRGB values[4];
    GimpRGB rgb;
    PyObject *py_values, *v;
    int i, success;
    static char *kwlist[] = { "x", "y", "values", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     with_alpha ? "ddO:bilinear_rgba"
                                               : "ddO:bilinear_rgb",
                                     kwlist,
                                     &x, &y, &py_values))
        return NULL;

    if (!PySequence_Check(py_values) || PySequence_Size(py_values) != 4) {
        PyErr_SetString(PyExc_TypeError, "values is not a sequence of 4 items");
        return NULL;
    }

    for (i = 0; i < 4; i++) {
        v = PySequence_GetItem(py_values, i);
        success = pygimp_rgb_from_pyobject(v, &values[i]);
        Py_DECREF(v);
        if (!success) {
            PyErr_Format(PyExc_TypeError, "values[%d] is not a GimpRGB", i);
            return NULL;
        }
    }

    if (with_alpha)
        rgb = gimp_bilinear_rgba(x, y, values);
    else
        rgb = gimp_bilinear_rgb(x, y, values);

    return pygimp_rgb_new(&rgb);
}
Example #2
0
static void
getpixel (GimpPixelRgn *src_rgn,
          GimpRGB      *p,
          gdouble       u,
          gdouble       v)
{
  register gint x1, y1, x2, y2;
  gint width, height;
  static GimpRGB pp[4];

  width = src_rgn->w;
  height = src_rgn->h;

  x1 = (gint)u;
  y1 = (gint)v;

  if (x1 < 0)
    x1 = width - (-x1 % width);
  else
    x1 = x1 % width;

  if (y1 < 0)
    y1 = height - (-y1 % height);
  else
    y1 = y1 % height;

  x2 = (x1 + 1) % width;
  y2 = (y1 + 1) % height;

  peek (src_rgn, x1, y1, &pp[0]);
  peek (src_rgn, x2, y1, &pp[1]);
  peek (src_rgn, x1, y2, &pp[2]);
  peek (src_rgn, x2, y2, &pp[3]);

  if (source_drw_has_alpha)
    *p = gimp_bilinear_rgba (u, v, pp);
  else
    *p = gimp_bilinear_rgb (u, v, pp);
}