2009-09-01 03:14:13 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
qimage.cpp
|
|
|
|
|
2017-01-13 04:29:42 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <gambas@users.sourceforge.net>
|
2009-09-01 03:14:13 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
2011-12-31 03:39:20 +01:00
|
|
|
MA 02110-1301, USA.
|
2009-09-01 03:14:13 +02:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "qimage.h"
|
|
|
|
|
|
|
|
void QImage::init()
|
|
|
|
{
|
|
|
|
img = NULL;
|
|
|
|
bpl = 0;
|
|
|
|
jt = NULL;
|
2017-09-08 02:11:09 +02:00
|
|
|
inv = FALSE;
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 02:11:09 +02:00
|
|
|
void QImage::check()
|
2009-09-01 03:14:13 +02:00
|
|
|
{
|
2017-09-08 02:11:09 +02:00
|
|
|
if (!img)
|
|
|
|
return;
|
2012-12-08 03:17:49 +01:00
|
|
|
if (GB_IMAGE_FMT_IS_SWAPPED(img->format))
|
|
|
|
fprintf(stderr, "gb.image.effect: warning: unsupported image format: %s\n", IMAGE.FormatToString(img->format));
|
2017-09-08 02:11:09 +02:00
|
|
|
inv = GB_IMAGE_FMT_IS_RGBA(img->format);
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QImage::create(int w, int h, bool t)
|
|
|
|
{
|
|
|
|
img = IMAGE.Create(w, h, t ? GB_IMAGE_BGRA : GB_IMAGE_BGRX, NULL);
|
2017-09-08 02:11:09 +02:00
|
|
|
//GB.Ref(img);
|
|
|
|
check();
|
|
|
|
jumpTable();
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage::QImage()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage::QImage(const QSize &size, bool t)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
create(size.width(), size.height(), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage::QImage(int w, int h, bool t)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
create(w, h, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage::QImage(GB_IMAGE image)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
img = (GB_IMG *)image;
|
2017-09-08 02:11:09 +02:00
|
|
|
//GB.Ref(img);
|
|
|
|
SYNCHRONIZE_IMAGE(img);
|
|
|
|
check();
|
|
|
|
jumpTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage::QImage(const QImage ©)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
img = (GB_IMG *)copy.object();
|
|
|
|
//GB.Ref(img);
|
2010-06-19 14:38:28 +02:00
|
|
|
SYNCHRONIZE_IMAGE(img);
|
2017-09-08 02:11:09 +02:00
|
|
|
check();
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage::~QImage()
|
|
|
|
{
|
|
|
|
if (jt)
|
2017-09-08 02:11:09 +02:00
|
|
|
{
|
|
|
|
free(jt);
|
|
|
|
jt = NULL;
|
|
|
|
}
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QImage::release()
|
|
|
|
{
|
2017-09-08 02:11:09 +02:00
|
|
|
GB.Unref(POINTER(&img));
|
|
|
|
img = NULL;
|
2009-09-01 03:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static inline uint invert(uint col)
|
|
|
|
{
|
|
|
|
return (col >> 24) | (col << 24) | ((col & 0x00FF0000) >> 8) | ((col & 0x0000FF00) << 8);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void QImage::invert()
|
|
|
|
{
|
|
|
|
uint i, n;
|
|
|
|
uchar *p, t;
|
|
|
|
|
|
|
|
n = width() * height();
|
|
|
|
p = (uchar *)bits();
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++, p += 4)
|
|
|
|
{
|
|
|
|
t = p[0];
|
|
|
|
p[0] = p[2];
|
|
|
|
p[2] = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uchar **QImage::jumpTable()
|
|
|
|
{
|
|
|
|
if (!jt && img->data)
|
|
|
|
{
|
2017-09-08 02:11:09 +02:00
|
|
|
int bpl = 4 * width();
|
2009-09-01 03:14:13 +02:00
|
|
|
jt = (uchar**)malloc(height() * sizeof(uchar*));
|
|
|
|
for (int i = 0; i < height(); i++)
|
|
|
|
jt[i] = (uchar *)img->data + i * bpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QImage::invertPixels()
|
|
|
|
{
|
|
|
|
uint i, n;
|
|
|
|
uint *p;
|
|
|
|
|
|
|
|
n = width() * height();
|
|
|
|
p = (uint *)bits();
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
p[i] ^= 0xFFFFFF;
|
|
|
|
}
|