summaryrefslogtreecommitdiffstats
path: root/examples/qtapp/myqt.cpp
blob: 2375341325f4cf331698e64d7e1eaee714ca06a8 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <qlibrary.h>
#include <qapplication.h>
#include <qfile.h>

#include <qimage.h>

#include "myqt.h"

#include "ksquirrel-libs/fmt_utils.h"
#include "ksquirrel-libs/error.h"

MyQT::MyQT(TQWidget *parent, const char *name) : QLabel(parent, name)
{
    setAlignment(TQt::AlignCenter);
}

MyQT::~MyQT()
{}

QPixmap MyQT::loadImage()
{
	QLibrary lib("/usr/lib/ksquirrel-libs/libkls_bmp.so");
	lib.load();

	if(!lib.isLoaded())
	{
	    tqWarning("Can't load BMP library.");
	    tqApp->quit();
	}

	int 		i = 0;
	fmt_info	finfo;
	RGBA		*image;
	int 		current = 0;

	codec_create = (fmt_codec_base*(*)())lib.resolve("codec_create");
	codec_destroy = (void (*)(fmt_codec_base*))lib.resolve("codec_destroy");

	if(!codec_create || !codec_destroy)
	{
	    tqWarning("Library corrupted.");
	    lib.unload();
	    tqApp->quit();
	}

	const char *s = "../w3.bmp";

	if(!QFile::exists(s))
	{
	    tqWarning("Can't find example image.");
	    lib.unload();
	    tqApp->quit();
	}

	codeK = codec_create();

	i = codeK->read_init(s);

	if(i != SQE_OK)
	{
	    codeK->read_close();
	    return QPixmap();
	}

	i = codeK->read_next();
	
	finfo = codeK->information();

	if(i != SQE_OK)
	{
	    codeK->read_close();
	    return QPixmap();
	}

	image = (RGBA*)calloc(finfo.image[current].w * finfo.image[current].h, sizeof(RGBA));

	if(!image)
	{
	    codeK->read_close();
	    return QPixmap();
	}

	memset(image, 255, finfo.image[current].w * finfo.image[current].h * sizeof(RGBA));
	
	RGBA *scan;

	for(int pass = 0;pass < finfo.image[current].passes;pass++)
	{
		codeK->read_next_pass();

		for(int j = 0;j < finfo.image[current].h;j++)
		{
			scan = image + j * finfo.image[current].w;
			codeK->read_scanline(scan);
		}
	}

	if(finfo.image[current].needflip)
	    fmt_utils::flipv((char*)image, finfo.image[current].w * sizeof(RGBA), finfo.image[current].h);

	codeK->read_close();

	TQImage im((unsigned char*)image, finfo.image[current].w, finfo.image[current].h, 32, 0, 0, TQImage::LittleEndian);
	
	return QPixmap(im.swapRGB());
}

void MyQT::bind()
{
	setPixmap(loadImage());	
}