1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
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
[] = {
36 "Linear with Low Pass (Int)",
41 const char *GP_InterpolationTypeName(enum GP_InterpolationType interp_type
)
43 if (interp_type
> GP_INTERP_MAX
)
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
)
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
);
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
);
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");
82 return resize(src
, dst
, type
, callback
);
85 GP_Pixmap
*GP_FilterResizeAlloc(const GP_Pixmap
*src
,
87 GP_InterpolationType type
,
88 GP_ProgressCallback
*callback
)
90 GP_Pixmap
*res
= GP_PixmapAlloc(w
, h
, src
->pixel_type
);
95 if (resize(src
, res
, type
, callback
)) {