45 #include "allheaders.h" 48 static l_uint16 * makeExpandTab2x(
void);
49 static l_uint32 * makeExpandTab4x(
void);
50 static l_uint32 * makeExpandTab8x(
void);
51 static l_uint32 expandtab16[] = {
52 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff};
71 l_int32 w, h, d, wd, hd, wpls, wpld, i, j, k, start;
72 l_uint32 *datas, *datad, *lines, *lined;
75 PROCNAME(
"pixExpandBinaryReplicate");
78 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
81 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
82 if (xfact <= 0 || yfact <= 0)
83 return (
PIX *)ERROR_PTR(
"invalid scale factor: <= 0", procName, NULL);
88 if (xfact == 2 || xfact == 4 || xfact == 8 || xfact == 16)
92 wpls = pixGetWpl(
pixs);
96 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
97 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
98 pixCopyResolution(pixd,
pixs);
99 pixScaleResolution(pixd, (l_float32)xfact, (l_float32)yfact);
100 wpld = pixGetWpl(pixd);
103 for (i = 0; i < h; i++) {
104 lines = datas + i * wpls;
105 lined = datad + yfact * i * wpld;
106 for (j = 0; j < w; j++) {
109 for (k = 0; k < xfact; k++)
113 for (k = 1; k < yfact; k++)
114 memcpy(lined + k * wpld, lined, 4 * wpld);
137 l_int32 i, j, k, w, h, d, wd, hd, wpls, wpld, sdibits, sqbits, sbytes;
138 l_uint32 *datas, *datad, *lines, *lined, *tab4, *tab8;
141 PROCNAME(
"pixExpandBinaryPower2");
144 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
147 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
150 if (factor != 2 && factor != 4 && factor != 8 && factor != 16)
151 return (
PIX *)ERROR_PTR(
"factor must be in {2,4,8,16}", procName, NULL);
153 wpls = pixGetWpl(
pixs);
157 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
158 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
159 pixCopyResolution(pixd,
pixs);
160 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
161 wpld = pixGetWpl(pixd);
164 tab2 = makeExpandTab2x();
165 sbytes = (w + 7) / 8;
166 for (i = 0; i < h; i++) {
167 lines = datas + i * wpls;
168 lined = datad + 2 * i * wpld;
169 for (j = 0; j < sbytes; j++) {
173 memcpy(lined + wpld, lined, 4 * wpld);
176 }
else if (factor == 4) {
177 tab4 = makeExpandTab4x();
178 sbytes = (w + 7) / 8;
179 for (i = 0; i < h; i++) {
180 lines = datas + i * wpls;
181 lined = datad + 4 * i * wpld;
182 for (j = 0; j < sbytes; j++) {
184 lined[j] = tab4[sval];
186 for (k = 1; k < 4; k++)
187 memcpy(lined + k * wpld, lined, 4 * wpld);
190 }
else if (factor == 8) {
191 tab8 = makeExpandTab8x();
192 sqbits = (w + 3) / 4;
193 for (i = 0; i < h; i++) {
194 lines = datas + i * wpls;
195 lined = datad + 8 * i * wpld;
196 for (j = 0; j < sqbits; j++) {
199 L_WARNING(
"sval = %d; should be < 16\n", procName, sval);
200 lined[j] = tab8[sval];
202 for (k = 1; k < 8; k++)
203 memcpy(lined + k * wpld, lined, 4 * wpld);
207 sdibits = (w + 1) / 2;
208 for (i = 0; i < h; i++) {
209 lines = datas + i * wpls;
210 lined = datad + 16 * i * wpld;
211 for (j = 0; j < sdibits; j++) {
213 lined[j] = expandtab16[sval];
215 for (k = 1; k < 16; k++)
216 memcpy(lined + k * wpld, lined, 4 * wpld);
228 makeExpandTab2x(
void)
233 PROCNAME(
"makeExpandTab2x");
235 if ((tab = (l_uint16 *) LEPT_CALLOC(256,
sizeof(l_uint16))) == NULL)
236 return (l_uint16 *)ERROR_PTR(
"tab not made", procName, NULL);
238 for (i = 0; i < 256; i++) {
262 makeExpandTab4x(
void)
267 PROCNAME(
"makeExpandTab4x");
269 if ((tab = (l_uint32 *) LEPT_CALLOC(256,
sizeof(l_uint32))) == NULL)
270 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
272 for (i = 0; i < 256; i++) {
288 tab[i] |= 0xf0000000;
296 makeExpandTab8x(
void)
301 PROCNAME(
"makeExpandTab8x");
303 if ((tab = (l_uint32 *) LEPT_CALLOC(16,
sizeof(l_uint32))) == NULL)
304 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
306 for (i = 0; i < 16; i++) {
314 tab[i] |= 0xff000000;
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
#define GET_DATA_BIT(pdata, n)
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_BYTE(pdata, n)
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
#define GET_DATA_DIBIT(pdata, n)
PIX * pixExpandBinaryPower2(PIX *pixs, l_int32 factor)
pixExpandBinaryPower2()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define SET_DATA_BIT(pdata, n)
PIX * pixExpandBinaryReplicate(PIX *pixs, l_int32 xfact, l_int32 yfact)
pixExpandBinaryReplicate()