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), frmt(OTHER_FORMAT)
26 context = imlib_context_new();
30 ImlibImage::ImlibImage(int width, int height): data(NULL), w(width), h(height), frmt(OTHER_FORMAT)
33 context = imlib_context_new();
34 imlib_context_push(context);
35 data = imlib_create_image(width, height);
40 ImlibImage::~ImlibImage()
45 imlib_context_push(context);
46 imlib_context_set_image(data);
48 imlib_context_pop(); //??
50 imlib_context_free(context);
54 int ImlibImage::load(const QString &path)
56 Imlib_Load_Error error;
60 imlib_context_push(context);
61 data = imlib_load_image_with_error_return(QFile::encodeName(path), &error);
62 if (error == IMLIB_LOAD_ERROR_NONE)
64 imlib_context_set_image(data);
65 w = imlib_image_get_width();
66 h = imlib_image_get_height();
70 if (w == 0 || h == 0) {
73 double r = (double)w/h;
77 else if (1.0/r > 1.14)
85 return error == IMLIB_LOAD_ERROR_NONE;
88 void ImlibImage::addImage(ImlibImage *source, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
91 if (data && source->data)
93 imlib_context_push(context);
94 imlib_context_set_image(data);
95 imlib_blend_image_onto_image(source->data, 1,
103 void ImlibImage::draw(QPaintDevice *p, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
108 imlib_context_push(context);
110 imlib_context_set_image(data);
112 imlib_context_set_display(p->x11Display());
113 imlib_context_set_visual((Visual *)p->x11Visual());
114 imlib_context_set_colormap(p->x11Colormap());
116 imlib_context_set_drawable(p->handle());
117 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
124 int ImlibImage::width() const
129 int ImlibImage::height() const
134 ImageFormat ImlibImage::getFormat() const
139 void ImlibImage::setFormat(ImageFormat format)
144 void ImlibImage::rotate(int orient)
149 imlib_context_push(context);
150 imlib_context_set_image(data);
151 imlib_image_orientate(orient);
152 w = imlib_image_get_width();
153 h = imlib_image_get_height();
159 ImlibImage* ImlibImage::rotateClone(int orient)
163 ImlibImage *img = new ImlibImage();
164 imlib_context_push(context);
165 imlib_context_set_image(data);
166 imlib_image_orientate(orient);
167 img->data = imlib_clone_image();
169 imlib_context_set_image(img->data);
170 imlib_image_orientate(0);
171 img->w = h; //imlib_image_get_width();
172 img->h = w; //imlib_image_get_height();
178 void ImlibImage::reset()
183 imlib_context_push(context);
184 imlib_context_set_image(data);
194 void ImlibImage::setCacheSize(int bytes)
197 imlib_set_cache_size(bytes);