1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include "image-helpers.h"
21 Glib::RefPtr<Gdk::Pixmap> to_pixmap(Glib::RefPtr<Gdk::Pixbuf> pixbuf)
23 Glib::RefPtr<Gdk::Pixmap> p = Gdk::Pixmap::create(Glib::RefPtr<Gdk::Drawable>(0), pixbuf->get_width(), pixbuf->get_height(), 24);
24 pixbuf->render_to_drawable_alpha(p, 0, 0, 0, 0, pixbuf->get_width(),
25 pixbuf->get_height(), Gdk::PIXBUF_ALPHA_BILEVEL,
26 123, Gdk::RGB_DITHER_NONE, 0, 0);
27 //p = Gdk::Pixmap::create(Glib::RefPtr<Gdk::Drawable>(0),
28 //pixbuf->get_width(), pixbuf->get_height(), 24);
29 //p->draw_pixbuf(pixbuf, 0, 0, 0, 0, pixbuf->get_width(), pixbuf->get_height(),
30 //Gdk::RGB_DITHER_NORMAL, 0, 0);
35 disassemble_row(const std::string &file, int no)
37 Glib::RefPtr<Gdk::Pixbuf> row = Gdk::Pixbuf::create_from_file(file);
39 std::vector<Glib::RefPtr<Gdk::Pixbuf> > images;
42 int h = row->get_height();
43 int w = row->get_width() / no;
46 for (int x = 0; x < no; ++x) {
47 Glib::RefPtr<Gdk::Pixbuf> buf
48 = Gdk::Pixbuf::create(row->get_colorspace(),
50 row->get_bits_per_sample(),
53 row->copy_area(x * w, 0, w, h, buf, 0, 0);
55 images.push_back(buf);
58 std::vector<PixMask*> pixmasks;
59 for (unsigned int i = 0; i < images.size(); i++)
60 pixmasks.push_back(PixMask::create(images[i]));
65 disassemble_row(const std::string &file, int no, bool first_half_height)
67 Glib::RefPtr<Gdk::Pixbuf> row = Gdk::Pixbuf::create_from_file(file);
69 std::vector<Glib::RefPtr<Gdk::Pixbuf> > images;
72 int h = row->get_height() / 2;
73 int w = row->get_width() / no;
76 if (first_half_height == false)
79 for (int x = 0; x < no; ++x) {
80 Glib::RefPtr<Gdk::Pixbuf> buf
81 = Gdk::Pixbuf::create(row->get_colorspace(),
83 row->get_bits_per_sample(),
86 row->copy_area(x * w, s, w, h, buf, 0, 0);
88 images.push_back(buf);
91 std::vector<PixMask*> pixmasks;
92 for (unsigned int i = 0; i < images.size(); i++)
93 pixmasks.push_back(PixMask::create(images[i]));
96 int get_pwidth(Glib::RefPtr<Gdk::Pixmap> pixmap)
98 int width = 0, height = 0;
99 pixmap->get_size(width, height);
102 int get_pheight(Glib::RefPtr<Gdk::Pixmap> pixmap)
104 int width = 0, height = 0;
105 pixmap->get_size(width, height);
108 Glib::RefPtr<Gdk::Pixmap> scale (Glib::RefPtr<Gdk::Pixmap> pixmap, int w, int h)
111 //return to_pixmap(to_pixbuf(pixmap)->scale_simple(w, h, Gdk::INTERP_BILINEAR));