Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / filters / GP_Resize.c
blob5e8b0babf9ef21f744ee9b53843fe947aa50762e
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim 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 GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <errno.h>
25 #include "core/GP_Pixmap.h"
26 #include "core/GP_Debug.h"
28 #include "GP_ResizeNN.h"
29 #include "GP_ResizeLinear.h"
30 #include "GP_ResizeCubic.h"
31 #include "GP_Resize.h"
33 static const char *interp_types[] = {
34 "Nearest Neighbour",
35 "Linear (Int)",
36 "Linear with Low Pass (Int)",
37 "Cubic (Float)",
38 "Cubic (Int)",
41 const char *GP_InterpolationTypeName(enum GP_InterpolationType interp_type)
43 if (interp_type > GP_INTERP_MAX)
44 return "Unknown";
46 return interp_types[interp_type];
49 static int resize(const GP_Pixmap *src, GP_Pixmap *dst,
50 GP_InterpolationType type,
51 GP_ProgressCallback *callback)
53 switch (type) {
54 case GP_INTERP_NN:
55 return GP_FilterResizeNN(src, dst, callback);
56 case GP_INTERP_LINEAR_INT:
57 return GP_FilterResizeLinearInt(src, dst, callback);
58 case GP_INTERP_LINEAR_LF_INT:
59 return GP_FilterResizeLinearLFInt(src, dst, callback);
60 case GP_INTERP_CUBIC:
61 return GP_FilterResizeCubic(src, dst, callback);
62 case GP_INTERP_CUBIC_INT:
63 return GP_FilterResizeCubicInt(src, dst, callback);
66 GP_WARN("Invalid interpolation type %u", (unsigned int)type);
68 errno = EINVAL;
69 return 1;
72 int GP_FilterResize(const GP_Pixmap *src, GP_Pixmap *dst,
73 GP_InterpolationType type,
74 GP_ProgressCallback *callback)
76 if (src->pixel_type != dst->pixel_type) {
77 GP_WARN("The src and dst pixel types must match");
78 errno = EINVAL;
79 return 1;
82 return resize(src, dst, type, callback);
85 GP_Pixmap *GP_FilterResizeAlloc(const GP_Pixmap *src,
86 GP_Size w, GP_Size h,
87 GP_InterpolationType type,
88 GP_ProgressCallback *callback)
90 GP_Pixmap *res = GP_PixmapAlloc(w, h, src->pixel_type);
92 if (!res)
93 return NULL;
95 if (resize(src, res, type, callback)) {
96 GP_PixmapFree(res);
97 return NULL;
100 return res;