45 #include <config_auto.h>
49 #include "allheaders.h"
52 static l_uint16 * makeExpandTab2x(
void);
53 static l_uint32 * makeExpandTab4x(
void);
54 static l_uint32 * makeExpandTab8x(
void);
55 static l_uint32 expandtab16[] = {
56 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff};
74 l_int32 w, h, d, wd, hd, wpls, wpld, i, j, k, start;
75 l_uint32 *datas, *datad, *lines, *lined;
78 PROCNAME(
"pixExpandBinaryReplicate");
81 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
84 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
85 if (xfact <= 0 || yfact <= 0)
86 return (
PIX *)ERROR_PTR(
"invalid scale factor: <= 0", procName, NULL);
91 if (xfact == 2 || xfact == 4 || xfact == 8 || xfact == 16)
95 wpls = pixGetWpl(pixs);
99 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
100 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
101 pixCopyResolution(pixd, pixs);
102 pixScaleResolution(pixd, (l_float32)xfact, (l_float32)yfact);
103 wpld = pixGetWpl(pixd);
106 for (i = 0; i < h; i++) {
107 lines = datas + i * wpls;
108 lined = datad + yfact * i * wpld;
109 for (j = 0; j < w; j++) {
112 for (k = 0; k < xfact; k++)
116 for (k = 1; k < yfact; k++)
117 memcpy(lined + k * wpld, lined, 4 * wpld);
140 l_int32 i, j, k, w, h, d, wd, hd, wpls, wpld, sdibits, sqbits, sbytes;
141 l_uint32 *datas, *datad, *lines, *lined, *tab4, *tab8;
144 PROCNAME(
"pixExpandBinaryPower2");
147 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
150 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
153 if (factor != 2 && factor != 4 && factor != 8 && factor != 16)
154 return (
PIX *)ERROR_PTR(
"factor must be in {2,4,8,16}", procName, NULL);
156 wpls = pixGetWpl(pixs);
160 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
161 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
162 pixCopyResolution(pixd, pixs);
163 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
164 wpld = pixGetWpl(pixd);
167 tab2 = makeExpandTab2x();
168 sbytes = (w + 7) / 8;
169 for (i = 0; i < h; i++) {
170 lines = datas + i * wpls;
171 lined = datad + 2 * i * wpld;
172 for (j = 0; j < sbytes; j++) {
176 memcpy(lined + wpld, lined, 4 * wpld);
179 }
else if (factor == 4) {
180 tab4 = makeExpandTab4x();
181 sbytes = (w + 7) / 8;
182 for (i = 0; i < h; i++) {
183 lines = datas + i * wpls;
184 lined = datad + 4 * i * wpld;
185 for (j = 0; j < sbytes; j++) {
187 lined[j] = tab4[sval];
189 for (k = 1; k < 4; k++)
190 memcpy(lined + k * wpld, lined, 4 * wpld);
193 }
else if (factor == 8) {
194 tab8 = makeExpandTab8x();
195 sqbits = (w + 3) / 4;
196 for (i = 0; i < h; i++) {
197 lines = datas + i * wpls;
198 lined = datad + 8 * i * wpld;
199 for (j = 0; j < sqbits; j++) {
201 lined[j] = tab8[sval];
203 for (k = 1; k < 8; k++)
204 memcpy(lined + k * wpld, lined, 4 * wpld);
208 sdibits = (w + 1) / 2;
209 for (i = 0; i < h; i++) {
210 lines = datas + i * wpls;
211 lined = datad + 16 * i * wpld;
212 for (j = 0; j < sdibits; j++) {
214 lined[j] = expandtab16[sval];
216 for (k = 1; k < 16; k++)
217 memcpy(lined + k * wpld, lined, 4 * wpld);
229 makeExpandTab2x(
void)
234 tab = (l_uint16 *) LEPT_CALLOC(256,
sizeof(l_uint16));
235 for (i = 0; i < 256; i++) {
258 makeExpandTab4x(
void)
263 tab = (l_uint32 *) LEPT_CALLOC(256,
sizeof(l_uint32));
264 for (i = 0; i < 256; i++) {
280 tab[i] |= 0xf0000000;
287 makeExpandTab8x(
void)
292 tab = (l_uint32 *) LEPT_CALLOC(16,
sizeof(l_uint32));
293 for (i = 0; i < 16; i++) {
301 tab[i] |= 0xff000000;
#define GET_DATA_QBIT(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define GET_DATA_BIT(pdata, n)
PIX * pixExpandBinaryReplicate(PIX *pixs, l_int32 xfact, l_int32 yfact)
pixExpandBinaryReplicate()
PIX * pixExpandBinaryPower2(PIX *pixs, l_int32 factor)
pixExpandBinaryPower2()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()