-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnga.cpp
51 lines (41 loc) · 1.17 KB
/
pnga.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Simple program to convert an RGB image where white=alpha, and black=colour into
* an RGBA image suitable for use by QtC.
*
* Compile with: g++ pnga.cpp -o pnga -I/usr/include/qt3 -lqt-mt
*/
#include <qimage.h>
static void qtc_adjust_pix(unsigned char *data, int numChannels, int w, int h, int stride)
{
int width=w*numChannels,
offset=0,
row;
for(row=0; row<h; ++row)
{
int column;
for(column=0; column<width; column+=numChannels)
{
int alpha=(int)data[offset+column+2];
data[offset+column] = data[offset+column+1] = data[offset+column+2] = 0;
data[offset+column+3] = 255-alpha;
}
offset+=stride;
}
}
int main(int argc, char *argv[])
{
if(2==argc)
{
QString fname(argv[1]);
QImage img(fname);
if (img.depth()<32)
img=img.convertDepth(32);
img.setAlphaBuffer(true);
qtc_adjust_pix(img.bits(), 4, img.width(), img.height(), img.bytesPerLine());
int pos=fname.findRev('.');
img.save(fname.left(pos)+"_a.png", "PNG");
}
else
printf("Usage: %s <img file>\n", argv[0]);
return 0;
}