[GB.IMAGE.EFFECT]

* NEW: Image.Histogram() is a new method that returns the image histogram.
* NEW: ImageHistogram is a new class that represents an image histogram.


git-svn-id: svn://localhost/gambas/trunk@3647 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2011-03-13 02:47:19 +00:00
parent d7c7f37a30
commit bfaf40d1e0
4 changed files with 105 additions and 17 deletions

View File

@ -324,6 +324,81 @@ BEGIN_METHOD(CIMAGE_implode, GB_FLOAT factor; GB_INTEGER background)
END_METHOD
BEGIN_METHOD_VOID(Image_Histogram)
CIMAGEHISTOGRAM *hist;
int *histogram;
QImage image(THIS);
unsigned int *p, *pm;
GB.New(POINTER(&hist), GB.FindClass("ImageHistogram"), NULL, NULL);
GB.Alloc(POINTER(&histogram), sizeof(int) * 256 * 4);
memset(histogram, 0, 256 * 4 * sizeof(int));
p = (unsigned int *)image.bits();
pm = &p[image.width() * image.height()];
while (p < pm)
{
histogram[qBlue(*p)]++;
histogram[qGreen(*p) + 256]++;
histogram[qRed(*p) + 256 * 2]++;
histogram[qAlpha(*p) + 256 * 3]++;
p++;
}
hist->histogram = histogram;
GB.ReturnObject(hist);
END_METHOD
BEGIN_METHOD_VOID(ImageHistogram_free)
GB.Free(POINTER(&THIS_HISTOGRAM->histogram));
END_METHOD
BEGIN_METHOD(ImageHistogram_get, GB_INTEGER channel; GB_INTEGER value)
int channel;
int value;
switch(VARG(channel))
{
case KImageEffect::Blue: channel = 0; break;
case KImageEffect::Green: channel = 1; break;
case KImageEffect::Red: channel = 2; break;
case KImageEffect::Alpha: channel = 3; break;
default: GB.Error("Bad channel"); return;
}
value = VARG(value);
if (value < 0 || value > 255)
{
GB.Error("Out of bounds");
return;
}
GB.ReturnInteger(THIS_HISTOGRAM->histogram[channel * 256 + value]);
END_METHOD
GB_DESC ImageHistogramDesc[] =
{
GB_DECLARE("ImageHistogram", sizeof(CIMAGEHISTOGRAM)),
GB_NOT_CREATABLE(),
GB_METHOD("_free", NULL, ImageHistogram_free, NULL),
GB_METHOD("_get", "i", ImageHistogram_get, "(Channel)i(Value)i"),
GB_END_DECLARE
};
GB_DESC CImageDesc[] =
{
GB_DECLARE("Image", 0),
@ -341,6 +416,7 @@ GB_DESC CImageDesc[] =
GB_CONSTANT("Red", "i", KImageEffect::Red),
GB_CONSTANT("Green", "i", KImageEffect::Green),
GB_CONSTANT("Blue", "i", KImageEffect::Blue),
GB_CONSTANT("Alpha", "i", KImageEffect::Alpha),
GB_CONSTANT("Uniform", "i", KImageEffect::UniformNoise),
GB_CONSTANT("Gaussian", "i", KImageEffect::GaussianNoise),
@ -376,6 +452,8 @@ GB_DESC CImageDesc[] =
GB_METHOD("Wave", "Image", CIMAGE_wave, "[(Amplitude)f(WaveLength)f(Background)i]"),
GB_METHOD("Noise", "Image", CIMAGE_noise, "(Noise)i"),
GB_METHOD("Implode", "Image", CIMAGE_implode, "[(Factor)f(Background)i]"),
GB_METHOD("Histogram", "ImageHistogram", Image_Histogram, NULL),
GB_END_DECLARE
};

View File

@ -28,12 +28,20 @@
#ifndef __CIMAGE_CPP
extern GB_DESC CImageDesc[];
extern GB_DESC ImageHistogramDesc[];
#else
#define THIS ((GB_IMAGE)_object)
#define THIS_HISTOGRAM ((CIMAGEHISTOGRAM *)_object)
#endif
typedef
struct {
GB_BASE ob;
int *histogram;
}
CIMAGEHISTOGRAM;
#endif

View File

@ -93,7 +93,8 @@ public:
Green = 2, //!< Green channel
Blue = 4, //!< Blue channel
All = 7, //!< All channels
Gray = 15 //!< Grey channel
Alpha = 8
//Gray = 15 //!< Grey channel
};
/**

View File

@ -1,22 +1,22 @@
/***************************************************************************
main.cpp
main.cpp
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
@ -32,14 +32,15 @@ GB_INTERFACE IMAGE EXPORT;
GB_DESC *GB_CLASSES[] EXPORT =
{
CImageDesc,
NULL
ImageHistogramDesc,
CImageDesc,
NULL
};
int EXPORT GB_INIT(void)
{
GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE);
return 0;
return 0;
}
void EXPORT GB_EXIT()