Beispiel #1
0
GimpRGB
peek (gint x,
      gint y)
{
  static guchar data[4];

  GimpRGB color;

  gimp_pixel_rgn_get_pixel (&source_region, data, x, y);

  color.r = (gdouble) (data[0]) / 255.0;
  color.g = (gdouble) (data[1]) / 255.0;
  color.b = (gdouble) (data[2]) / 255.0;

  if (input_drawable->bpp == 4)
    {
      if (in_channels == 4)
        color.a = (gdouble) (data[3]) / 255.0;
      else
        color.a = 1.0;
    }
  else
    {
      color.a = 1.0;
    }

  return color;
}
Beispiel #2
0
static GimpRGB
peek_box_image (gint image,
		gint x,
		gint y)
{
  static guchar data[4];

  GimpRGB color;

  gimp_pixel_rgn_get_pixel (&box_regions[image], data, x, y);

  color.r = (gdouble) (data[0]) / 255.0;
  color.g = (gdouble) (data[1]) / 255.0;
  color.b = (gdouble) (data[2]) / 255.0;

  if (box_drawables[image]->bpp == 4)
    {
      if (gimp_drawable_has_alpha (box_drawables[image]->drawable_id))
        color.a = (gdouble) (data[3]) / 255.0;
      else
        color.a = 1.0;
    }
  else
    {
      color.a = 1.0;
    }

  return color;
}
Beispiel #3
0
static guchar*
rgb_to_hsl (GimpDrawable     *drawable,
            LICEffectChannel  effect_channel)
{
  guchar       *themap, data[4];
  gint          x, y;
  GimpRGB       color;
  GimpHSL       color_hsl;
  gdouble       val = 0.0;
  glong         maxc, index = 0;
  GimpPixelRgn  region;
  GRand        *gr;

  gr = g_rand_new ();

  maxc = drawable->width * drawable->height;

  gimp_pixel_rgn_init (&region, drawable, border_x, border_y,
                       border_w, border_h, FALSE, FALSE);

  themap = g_new (guchar, maxc);

  for (y = 0; y < region.h; y++)
    {
      for (x = 0; x < region.w; x++)
        {
          data[3] = 255;

          gimp_pixel_rgn_get_pixel (&region, data, x, y);
          gimp_rgba_set_uchar (&color, data[0], data[1], data[2], data[3]);
          gimp_rgb_to_hsl (&color, &color_hsl);

          switch (effect_channel)
            {
            case LIC_HUE:
              val = color_hsl.h * 255;
              break;
            case LIC_SATURATION:
              val = color_hsl.s * 255;
              break;
            case LIC_BRIGHTNESS:
              val = color_hsl.l * 255;
              break;
            }

          /* add some random to avoid unstructured areas. */
          val += g_rand_double_range (gr, -1.0, 1.0);

          themap[index++] = (guchar) CLAMP0255 (RINT (val));
        }
    }

  g_rand_free (gr);

  return themap;
}
Beispiel #4
0
static void
peek (GimpPixelRgn *src_rgn,
      gint          x,
      gint          y,
      GimpRGB      *color)
{
  static guchar data[4] = { 0, };

  gimp_pixel_rgn_get_pixel (src_rgn, data, x, y);
  gimp_rgba_set_uchar (color, data[0], data[1], data[2], data[3]);
}
guchar
sel_pixel_value (gint row,
                 gint col)
{
  guchar ret;

  if (col > sel_width || row > sel_height)
    {
      g_warning ("sel_pixel_value [%d,%d] out of bounds", col, row);
      return 0;
    }

  gimp_pixel_rgn_get_pixel(&selection_rgn,&ret,col+sel_x1,row+sel_y1);

  return ret;
}
Beispiel #6
0
static void
exponentialrange (GimpDrawable *drawable)
{
  gint         i, j, k, channels;
  gint         x1, y1, x2, y2;
  GimpPixelRgn rgn_in, rgn_out;
  guchar       output[4];

  /* Gets upper left and lower right coordinates,
   * and layers number in the image */
  gimp_drawable_mask_bounds (drawable->drawable_id,
                             &x1, &y1,
                             &x2, &y2);
  channels = gimp_drawable_bpp (drawable->drawable_id);

  /* Initialises two PixelRgns, one to read original data,
   * and the other to write output data. That second one will
   * be merged at the end by the call to
   * gimp_drawable_merge_shadow() */
  gimp_pixel_rgn_init (&rgn_in,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       FALSE, FALSE);
  gimp_pixel_rgn_init (&rgn_out,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       TRUE, TRUE);

  /* find the range [minp,maxp] */
  guchar minp[4],maxp[4];
  /* initial values are high for minp, low for maxp*/
  for (j = 0; j < 4; j++){
	minp[j]=255; // default for guchar 0..255
	maxp[j]=0;
  }
  /* get the right range */
  for (i = x1; i < x2; i++){
      for (j = y1; j < y2; j++){
          guchar pixel[4];
          gimp_pixel_rgn_get_pixel (&rgn_in, pixel, i, j);
          for (k = 0; k < channels; k++){
		if(minp[k]>pixel[k]) minp[k]=pixel[k];
		if(maxp[k]<pixel[k]) maxp[k]=pixel[k];
          }
      }
  }


  for (i = x1; i < x2; i++)
    {
      for (j = y1; j < y2; j++)
        {
          guchar pixel[4];

          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel, /*[4]*/
                                    i, j);
          /* For each layer, compute the exponential in the same range */
          for (k = 0; k < channels; k++)
            {
              	double ex =   exp(pixel[k])- exp(minp[k]);
                double ran=exp(maxp[k])-exp(minp[k]);
                output[k] = (guchar)( minp[k] + (maxp[k]-minp[k]) * (ex/ran) );

            }

          gimp_pixel_rgn_set_pixel (&rgn_out,
                                    output,
                                    i, j);
        } /*end for j*/

      if (i % 10 == 0)
        gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1));

    } /*end for i*/

  /* Update the modified region */
  gimp_drawable_flush (drawable);
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
  gimp_drawable_update (drawable->drawable_id,
                        x1, y1,
                        x2 - x1, y2 - y1);
}
Beispiel #7
0
static void
exponential (GimpDrawable *drawable)
{
  gint         i, j, k, channels;
  gint         x1, y1, x2, y2;
  GimpPixelRgn rgn_in, rgn_out;
  guchar       output[4];

  /* Gets upper left and lower right coordinates,
   * and layers number in the image */
  gimp_drawable_mask_bounds (drawable->drawable_id,
                             &x1, &y1,
                             &x2, &y2);
  channels = gimp_drawable_bpp (drawable->drawable_id);

  /* Initialises two PixelRgns, one to read original data,
   * and the other to write output data. That second one will
   * be merged at the end by the call to
   * gimp_drawable_merge_shadow() */
  gimp_pixel_rgn_init (&rgn_in,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       FALSE, FALSE);
  gimp_pixel_rgn_init (&rgn_out,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       TRUE, TRUE);

  /*
  guchar minp[4],maxp[4];
  for (j = 0; j < 4; j++){
	minp[j]=255;
	maxp[j]=0;
  }
  for (i = x1; i < x2; i++){
      for (j = y1; j < y2; j++){
          guchar pixel[4];
          gimp_pixel_rgn_get_pixel (&rgn_in, pixel, i, j);
          for (k = 0; k < channels; k++){
		if(minp[k]>pixel[k]) minp[k]=pixel[k];
		if(maxp[k]<pixel[k]) maxp[k]=pixel[k];
          }
  } }
  */

  for (i = x1; i < x2; i++)
    {
      for (j = y1; j < y2; j++)
        {
/*          guchar pixel[9][4];   */
          guchar pixel[4];

          /* Get ONE pixel */
       /* gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[0],
                                    MAX (i - 1, x1), MAX (j - 1, y1));
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[1],
                                    MAX (i - 1, x1), j);
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[2],
                                    MAX (i - 1, x1), MIN (j + 1, y2 - 1));

          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[3],
                                    i, MAX (j - 1, y1));  */
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel, /*[4]*/
                                    i, j);
       /*  gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[5],
                                    i, MIN (j + 1, y2 - 1));

          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[6],
                                    MIN (i + 1, x2 - 1), MAX (j - 1, y1));
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[7],
                                    MIN (i + 1, x2 - 1), j);
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[8],
                                    MIN (i + 1, x2 - 1), MIN (j + 1, y2 - 1));
        */
          /* For each layer, compute the exponential color code
		 (255*(-1 +exp(code))/(-1 +exp(255)) ) */

          for (k = 0; k < channels; k++)
            {
                double ex = exp(pixel[k])-1, max=exp(255)-1;
                output[k] = (guchar)(255 *(ex/max));
            }

          gimp_pixel_rgn_set_pixel (&rgn_out,
                                    output,
                                    i, j);
        } /*end for j*/

      if (i % 10 == 0)
        gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1));

    } /*end for i*/

  /* Update the modified region */
  gimp_drawable_flush (drawable);
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
  gimp_drawable_update (drawable->drawable_id,
                        x1, y1,
                        x2 - x1, y2 - y1);
}
Beispiel #8
0
static void
symmetry (GimpDrawable *drawable)
{
  gint         i, j, k, channels;
  gint         x1, y1, x2, y2;
  GimpPixelRgn rgn_in, rgn_out;
  guchar       output[4];

  /* Gets upper left and lower right coordinates,
   * and layers number in the image */
  gimp_drawable_mask_bounds (drawable->drawable_id,
                             &x1, &y1,
                             &x2, &y2);
  channels = gimp_drawable_bpp (drawable->drawable_id);

  /* Initialises two PixelRgns, one to read original data,
   * and the other to write output data. That second one will
   * be merged at the end by the call to
   * gimp_drawable_merge_shadow() */
  gimp_pixel_rgn_init (&rgn_in,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       FALSE, FALSE);
  gimp_pixel_rgn_init (&rgn_out,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       TRUE, TRUE);

  for (i = x1; i < x2; i++)
    {
      for (j = y1; j < y2; j++)
        {
          guchar pixel[4];

          /* Get ONE pixel */
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel,
                                    i, j);
          /* For each layer */
          for (k = 0; k < channels; k++)
            {
              output[k] = 255 - pixel[k];
            }

          gimp_pixel_rgn_set_pixel (&rgn_out,
                                    output,
                                    i, j);
        } /*end for j*/

      if (i % 10 == 0)
        gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1));

    } /*end for i*/

  /* Update the modified region */
  gimp_drawable_flush (drawable);
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
  gimp_drawable_update (drawable->drawable_id,
                        x1, y1,
                        x2 - x1, y2 - y1);
}
Beispiel #9
0
void * jpeg_highlighter_analyze(JOB_ARG *job)
{
	int ii, jj, kk;
	int row;
	int col;

	long long red_sum = 0;
	long long green_sum = 0;
	long long blue_sum = 0;

	guchar max_pixel_color[4];

	union
	{
		guchar pixel[4];
		unsigned int value;
	} stuff;

	gint32 layer_id;
	int temp = 0;
	int unique_compressed_colors = 0;
	int unique_original_colors = 0;

	int *histogram;

	max_pixel_color[0] = 0;
	max_pixel_color[1] = 0;
	max_pixel_color[2] = 0;
	max_pixel_color[3] = 0;

	histogram = (int*)malloc(sizeof(int)*255*255*255);
//
//	GimpRunMode mode = GIMP_RUN_NONINTERACTIVE;
//	PIXEL **temp_array;
GimpPixelRgn rgn_in;

	printf("in analizer\n");

	job->drawable->drawable_id = gimp_image_get_active_drawable(job->image_id);

	layer_id = gimp_image_get_active_layer(job->image_id);

//	printf("adding alpha channel\n");
//	gimp_layer_add_alpha(layer_id);
//
//
////	if(! gimp_drawable_has_alpha (layer_id))
////	{
////		 /* some filtermacros do not work with layer that do not have an alpha channel
////		 * and cause gimp to fail on attempt to call gimp_pixel_rgn_init
////		  * with both dirty and shadow flag set to TRUE
////		  * in this situation GIMP displays the error message
////		  *    "expected tile ack and received: 5"
////		  *    and causes the called plug-in to exit immediate without success
////		  * Therfore always add an alpha channel before calling a filtermacro.
////		  */
////		  gimp_layer_add_alpha(layer_id);
////		  printf("adding alpha channel\n");
////   }


	printf("zeroed array\n");

	for(ii = 0; ii < 255*255*255; ii++)
	{
		histogram[ii] = 0;
	}

	gimp_pixel_rgn_init(&rgn_in, job->drawable, job->start_colum, job->start_row, job->image.width, job->image.height, FALSE, FALSE);

	for (row = 0; row < job->image.height; row++)
	{
		for (col = 0; col < job->image.width; col++)
		{
			gimp_pixel_rgn_get_pixel (&rgn_in, stuff.pixel, col,row);

			job->array_out[col][row].red = stuff.pixel[0];
			job->array_out[col][row].green = stuff.pixel[1];
			job->array_out[col][row].blue = stuff.pixel[2];

			red_sum += stuff.pixel[0];
			green_sum += stuff.pixel[1];
			blue_sum += stuff.pixel[2];

			stuff.pixel[3] = 0;

			if(stuff.pixel[0] + stuff.pixel[1]+ stuff.pixel[2] > max_pixel_color[0] +  max_pixel_color[1] +  max_pixel_color[2] )
			{
				max_pixel_color[0] = stuff.pixel[0];
				max_pixel_color[1] = stuff.pixel[1];
				max_pixel_color[2] = stuff.pixel[2];
			}

			histogram[stuff.value]++;

		}

		if (row % 50 == 0)
		{
			gimp_progress_update ((gdouble) row / job->image.height);

		}
	}

	for(ii = 0; ii < 255*255*255; ii++)
	{	
		if(histogram[ii] != 0)
		{
			unique_compressed_colors++;
		}
	}

	//doing the original

	printf("zeroed array\n");

	for(ii = 0; ii < 255*255*255; ii++)
	{
		histogram[ii] = 0;
	}


	for (row = 0; row < job->image.height; row++)
	{
		for (col = 0; col < job->image.width; col++)
		{
			stuff.pixel[0] = job->array_in[col][row].red;
			stuff.pixel[1] = job->array_in[col][row].green;
			stuff.pixel[2] = job->array_in[col][row].blue;

			stuff.pixel[3] = 0;

			histogram[stuff.value]++;

		}
	}

	for(ii = 0; ii < 255*255*255; ii++)
	{
		if(histogram[ii] != 0)
		{
			unique_original_colors++;
		}
	}

	free(histogram);

	print_log("\nJpeg compression difference\n",temp);
	print_log("unique colors in original image:%d\n",unique_original_colors);
	print_log("unique colors in compressed image:%d\n",unique_compressed_colors);
	print_log("ratio: %f\n",(double)unique_original_colors/unique_compressed_colors);
	print_log("brightest compressed color %d %d %d\n",max_pixel_color[0], max_pixel_color[1], max_pixel_color[2]);
	print_log("avg compressed color %f %f %f\n",(float)red_sum/(job->image.height*job->image.width), (float)green_sum/(job->image.height*job->image.width),(float)blue_sum/(job->image.height*job->image.width));
}
Beispiel #10
0
static PyObject *
pr_subscript(PyGimpPixelRgn *self, PyObject *key)
{
    GimpPixelRgn *pr = &(self->pr);
    PyObject *x, *y;
    Py_ssize_t x1, y1, x2, y2, xs, ys;
    PyObject *ret;

    if (!PyTuple_Check(key) || PyTuple_Size(key) != 2) {
        PyErr_SetString(PyExc_TypeError, "subscript must be a 2-tuple");
        return NULL;
    }

    if (!PyArg_ParseTuple(key, "OO", &x, &y))
        return NULL;

    if (PyInt_Check(x)) {
        x1 = PyInt_AsSsize_t(x);

        if (x1 < pr->x || x1 >= pr->x + pr->w) {
            PyErr_SetString(PyExc_IndexError, "x subscript out of range");
            return NULL;
        }

        if (PyInt_Check(y)) {
            y1 = PyInt_AsSsize_t(y);

            if (y1 < pr->y || y1 >= pr->y + pr->h) {
                PyErr_SetString(PyExc_IndexError, "y subscript out of range");
                return NULL;
            }

            ret = PyString_FromStringAndSize(NULL, pr->bpp);
            gimp_pixel_rgn_get_pixel(pr, (guchar*)PyString_AS_STRING(ret),
                                     x1, y1);

        } else if (PySlice_Check(y)) {
            if (PySlice_GetIndices((PySliceObject*)y, pr->y + pr->h,
                                   &y1, &y2, &ys) ||
                y1 >= y2 || ys != 1) {
                PyErr_SetString(PyExc_IndexError, "invalid y slice");
                return NULL;
            }

            if(y1 == 0)
                y1 = pr->y;

            if(y1 < pr->y || y2 < pr->y) {
                PyErr_SetString(PyExc_IndexError, "y subscript out of range");
                return NULL;
            }

            ret = PyString_FromStringAndSize(NULL, pr->bpp * (y2 - y1));
            gimp_pixel_rgn_get_col(pr, (guchar*)PyString_AS_STRING(ret),
                                   x1, y1, y2-y1);
	    }
        else {
            PyErr_SetString(PyExc_TypeError, "invalid y subscript");
            return NULL;
        }
    } else if (PySlice_Check(x)) {
        if (PySlice_GetIndices((PySliceObject *)x, pr->x + pr->w,
                               &x1, &x2, &xs) ||
            x1 >= x2 || xs != 1) {
            PyErr_SetString(PyExc_IndexError, "invalid x slice");
            return NULL;
        }
        if (x1 == 0)
            x1 = pr->x;
        if(x1 < pr->x || x2 < pr->x) {
            PyErr_SetString(PyExc_IndexError, "x subscript out of range");
            return NULL;
        }

        if (PyInt_Check(y)) {
            y1 = PyInt_AsSsize_t(y);
            if (y1 < pr->y || y1 >= pr->y + pr->h) {
                PyErr_SetString(PyExc_IndexError, "y subscript out of range");
                return NULL;
            }
            ret = PyString_FromStringAndSize(NULL, pr->bpp * (x2 - x1));
            gimp_pixel_rgn_get_row(pr, (guchar*)PyString_AS_STRING(ret),
                                   x1, y1, x2 - x1);

        } else if (PySlice_Check(y)) {
            if (PySlice_GetIndices((PySliceObject*)y, pr->y + pr->h,
                                   &y1, &y2, &ys) ||
                y1 >= y2 || ys != 1) {
                PyErr_SetString(PyExc_IndexError, "invalid y slice");
                return NULL;
            }

            if(y1 == 0)
                y1 = pr->y;
            if(y1 < pr->y || y2 < pr->y) {
                PyErr_SetString(PyExc_IndexError, "y subscript out of range");
                return NULL;
            }

            ret = PyString_FromStringAndSize(NULL,
                                             pr->bpp * (x2 - x1) * (y2 - y1));
            gimp_pixel_rgn_get_rect(pr, (guchar*)PyString_AS_STRING(ret),
                                    x1, y1, x2 - x1, y2 - y1);
	    }
        else {
            PyErr_SetString(PyExc_TypeError, "invalid y subscript");
            return NULL;
        }

    } else {
        PyErr_SetString(PyExc_TypeError, "invalid x subscript");
        return NULL;
    }
    return ret;
}
Beispiel #11
0
static void
blur (GimpDrawable *drawable)
{
  gint         i, j, k, channels;
  gint         x1, y1, x2, y2;
  GimpPixelRgn rgn_in, rgn_out;
  guchar       output[4];

  /* Gets upper left and lower right coordinates,
   * and layers number in the image */
  gimp_drawable_mask_bounds (drawable->drawable_id,
                             &x1, &y1,
                             &x2, &y2);
  channels = gimp_drawable_bpp (drawable->drawable_id);

  /* Initialises two PixelRgns, one to read original data,
   * and the other to write output data. That second one will
   * be merged at the end by the call to
   * gimp_drawable_merge_shadow() */
  gimp_pixel_rgn_init (&rgn_in,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       FALSE, FALSE);
  gimp_pixel_rgn_init (&rgn_out,
                       drawable,
                       x1, y1,
                       x2 - x1, y2 - y1,
                       TRUE, TRUE);

  for (i = x1; i < x2; i++)
    {
      for (j = y1; j < y2; j++)
        {
          guchar pixel[9][4];

          /* Get nine pixels */
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[0],
                                    MAX (i - 1, x1), MAX (j - 1, y1));
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[1],
                                    MAX (i - 1, x1), j);
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[2],
                                    MAX (i - 1, x1), MIN (j + 1, y2 - 1));

          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[3],
                                    i, MAX (j - 1, y1));
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[4],
                                    i, j);
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[5],
                                    i, MIN (j + 1, y2 - 1));

          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[6],
                                    MIN (i + 1, x2 - 1), MAX (j - 1, y1));
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[7],
                                    MIN (i + 1, x2 - 1), j);
          gimp_pixel_rgn_get_pixel (&rgn_in,
                                    pixel[8],
                                    MIN (i + 1, x2 - 1), MIN (j + 1, y2 - 1));

          /* For each layer, compute the average of the
           * nine */
          for (k = 0; k < channels; k++)
            {
              int tmp, sum = 0;
              for (tmp = 0; tmp < 9; tmp++)
                sum += pixel[tmp][k];
              output[k] = sum / 9;
            }

          gimp_pixel_rgn_set_pixel (&rgn_out,
                                    output,
                                    i, j);
        }

      if (i % 10 == 0)
        gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1));
    }

  /* Update the modified region */
  gimp_drawable_flush (drawable);
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
  gimp_drawable_update (drawable->drawable_id,
                        x1, y1,
                        x2 - x1, y2 - y1);
}