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) 2011 Tomas Gavenciak <gavento@ucw.cz> *
21 *****************************************************************************/
23 #include "GP_Common.h"
24 #include "GP_Convert.h"
25 #include "GP_GetPutPixel.h"
26 #include "GP_TestingCore.h"
27 #include "GP_TestingRandom.h"
30 * TODO: Use a different version for palette types.
32 GP_Pixel
GP_RandomColor(GP_PixelType type
)
34 return GP_RGBAToPixel(GP_TestingRandom() % 256, GP_TestingRandom() % 256,
35 GP_TestingRandom() % 256, GP_TestingRandom() % 256, type
);
38 void GP_RandomizeRect(GP_Context
*context
, GP_Coord x
, GP_Coord y
, GP_Size w
, GP_Size h
)
42 for (i
= 0; i
< w
; i
++)
43 for (j
= 0; j
< h
; j
++)
44 GP_PutPixel(context
, i
+ x
, j
+ y
, GP_RandomColor(context
->pixel_type
));
47 /* TODO: Proper equality definition (currently almost ad-hoc */
48 int GP_EqualColors(GP_Pixel p1
, GP_PixelType t1
, GP_Pixel p2
, GP_PixelType t2
)
50 int size1
= GP_PixelTypes
[t1
].size
;
51 int size2
= GP_PixelTypes
[t2
].size
;
55 return GP_GET_BITS(0, size1
, p1
) == GP_GET_BITS(0, size1
, p2
);
57 // t1 -> RGBA8888 -> t2
58 GP_Pixel conv1
= GP_RGBA8888ToPixel(GP_PixelToRGBA8888(p1
, t1
), t2
);
59 if (GP_GET_BITS(0, size2
, conv1
) == GP_GET_BITS(0, size2
, p2
))
62 // t2 -> RGBA8888 -> t1
63 GP_Pixel conv2
= GP_RGBA8888ToPixel(GP_PixelToRGBA8888(p2
, t2
), t1
);
64 if (GP_GET_BITS(0, size1
, conv2
) == GP_GET_BITS(0, size1
, p1
))
70 int GP_EqualRects(const GP_Context
*c1
, GP_Coord x1
, GP_Coord y1
, GP_Size w
, GP_Size h
,
71 const GP_Context
*c2
, GP_Coord x2
, GP_Coord y2
)
76 for (i
= 0; i
< w
; i
++)
77 for (j
= 0; j
< h
; j
++) {
78 if (!GP_EqualColors(GP_GetPixel(c1
, x1
+ i
, y1
+ j
), c1
->pixel_type
,
79 GP_GetPixel(c2
, x2
+ i
, y2
+ j
), c2
->pixel_type
))