74l_int32 w, h, d, wd, hd, wpls, wpld, i, j, k, start;
75l_uint32 *datas, *datad, *lines, *lined;
79 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
80 pixGetDimensions(pixs, &w, &h, &d);
82 return (
PIX *)ERROR_PTR(
"pixs not binary", __func__, NULL);
83 if (xfact <= 0 || yfact <= 0)
84 return (
PIX *)ERROR_PTR(
"invalid scale factor: <= 0", __func__, NULL);
88 return pixCopy(NULL, pixs);
89 if (xfact == 2 || xfact == 4 || xfact == 8 || xfact == 16)
93 wpls = pixGetWpl(pixs);
94 datas = pixGetData(pixs);
97 if ((pixd = pixCreate(wd, hd, 1)) == NULL)
98 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
99 pixCopyResolution(pixd, pixs);
100 pixScaleResolution(pixd, (l_float32)xfact, (l_float32)yfact);
101 wpld = pixGetWpl(pixd);
102 datad = pixGetData(pixd);
104 for (i = 0; i < h; i++) {
105 lines = datas + i * wpls;
106 lined = datad + yfact * i * wpld;
107 for (j = 0; j < w; j++) {
110 for (k = 0; k < xfact; k++)
114 for (k = 1; k < yfact; k++)
115 memcpy(lined + k * wpld, lined, 4 * wpld);
138l_int32 i, j, k, w, h, d, wd, hd, wpls, wpld, sdibits, sqbits, sbytes;
139l_uint32 *datas, *datad, *lines, *lined, *tab4, *tab8;
143 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
144 pixGetDimensions(pixs, &w, &h, &d);
146 return (
PIX *)ERROR_PTR(
"pixs not binary", __func__, NULL);
148 return pixCopy(NULL, pixs);
149 if (factor != 2 && factor != 4 && factor != 8 && factor != 16)
150 return (
PIX *)ERROR_PTR(
"factor must be in {2,4,8,16}", __func__, NULL);
152 wpls = pixGetWpl(pixs);
153 datas = pixGetData(pixs);
156 if ((pixd = pixCreate(wd, hd, 1)) == NULL)
157 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
158 pixCopyResolution(pixd, pixs);
159 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
160 wpld = pixGetWpl(pixd);
161 datad = pixGetData(pixd);
163 tab2 = makeExpandTab2x();
164 sbytes = (w + 7) / 8;
165 for (i = 0; i < h; i++) {
166 lines = datas + i * wpls;
167 lined = datad + 2 * i * wpld;
168 for (j = 0; j < sbytes; j++) {
172 memcpy(lined + wpld, lined, 4 * wpld);
175 }
else if (factor == 4) {
176 tab4 = makeExpandTab4x();
177 sbytes = (w + 7) / 8;
178 for (i = 0; i < h; i++) {
179 lines = datas + i * wpls;
180 lined = datad + 4 * i * wpld;
181 for (j = 0; j < sbytes; j++) {
183 lined[j] = tab4[sval];
185 for (k = 1; k < 4; k++)
186 memcpy(lined + k * wpld, lined, 4 * wpld);
189 }
else if (factor == 8) {
190 tab8 = makeExpandTab8x();
191 sqbits = (w + 3) / 4;
192 for (i = 0; i < h; i++) {
193 lines = datas + i * wpls;
194 lined = datad + 8 * i * wpld;
195 for (j = 0; j < sqbits; j++) {
197 lined[j] = tab8[sval];
199 for (k = 1; k < 8; k++)
200 memcpy(lined + k * wpld, lined, 4 * wpld);
204 sdibits = (w + 1) / 2;
205 for (i = 0; i < h; i++) {
206 lines = datas + i * wpls;
207 lined = datad + 16 * i * wpld;
208 for (j = 0; j < sdibits; j++) {
210 lined[j] = expandtab16[sval];
212 for (k = 1; k < 16; k++)
213 memcpy(lined + k * wpld, lined, 4 * wpld);