2 * This file is a part of QComicBook.
4 * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
6 * QComicBook is free software; you can redestribute it and/or modify it
7 * under terms of GNU General Public License by Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY. See GPL for more details.
13 #include "imlibimage.h"
14 #include <qpaintdevice.h>
19 using namespace QComicBook;
21 QMutex ImlibImage::mutex;
23 ImlibImage::ImlibImage(): data(NULL), w(0), h(0)
26 context = imlib_context_new();
30 ImlibImage::~ImlibImage()
35 imlib_context_push(context);
36 imlib_context_set_image(data);
38 imlib_context_pop(); //??
40 imlib_context_free(context);
44 int ImlibImage::load(const QString &path)
46 Imlib_Load_Error error;
50 imlib_context_push(context);
51 data = imlib_load_image_with_error_return(QFile::encodeName(path), &error);
52 if (error == IMLIB_LOAD_ERROR_NONE)
54 imlib_context_set_image(data);
55 w = imlib_image_get_width();
56 h = imlib_image_get_height();
61 return error == IMLIB_LOAD_ERROR_NONE;
64 void ImlibImage::draw(QPaintDevice *p, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
69 imlib_context_push(context);
71 imlib_context_set_image(data);
73 imlib_context_set_display(p->x11Display());
74 imlib_context_set_visual((Visual *)p->x11Visual());
75 imlib_context_set_colormap(p->x11Colormap());
77 imlib_context_set_drawable(p->handle());
78 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
85 int ImlibImage::width() const
90 int ImlibImage::height() const
95 void ImlibImage::rotate(int orient)
101 imlib_context_push(context);
102 imlib_context_set_image(data);
103 imlib_image_orientate(orient);
104 w = imlib_image_get_width();
105 h = imlib_image_get_height();
112 ImlibImage* ImlibImage::rotateClone(int orient)
116 ImlibImage *img = new ImlibImage();
117 imlib_context_push(context);
118 imlib_context_set_image(data);
119 imlib_image_orientate(orient);
120 img->data = imlib_clone_image();
122 imlib_context_set_image(img->data);
123 imlib_image_orientate(0);
124 img->w = h; //imlib_image_get_width();
125 img->h = w; //imlib_image_get_height();
131 void ImlibImage::reset()
137 imlib_context_push(context);
138 imlib_context_set_image(data);
148 void ImlibImage::setCacheSize(int bytes)
151 imlib_set_cache_size(bytes);