filters/gp_filter_resize_alloc: Check w and h
[gfxprim.git] / libs / gfx / GP_Rect.c
blob832b2640e85622049967e9f5b4b94ccc1184e2cf
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-2011 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
26 #include "core/GP_Transform.h"
28 #include "gfx/GP_HLine.h"
29 #include "gfx/GP_VLine.h"
30 #include "gfx/GP_Rect.h"
32 void gp_rect_xyxy_raw(gp_pixmap *pixmap, gp_coord x0, gp_coord y0,
33 gp_coord x1, gp_coord y1, gp_pixel pixel)
35 gp_hline_raw(pixmap, x0, x1, y0, pixel);
36 gp_hline_raw(pixmap, x0, x1, y1, pixel);
37 gp_vline_raw(pixmap, x0, y0, y1, pixel);
38 gp_vline_raw(pixmap, x1, y0, y1, pixel);
41 void gp_rect_xywh_raw(gp_pixmap *pixmap, gp_coord x, gp_coord y,
42 gp_size w, gp_size h, gp_pixel pixel)
44 if (w == 0 || h == 0)
45 return;
47 gp_rect_xyxy_raw(pixmap, x, y, x + w - 1, y + h - 1, pixel);
50 void gp_rect_xyxy(gp_pixmap *pixmap, gp_coord x0, gp_coord y0,
51 gp_coord x1, gp_coord y1, gp_pixel pixel)
53 GP_CHECK_PIXMAP(pixmap);
55 GP_TRANSFORM_POINT(pixmap, x0, y0);
56 GP_TRANSFORM_POINT(pixmap, x1, y1);
58 gp_rect_xyxy_raw(pixmap, x0, y0, x1, y1, pixel);
61 void gp_rect_xywh(gp_pixmap *pixmap, gp_coord x, gp_coord y,
62 gp_size w, gp_size h, gp_pixel pixel)
64 if (w == 0 || h == 0)
65 return;
67 gp_rect_xyxy(pixmap, x, y, x + w - 1, y + h - 1, pixel);
70 void gp_fill_rect_xyxy_raw(gp_pixmap *pixmap, gp_coord x0, gp_coord y0,
71 gp_coord x1, gp_coord y1, gp_pixel pixel)
73 GP_CHECK_PIXMAP(pixmap);
75 if (y0 > y1)
76 GP_SWAP(y0, y1);
78 y0 = GP_MAX(0, y0);
79 y1 = GP_MIN(y1, (gp_coord)pixmap->h - 1);
81 gp_coord y;
82 for (y = y0; y <= y1; y++)
83 gp_hline_raw(pixmap, x0, x1, y, pixel);
86 void gp_fill_rect_xywh_raw(gp_pixmap *pixmap, gp_coord x, gp_coord y,
87 gp_size w, gp_size h, gp_pixel pixel)
89 if (w == 0 || h == 0)
90 return;
92 gp_fill_rect_xyxy_raw(pixmap, x, y, x + w - 1, y + h - 1, pixel);
95 void gp_fill_rect_xyxy(gp_pixmap *pixmap, gp_coord x0, gp_coord y0,
96 gp_coord x1, gp_coord y1, gp_pixel pixel)
98 GP_CHECK_PIXMAP(pixmap);
100 GP_TRANSFORM_POINT(pixmap, x0, y0);
101 GP_TRANSFORM_POINT(pixmap, x1, y1);
103 gp_fill_rect_xyxy_raw(pixmap, x0, y0, x1, y1, pixel);
106 void gp_fill_rect_xywh(gp_pixmap *pixmap, gp_coord x, gp_coord y,
107 gp_size w, gp_size h, gp_pixel pixel)
109 if (w == 0 || h == 0)
110 return;
112 gp_fill_rect_xyxy(pixmap, x, y, x + w - 1, y + h - 1, pixel);