12#include <QApplication>
14#include <kpluginfactory.h>
105 img = QImage(tga.
width, tga.
height, QImage::Format_RGB32);
115 const bool alphaFlag = tga.
flags & 0xf;
117 qWarning() <<
"WARNING: TGA image with 32-bit pixel size reports absence of alpha channel. It is not possible, fixing...";
121 img = QImage(tga.
width, tga.
height, QImage::Format_ARGB32);
128 dbgFile <<
"This TGA file is broken with size " << size;
140 uchar *
const image =
new uchar[size];
144 char * dst = (
char *)image;
152 uint count = (c & 0x7f) + 1;
153 num -= count * pixel_size;
156 dbgFile <<
"This TGA file is broken: the number of pixels left to read and the number of RLE pixels do not agree" <<
ppVar(num) <<
ppVar(count) <<
ppVar(pixel_size);
162 Q_ASSERT(pixel_size <= 8);
164 s.readRawData(pixel, pixel_size);
166 memcpy(dst, pixel, pixel_size);
172 s.readRawData(dst, count);
178 s.readRawData((
char *)image, size);
182 int y_start, y_step, y_end;
195 bool hasAlpha =
false;
196 for (
int y = y_start; y != y_end; y += y_step) {
197 QRgb * scanline = (
QRgb *) (
void*) img.scanLine(y);
201 for (
int x = 0; x < tga.
width; x++) {
205 }
else if (info.
grey) {
207 for (
int x = 0; x < tga.
width; x++) {
208 scanline[x] = qRgb(*src, *src, *src);
214 for (
int x = 0; x < tga.
width; x++) {
216 scanline[x] = qRgb((c.
r << 3) | (c.
r >> 2), (c.
g << 3) | (c.
g >> 2), (c.
b << 3) | (c.
b >> 2));
220 for (
int x = 0; x < tga.
width; x++) {
221 scanline[x] = qRgb(src[2], src[1], src[0]);
225 for (
int x = 0; x < tga.
width; x++) {
226 const uchar alpha = src[3];
227 scanline[x] = qRgba(src[2], src[1], src[0], alpha);
229 hasAlpha |= (alpha > 0);
241 img.convertTo(QImage::Format_RGB32);
242 qWarning() <<
"WARNING: TGA image with 32-bit has all pixels transparent, removing alpha information.";
255 Q_UNUSED(configuration);
257 s.setByteOrder(QDataStream::LittleEndian);
275 bool result =
loadTGA(s, tga, img);
277 if (result ==
false) {
282 KisImageSP image =
new KisImage(document->createUndoStore(), img.width(), img.height(), colorSpace,
"imported from tga");
288 document->setCurrentImage(image);
293#include "kis_tga_import.moc"
KisGroupLayerSP rootLayer() const
QString nextLayerName(const QString &baseName="") const
The base class for import and export filters.
void convertFromQImage(const QImage &image, const KoColorProfile *profile, qint32 offsetX=0, qint32 offsetY=0)
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration=0) override
KisTGAImport(QObject *parent, const QVariantList &)
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
static QDataStream & operator>>(QDataStream &s, TgaHeader &head)
static bool loadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
static bool isSupported(const TgaHeader &head)
@ FormatFeaturesUnsupported
rgba palette[MAX_PALETTE]
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
KisPaintDeviceSP paintDevice
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())