2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <glib/gi18n.h>
28 #include "gfx/pixbuffactory.hpp"
29 #include "misc/autogfreeptr.hpp"
30 #include "gfx/pixbuf.hpp"
31 #include "gfx/pixbufmanip.hpp"
33 /* scale2x is not translated: the license says that we should call it in its original name. */
34 // TRANSLATORS: you can translate "nearest neighbor" to "nearest" if the resulting
35 // string would be too long otherwise.
36 const char *gd_scaling_names
[] = {N_("Nearest neighbor"), "Scale2x", "HQX", NULL
};
39 /* check the arrays on start */
43 g_assert(G_N_ELEMENTS(gd_scaling_names
) == GD_SCALING_MAX
+ 1); /* +1 is the terminating NULL */
48 /* scales a pixbuf with the appropriate scaling type. */
49 Pixbuf
*PixbufFactory::create_scaled(const Pixbuf
&src
, int scaling_factor
, GdScalingType scaling_type
, bool pal_emulation
) const {
50 Pixbuf
*scaled
= this->create(src
.get_width() * scaling_factor
, src
.get_height() * scaling_factor
);
51 switch (scaling_factor
) {
53 src
.copy(*scaled
, 0, 0);
56 switch (scaling_type
) {
57 case GD_SCALING_NEAREST
:
58 scale2xnearest(src
, *scaled
);
60 case GD_SCALING_SCALE2X
:
61 scale2x(src
, *scaled
);
67 g_assert_not_reached();
72 switch (scaling_type
) {
73 case GD_SCALING_NEAREST
:
74 scale3xnearest(src
, *scaled
);
76 case GD_SCALING_SCALE2X
:
77 scale3x(src
, *scaled
);
83 g_assert_not_reached();
88 switch (scaling_type
) {
89 case GD_SCALING_NEAREST
:
90 /* 2x nearest applied twice. */
92 std::auto_ptr
<Pixbuf
> scale2x(this->create(src
.get_width() * 2, src
.get_height() * 2));
93 scale2xnearest(src
, *scale2x
);
94 scale2xnearest(*scale2x
, *scaled
);
97 case GD_SCALING_SCALE2X
:
98 /* scale2x applied twice. */
100 std::auto_ptr
<Pixbuf
> scale2xpb(this->create(src
.get_width() * 2, src
.get_height() * 2));
101 scale2x(src
, *scale2xpb
);
102 scale2x(*scale2xpb
, *scaled
);
109 g_assert_not_reached();
114 g_assert_not_reached();
119 pal_emulate(*scaled
);
125 Pixbuf
*PixbufFactory::create_from_base64(const char *base64
) const {
127 AutoGFreePtr
<guchar
> decoded(g_base64_decode(base64
, &len
));
128 return create_from_inline(len
, decoded
);