MDJVU_IMPLEMENT void mdjvu_bitmap_unpack_all_0_or_1 (mdjvu_bitmap_t b, unsigned char **data) { int32 i = 0, h = BMP->height; for (i = 0; i < h; i++) { mdjvu_bitmap_unpack_row_0_or_1(b, data[i], i); } }
MDJVU_IMPLEMENT mdjvu_bitmap_t mdjvu_get_erosion_mask(mdjvu_bitmap_t bmp) { int32 w = mdjvu_bitmap_get_width(bmp); int32 h = mdjvu_bitmap_get_height(bmp); mdjvu_bitmap_t result = mdjvu_bitmap_create(w, h); int32 i; unsigned char *u, *t, *l, *r; if (h < 3) return result; u = (unsigned char *) malloc(w); /* upper row */ t = (unsigned char *) malloc(w); /* this row */ l = (unsigned char *) malloc(w); /* lower row */ r = (unsigned char *) malloc(w); /* result */ mdjvu_bitmap_unpack_row_0_or_1(bmp, t, 0); mdjvu_bitmap_unpack_row_0_or_1(bmp, l, 1); for (i = 1; i < h - 1; i++) { unsigned char *tmp = u; u = t; t = l; l = tmp; mdjvu_bitmap_unpack_row_0_or_1(bmp, l, i + 1); get_erosion_candidates_in_a_row(r, u, t, l, w); mdjvu_bitmap_pack_row(result, r, i); } free(u); free(t); free(l); free(r); return result; }
MDJVU_IMPLEMENT void mdjvu_smooth(mdjvu_bitmap_t b) { int32 w = mdjvu_bitmap_get_width(b); int32 h = mdjvu_bitmap_get_height(b); int32 i; unsigned char *u, *t, *l, *r; if (h < 3) return; u = (unsigned char *) calloc(w + 2, 1) + 1; /* upper row */ t = (unsigned char *) calloc(w + 2, 1) + 1; /* this row */ l = (unsigned char *) calloc(w + 2, 1) + 1; /* lower row */ r = (unsigned char *) malloc(w); /* result */ mdjvu_bitmap_unpack_row_0_or_1(b, l, 0); for (i = 0; i < h; i++) { unsigned char *tmp = u; u = t; t = l; l = tmp; if (i + 1 < h) mdjvu_bitmap_unpack_row_0_or_1(b, l, i + 1); else memset(l, 0, w); smooth_row(r, u, t, l, w); mdjvu_bitmap_pack_row(b, r, i); } free(u - 1); free(t - 1); free(l - 1); free(r); }