1 /*
2  * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 
27 #ifndef MLIB_IMAGECHECK_H
28 #define MLIB_IMAGECHECK_H
29 
30 #include <stdlib.h>
31 #include <mlib_image.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /***************************************************************/
38 
39 #define MLIB_IMAGE_CHECK(image)                                 \
40   if (image == NULL) return MLIB_NULLPOINTER
41 
42 #define MLIB_IMAGE_SIZE_EQUAL(image1,image2)                       \
43   if (mlib_ImageGetWidth(image1)  != mlib_ImageGetWidth(image2) || \
44       mlib_ImageGetHeight(image1) != mlib_ImageGetHeight(image2))  \
45     return MLIB_FAILURE
46 
47 #define MLIB_IMAGE_TYPE_EQUAL(image1,image2)                    \
48   if (mlib_ImageGetType(image1) != mlib_ImageGetType(image2))   \
49     return MLIB_FAILURE
50 
51 #define MLIB_IMAGE_CHAN_EQUAL(image1,image2)                          \
52   if (mlib_ImageGetChannels(image1) != mlib_ImageGetChannels(image2)) \
53     return MLIB_FAILURE
54 
55 #define MLIB_IMAGE_FULL_EQUAL(image1,image2)                    \
56   MLIB_IMAGE_SIZE_EQUAL(image1,image2);                         \
57   MLIB_IMAGE_TYPE_EQUAL(image1,image2);                         \
58   MLIB_IMAGE_CHAN_EQUAL(image1,image2)
59 
60 #define MLIB_IMAGE_HAVE_TYPE(image, type)                       \
61   if (mlib_ImageGetType(image) != type)                         \
62     return MLIB_FAILURE
63 
64 #define MLIB_IMAGE_HAVE_CHAN(image, channels)                   \
65   if (mlib_ImageGetChannels(image) != channels)                 \
66     return MLIB_FAILURE
67 
68 #define MLIB_IMAGE_HAVE_3_OR_4_CHAN(image)                      \
69   if (mlib_ImageGetChannels(image) != 3 &&                      \
70       mlib_ImageGetChannels(image) != 4)                        \
71     return MLIB_FAILURE
72 
73 #define MLIB_IMAGE_CHAN_SRC1_OR_EQ(src, dst)                      \
74   if (mlib_ImageGetChannels(src) != 1) {                          \
75     if (mlib_ImageGetChannels(src) != mlib_ImageGetChannels(dst)) \
76       return MLIB_FAILURE;                                        \
77   }
78 
79 #define MLIB_IMAGE_TYPE_DSTBIT_OR_EQ(src, dst)                  \
80   if ((mlib_ImageGetType(src) != mlib_ImageGetType(dst)) &&     \
81       (mlib_ImageGetType(dst) != MLIB_BIT)) {                   \
82     return MLIB_FAILURE;                                        \
83   }
84 
85 #define MLIB_IMAGE_GET_ALL_PARAMS(image, type, nchan, width, height, stride, pdata) \
86   type   = mlib_ImageGetType(image);                                                \
87   nchan  = mlib_ImageGetChannels(image);                                            \
88   width  = mlib_ImageGetWidth(image);                                               \
89   height = mlib_ImageGetHeight(image);                                              \
90   stride = mlib_ImageGetStride(image);                                              \
91   pdata  = (void*)mlib_ImageGetData(image)
92 
93 /***************************************************************/
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif  /* MLIB_IMAGECHECK_H */
99