2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
/*
|
|
28 |
* FUNCTIONS
|
|
29 |
* mlib_ImageConvCopyEdge - Copy src edges to dst edges
|
|
30 |
*
|
|
31 |
*
|
|
32 |
* SYNOPSIS
|
|
33 |
* mlib_status mlib_ImageConvCopyEdge(mlib_image *dst,
|
|
34 |
* const mlib_image *src,
|
|
35 |
* mlib_s32 dx_l,
|
|
36 |
* mlib_s32 dx_r,
|
|
37 |
* mlib_s32 dy_t,
|
|
38 |
* mlib_s32 dy_b,
|
|
39 |
* mlib_s32 cmask)
|
|
40 |
*
|
|
41 |
* ARGUMENT
|
|
42 |
* dst Pointer to an dst image.
|
|
43 |
* src Pointer to an src image.
|
|
44 |
* dx_l Number of columns on the left side of the
|
|
45 |
* image to be copyed.
|
|
46 |
* dx_r Number of columns on the right side of the
|
|
47 |
* image to be copyed.
|
|
48 |
* dy_t Number of rows on the top edge of the
|
|
49 |
* image to be copyed.
|
|
50 |
* dy_b Number of rows on the top edge of the
|
|
51 |
* image to be copyed.
|
|
52 |
* cmask Channel mask to indicate the channels to be convolved.
|
|
53 |
* Each bit of which represents a channel in the image. The
|
|
54 |
* channels corresponded to 1 bits are those to be processed.
|
|
55 |
*
|
|
56 |
* RESTRICTION
|
|
57 |
* The src and the dst must be the same type, same width, same height and have same number
|
|
58 |
* of channels (1, 2, 3, or 4). The unselected channels are not
|
|
59 |
* overwritten. If both src and dst have just one channel,
|
|
60 |
* cmask is ignored.
|
|
61 |
*
|
|
62 |
* DESCRIPTION
|
|
63 |
* Copy src edges to dst edges.
|
|
64 |
*
|
|
65 |
* The unselected channels are not overwritten.
|
|
66 |
* If src and dst have just one channel,
|
|
67 |
* cmask is ignored.
|
|
68 |
*/
|
|
69 |
|
|
70 |
#include "mlib_image.h"
|
|
71 |
#include "mlib_ImageConvEdge.h"
|
|
72 |
|
|
73 |
/***************************************************************/
|
|
74 |
#define EDGES(chan, type, mask) \
|
|
75 |
{ \
|
|
76 |
type *pdst = (type *) mlib_ImageGetData(dst); \
|
|
77 |
type *psrc = (type *) mlib_ImageGetData(src); \
|
|
78 |
mlib_s32 dst_stride = mlib_ImageGetStride(dst) / sizeof(type); \
|
|
79 |
mlib_s32 src_stride = mlib_ImageGetStride(src) / sizeof(type); \
|
|
80 |
mlib_s32 i, j, l; \
|
|
81 |
mlib_s32 testchan; \
|
|
82 |
\
|
|
83 |
testchan = 1; \
|
|
84 |
for (l = chan - 1; l >= 0; l--) { \
|
|
85 |
if ((mask & testchan) == 0) { \
|
|
86 |
testchan <<= 1; \
|
|
87 |
continue; \
|
|
88 |
} \
|
|
89 |
testchan <<= 1; \
|
|
90 |
for (j = 0; j < dx_l; j++) { \
|
|
91 |
for (i = dy_t; i < (img_height - dy_b); i++) { \
|
|
92 |
pdst[i*dst_stride + l + j*chan] = psrc[i*src_stride + l + j*chan]; \
|
|
93 |
} \
|
|
94 |
} \
|
|
95 |
for (j = 0; j < dx_r; j++) { \
|
|
96 |
for (i = dy_t; i < (img_height - dy_b); i++) { \
|
|
97 |
pdst[i*dst_stride + l+(img_width-1 - j)*chan] = \
|
|
98 |
psrc[i*src_stride + l+(img_width-1 - j)*chan]; \
|
|
99 |
} \
|
|
100 |
} \
|
|
101 |
for (i = 0; i < dy_t; i++) { \
|
|
102 |
for (j = 0; j < img_width; j++) { \
|
|
103 |
pdst[i*dst_stride + l + j*chan] = psrc[i*src_stride + l + j*chan]; \
|
|
104 |
} \
|
|
105 |
} \
|
|
106 |
for (i = 0; i < dy_b; i++) { \
|
|
107 |
for (j = 0; j < img_width; j++) { \
|
|
108 |
pdst[(img_height-1 - i)*dst_stride + l + j*chan] = \
|
|
109 |
psrc[(img_height-1 - i)*src_stride + l + j*chan]; \
|
|
110 |
} \
|
|
111 |
} \
|
|
112 |
} \
|
|
113 |
}
|
|
114 |
|
|
115 |
/***************************************************************/
|
|
116 |
mlib_status mlib_ImageConvCopyEdge(mlib_image *dst,
|
|
117 |
const mlib_image *src,
|
|
118 |
mlib_s32 dx_l,
|
|
119 |
mlib_s32 dx_r,
|
|
120 |
mlib_s32 dy_t,
|
|
121 |
mlib_s32 dy_b,
|
|
122 |
mlib_s32 cmask)
|
|
123 |
{
|
|
124 |
mlib_s32 img_width = mlib_ImageGetWidth(dst);
|
|
125 |
mlib_s32 img_height = mlib_ImageGetHeight(dst);
|
|
126 |
mlib_s32 channel = mlib_ImageGetChannels(dst);
|
|
127 |
|
|
128 |
if (dx_l + dx_r > img_width) {
|
|
129 |
dx_l = img_width;
|
|
130 |
dx_r = 0;
|
|
131 |
}
|
|
132 |
|
|
133 |
if (dy_t + dy_b > img_height) {
|
|
134 |
dy_t = img_height;
|
|
135 |
dy_b = 0;
|
|
136 |
}
|
|
137 |
|
|
138 |
if (channel == 1)
|
|
139 |
cmask = 1;
|
|
140 |
|
|
141 |
switch (mlib_ImageGetType(src)) {
|
|
142 |
case MLIB_BIT:
|
|
143 |
return mlib_ImageConvCopyEdge_Bit(dst, src, dx_l, dx_r, dy_t, dy_b, cmask);
|
|
144 |
case MLIB_BYTE:
|
|
145 |
EDGES(channel, mlib_u8, cmask)
|
|
146 |
break;
|
|
147 |
case MLIB_SHORT:
|
|
148 |
case MLIB_USHORT:
|
|
149 |
EDGES(channel, mlib_u16, cmask)
|
|
150 |
break;
|
|
151 |
case MLIB_INT:
|
|
152 |
case MLIB_FLOAT:
|
|
153 |
EDGES(channel, mlib_u32, cmask)
|
|
154 |
break;
|
|
155 |
case MLIB_DOUBLE:
|
|
156 |
EDGES(channel, mlib_d64, cmask)
|
|
157 |
break;
|
|
158 |
default:
|
|
159 |
return MLIB_FAILURE;
|
|
160 |
}
|
|
161 |
|
|
162 |
return MLIB_SUCCESS;
|
|
163 |
}
|
|
164 |
|
|
165 |
/***************************************************************/
|