summaryrefslogtreecommitdiff
path: root/libopie2/opieui/oimageeffect.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opieui/oimageeffect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oimageeffect.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp
index 01e7c6f..9a58bb9 100644
--- a/libopie2/opieui/oimageeffect.cpp
+++ b/libopie2/opieui/oimageeffect.cpp
@@ -25,25 +25,26 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// $Id$
#include <math.h>
#include <qimage.h>
#include <stdlib.h>
-#include "oimageeffect.h"
+#include <opie2/oimageeffect.h>
+#include <opie2/odebug.h>
#define MaxRGB 255L
#define DegreesToRadians(x) ((x)*M_PI/180.0)
using namespace std;
inline unsigned int intensityValue(unsigned int color)
{
return((unsigned int)((0.299*qRed(color) +
0.587*qGreen(color) +
0.1140000000000001*qBlue(color))));
}
@@ -54,25 +55,25 @@ inline unsigned int intensityValue(unsigned int color)
//
//======================================================================
QImage OImageEffect::gradient(const QSize &size, const QColor &ca,
const QColor &cb, GradientType eff, int ncols)
{
int rDiff, gDiff, bDiff;
int rca, gca, bca, rcb, gcb, bcb;
QImage image(size, 32);
if (size.width() == 0 || size.height() == 0) {
- qDebug( "WARNING: OImageEffect::gradient: invalid image" );
+ odebug << "WARNING: OImageEffect::gradient: invalid image" << oendl;
return image;
}
register int x, y;
rDiff = (rcb = cb.red()) - (rca = ca.red());
gDiff = (gcb = cb.green()) - (gca = ca.green());
bDiff = (bcb = cb.blue()) - (bca = ca.blue());
if( eff == VerticalGradient || eff == HorizontalGradient ){
uint *p;
@@ -340,25 +341,25 @@ QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
// float xbal = xfactor/5000.;
// float ybal = yfactor/5000.;
float xbal = xfactor/30./size.width();
float ybal = yfactor/30./size.height();
float rat;
int rDiff, gDiff, bDiff;
int rca, gca, bca, rcb, gcb, bcb;
QImage image(size, 32);
if (size.width() == 0 || size.height() == 0) {
- qDebug( "WARNING: OImageEffect::unbalancedGradient : invalid image" );
+ odebug << "WARNING: OImageEffect::unbalancedGradient : invalid image" << oendl;
return image;
}
register int x, y;
unsigned int *scanline;
rDiff = (rcb = cb.red()) - (rca = ca.red());
gDiff = (gcb = cb.green()) - (gca = ca.green());
bDiff = (bcb = cb.blue()) - (bca = ca.blue());
if( eff == VerticalGradient || eff == HorizontalGradient){
QColor cRow;
@@ -559,25 +560,25 @@ QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
/* This builds a 256 byte unsigned char lookup table with all
* the possible percent values prior to applying the effect, then uses
* integer math for the pixels. For any image larger than 9x9 this will be
* less expensive than doing a float operation on the 3 color components of
* each pixel. (mosfet)
*/
QImage& OImageEffect::intensity(QImage &image, float percent)
{
if (image.width() == 0 || image.height() == 0) {
- qDebug( "WARNING: OImageEffect::intensity : invalid image" );
+ odebug << "WARNING: OImageEffect::intensity : invalid image" << oendl;
return image;
}
int segColors = image.depth() > 8 ? 256 : image.numColors();
unsigned char *segTbl = new unsigned char[segColors];
int pixels = image.depth() > 8 ? image.width()*image.height() :
image.numColors();
unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
(unsigned int *)image.colorTable();
bool brighten = (percent >= 0);
if(percent < 0)
@@ -624,25 +625,25 @@ QImage& OImageEffect::intensity(QImage &image, float percent)
data[i] = qRgba(r, g, b, a);
}
}
delete [] segTbl;
return image;
}
QImage& OImageEffect::channelIntensity(QImage &image, float percent,
RGBComponent channel)
{
if (image.width() == 0 || image.height() == 0) {
- qDebug( "WARNING: OImageEffect::channelIntensity : invalid image" );
+ odebug << "WARNING: OImageEffect::channelIntensity : invalid image" << oendl;
return image;
}
int segColors = image.depth() > 8 ? 256 : image.numColors();
unsigned char *segTbl = new unsigned char[segColors];
int pixels = image.depth() > 8 ? image.width()*image.height() :
image.numColors();
unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
(unsigned int *)image.colorTable();
bool brighten = (percent >= 0);
if(percent < 0)
percent = -percent;
@@ -714,25 +715,25 @@ QImage& OImageEffect::channelIntensity(QImage &image, float percent,
delete [] segTbl;
return image;
}
// Modulate an image with an RBG channel of another image
//
QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse,
ModulationType type, int factor, RGBComponent channel)
{
if (image.width() == 0 || image.height() == 0 ||
modImage.width() == 0 || modImage.height() == 0) {
- qDebug( "WARNING: OImageEffect::modulate : invalid image" );
+ odebug << "WARNING: OImageEffect::modulate : invalid image" << oendl;
return image;
}
int r, g, b, h, s, v, a;
QColor clr;
int mod=0;
unsigned int x1, x2, y1, y2;
register int x, y;
// for image, we handle only depth 32
if (image.depth()<32) image = image.convertDepth(32);
@@ -843,25 +844,25 @@ QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse,
// Blend effects
//
//======================================================================
// Nice and fast direct pixel manipulation
QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity)
{
if (dst.width() <= 0 || dst.height() <= 0)
return dst;
if (opacity < 0.0 || opacity > 1.0) {
- qDebug( "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] ");
+ odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] " << oendl;
return dst;
}
int depth = dst.depth();
if (depth != 32)
dst = dst.convertDepth(32);
int pixels = dst.width() * dst.height();
int rcol, gcol, bcol;
clr.rgb(&rcol, &gcol, &bcol);
#ifdef WORDS_BIGENDIAN // ARGB (skip alpha)
@@ -886,30 +887,30 @@ QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity)
return dst;
}
// Nice and fast direct pixel manipulation
QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity)
{
if (src.width() <= 0 || src.height() <= 0)
return dst;
if (dst.width() <= 0 || dst.height() <= 0)
return dst;
if (src.width() != dst.width() || src.height() != dst.height()) {
- qDebug( "WARNING: OImageEffect::blend : src and destination images are not the same size" );
+ odebug << "WARNING: OImageEffect::blend : src and destination images are not the same size" << oendl;
return dst;
}
if (opacity < 0.0 || opacity > 1.0) {
- qDebug( "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" );
+ odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" << oendl;
return dst;
}
if (src.depth() != 32) src = src.convertDepth(32);
if (dst.depth() != 32) dst = dst.convertDepth(32);
int pixels = src.width() * src.height();
#ifdef WORDS_BIGENDIAN // ARGB (skip alpha)
register unsigned char *data1 = (unsigned char *)dst.bits() + 1;
register unsigned char *data2 = (unsigned char *)src.bits() + 1;
#else // BGRA
register unsigned char *data1 = (unsigned char *)dst.bits();
@@ -931,25 +932,25 @@ QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity)
data2++;
}
return dst;
}
QImage& OImageEffect::blend(QImage &image, float initial_intensity,
const QColor &bgnd, GradientType eff,
bool anti_dir)
{
if (image.width() == 0 || image.height() == 0 || image.depth()!=32 ) {
- qDebug( "WARNING: OImageEffect::blend : invalid image" );
+ odebug << "WARNING: OImageEffect::blend : invalid image" << oendl;
return image;
}
int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue();
int r, g, b;
int ind;
unsigned int xi, xf, yi, yf;
unsigned int a;
// check the boundaries of the initial intesity param
float unaffected = 1;
@@ -1124,25 +1125,25 @@ QImage& OImageEffect::blend(QImage &image, float initial_intensity,
g = qGreen(data[ind]) + (int)(intensity *
(g_bgnd - qGreen(data[ind])));
b = qBlue (data[ind]) + (int)(intensity *
(b_bgnd - qBlue (data[ind])));
if (r > 255) r = 255; if (r < 0 ) r = 0;
if (g > 255) g = 255; if (g < 0 ) g = 0;
if (b > 255) b = 255; if (b < 0 ) b = 0;
a = qAlpha(data[ind]);
data[ind] = qRgba(r, g, b, a);
}
}
}
- else qDebug( "OImageEffect::blend effect not implemented" );
+ else odebug << "OImageEffect::blend effect not implemented" << oendl;
return image;
}
// Not very efficient as we create a third big image...
//
QImage& OImageEffect::blend(QImage &image1, QImage &image2,
GradientType gt, int xf, int yf)
{
if (image1.width() == 0 || image1.height() == 0 ||
image2.width() == 0 || image2.height() == 0)
return image1;
@@ -1154,25 +1155,25 @@ QImage& OImageEffect::blend(QImage &image1, QImage &image2,
return blend(image1,image2,image3, Red); // Channel to use is arbitrary
}
// Blend image2 into image1, using an RBG channel of blendImage
//
QImage& OImageEffect::blend(QImage &image1, QImage &image2,
QImage &blendImage, RGBComponent channel)
{
if (image1.width() == 0 || image1.height() == 0 ||
image2.width() == 0 || image2.height() == 0 ||
blendImage.width() == 0 || blendImage.height() == 0) {
- qDebug( "OImageEffect::blend effect invalid image" );
+ odebug << "OImageEffect::blend effect invalid image" << oendl;
return image1;
}
int r, g, b;
int ind1, ind2, ind3;
unsigned int x1, x2, x3, y1, y2, y3;
unsigned int a;
register int x, y;
// for image1 and image2, we only handle depth 32
@@ -1252,25 +1253,25 @@ unsigned int OImageEffect::uHash(unsigned int c)
ng = g + (g >> 3); ng = ng < g ? ~0 : ng;
nb = b + (b >> 3); nb = nb < b ? ~0 : nb;
return qRgba(nr, ng, nb, a);
}
// -----------------------------------------------------------------------------
QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing)
{
if (image.width() == 0 || image.height() == 0) {
- qDebug( "OImageEffect::hash effect invalid image" );
+ odebug << "OImageEffect::hash effect invalid image" << oendl;
return image;
}
register int x, y;
unsigned int *data = (unsigned int *)image.bits();
unsigned int ind;
//CT no need to do it if not enough space
if ((lite == NorthLite ||
lite == SouthLite)&&
(unsigned)image.height() < 2+spacing) return image;
if ((lite == EastLite ||
@@ -1760,25 +1761,25 @@ bool OImageEffect::blend(
const QImage & upper,
const QImage & lower,
QImage & output
)
{
if (
upper.width() > lower.width() ||
upper.height() > lower.height() ||
upper.depth() != 32 ||
lower.depth() != 32
)
{
- qDebug( "OImageEffect::blend : Sizes not correct" );
+ odebug << "OImageEffect::blend : Sizes not correct" << oendl;
return false;
}
output = lower.copy();
register uchar *i, *o;
register int a;
register int col;
register int w = upper.width();
int row(upper.height() - 1);
do {
@@ -1977,25 +1978,25 @@ void OImageEffect::normalize(QImage &img)
{
int *histogram, threshold_intensity, intense;
int x, y, i;
unsigned int gray_value;
unsigned int *normalize_map;
unsigned int high, low;
// allocate histogram and normalize map
histogram = (int *)calloc(MaxRGB+1, sizeof(int));
normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int));
if(!normalize_map || !histogram){
- qWarning("Unable to allocate normalize histogram and map");
+ owarn << "Unable to allocate normalize histogram and map" << oendl;
free(normalize_map);
free(histogram);
return;
}
// form histogram
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
gray_value = intensityValue(data[x]);
@@ -2093,25 +2094,25 @@ void OImageEffect::equalize(QImage &img)
{
int *histogram, *map, *equalize_map;
int x, y, i, j;
unsigned int high, low;
// allocate histogram and maps
histogram = (int *)calloc(MaxRGB+1, sizeof(int));
map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int));
if(!histogram || !map || !equalize_map){
- qWarning("Unable to allocate equalize histogram and maps");
+ owarn << "Unable to allocate equalize histogram and maps" << oendl;
free(histogram);
free(map);
free(equalize_map);
return;
}
// form histogram
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
histogram[intensityValue(data[x])]++;
@@ -2178,43 +2179,43 @@ QImage OImageEffect::sample(QImage &src, int w, int h)
{
if(w == src.width() && h == src.height())
return(src);
double *x_offset, *y_offset;
int j, k, y;
register int x;
QImage dest(w, h, src.depth());
x_offset = (double *)malloc(w*sizeof(double));
y_offset = (double *)malloc(h*sizeof(double));
if(!x_offset || !y_offset){
- qWarning("Unable to allocate pixels buffer");
+ owarn << "Unable to allocate pixels buffer" << oendl;
free(x_offset);
free(y_offset);
return(src);
}
// init pixel offsets
for(x=0; x < w; ++x)
x_offset[x] = x*src.width()/((double)w);
for(y=0; y < h; ++y)
y_offset[y] = y*src.height()/((double)h);
// sample each row
if(src.depth() > 8){ // DirectClass source image
unsigned int *srcData, *destData;
unsigned int *pixels;
pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int));
if(!pixels){
- qWarning("Unable to allocate pixels buffer");
+ owarn << "Unable to allocate pixels buffer" << oendl;
free(pixels);
free(x_offset);
free(y_offset);
return(src);
}
j = (-1);
for(y=0; y < h; ++y){
destData = (unsigned int *)dest.scanLine(y);
if(j != y_offset[y]){
// read a scan line
j = (int)(y_offset[y]);
srcData = (unsigned int *)src.scanLine(j);
@@ -2224,25 +2225,25 @@ QImage OImageEffect::sample(QImage &src, int w, int h)
for(x=0; x < w; ++x){
k = (int)(x_offset[x]);
destData[x] = pixels[k];
}
}
free(pixels);
}
else{ // PsudeoClass source image
unsigned char *srcData, *destData;
unsigned char *pixels;
pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char));
if(!pixels){
- qWarning("Unable to allocate pixels buffer");
+ owarn << "Unable to allocate pixels buffer" << oendl;
free(pixels);
free(x_offset);
free(y_offset);
return(src);
}
// copy colortable
dest.setNumColors(src.numColors());
(void)memcpy(dest.colorTable(), src.colorTable(),
src.numColors()*sizeof(unsigned int));
// sample image
j = (-1);
@@ -3063,25 +3064,25 @@ QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength,
*q=interpolateColor(&src, x, (int)(y-sine_map[x]), background);
++q;
}
}
free(sine_map);
return(dest);
}
QImage OImageEffect::oilPaint(QImage &src, int radius)
{
// TODO 8bpp src!
if(src.depth() < 32){
- qWarning("Oil Paint source image < 32bpp. Convert before using!");
+ owarn << "Oil Paint source image < 32bpp. Convert before using!" << oendl;
return(src);
}
int j, k, i, x, y;
unsigned int *histogram;
unsigned int *s;
unsigned int count;
unsigned int *srcData, *destData;
QImage dest(src);
dest.detach();
histogram = (unsigned int *) malloc((MaxRGB+1)*sizeof(unsigned int));