📄 foo2oak.c
字号:
reccopies.unk = 0; // TODO oak_record(ofp, OAK_TYPE_COPIES, &reccopies, sizeof(reccopies)); recpaper.paper = PaperCode; recpaper.w1200 = PageWidth * 1200 / ResX; recpaper.h1200 = PageHeight * 1200 / ResY; recpaper.unk = 0; // TODO oak_record(ofp, OAK_TYPE_PAPER, &recpaper, sizeof(recpaper)); // image header (32/33) recmono.plane.unk0 = 0; recmono.plane.unk1 = 1; recmono.plane.w = w; // TODO recmono.plane.h = h; // TODO recmono.plane.resx = ResX; recmono.plane.resy = ResY; recmono.plane.nbits = 1; fill_image_plane_unknown(&recmono.plane); oak_record(ofp, OAK_TYPE_IMAGE_MONO, &recmono, sizeof(recmono)); oak_record(ofp, OAK_TYPE_START_IMAGE, NULL, 0); // // Mirror the bits in the image // for (y = 0; y < h; ++y) mirror_bytes(buf + y*bpl, bpl, Mirror1); // // Output the image stripes // #define N 256 for (y = 0; y < h; y += N) { struct jbg_enc_state se; unsigned char *bitmaps[1]; BIE_CHAIN *chain; BIE_CHAIN *current; OAK_IMAGE_DATA recdata; int chainlen; int padlen; static char pad[] = "PAD_PAD_PAD_PAD_"; int lines = (h-y) > N ? N : (h-y); bitmaps[0] = buf + y * ((w+7)/8); chain = NULL; memset(&recdata.bih, 0, sizeof(recdata.bih)); recdata.datalen = 0; recdata.padlen = 0; recdata.unk1C = 0; // TODO recdata.y = y; recdata.plane = 3; //K recdata.subplane = 0; if (lines < N) JbgOptions[2] = lines; else JbgOptions[2] = N; jbg_enc_init(&se, w, lines, 1, bitmaps, output_jbig, &chain); jbg_enc_options(&se, JbgOptions[0], JbgOptions[1], JbgOptions[2], JbgOptions[3], JbgOptions[4]); jbg_enc_out(&se); jbg_enc_free(&se); if (chain->len != 20) error(1, "Program error: missing BIH at start of chain\n"); chainlen = 0; for (current = chain->next; current; current = current->next) chainlen += current->len; // Copy in the BIH memcpy(&recdata.bih, chain->data, sizeof(recdata.bih)); // Oak is little-endian, but JBIG-kit is big-endian swap32(&recdata.bih.xd); swap32(&recdata.bih.yd); swap32(&recdata.bih.l0); recdata.datalen = chainlen; recdata.padlen = (recdata.datalen + 15) & ~0x0f; oak_record(ofp, OAK_TYPE_IMAGE_DATA, &recdata, sizeof(recdata)); for (current = chain->next; current; current = current->next) fwrite(current->data, 1, current->len, ofp); padlen = recdata.padlen - recdata.datalen; fwrite(pad, 1, padlen, ofp); free_chain(chain); } oak_record(ofp, OAK_TYPE_END_IMAGE, NULL, 0); endpage_arg = 0; // Mono oak_record(ofp, OAK_TYPE_END_PAGE, &endpage_arg, sizeof(endpage_arg)); return 0;}intpgm_page(unsigned char *raw, int w, int h, FILE *ofp){ WORD endpage_arg; DWORD source_arg; OAK_MEDIA recmedia; OAK_COPIES reccopies; OAK_PAPER recpaper; OAK_IMAGE_MONO recmono; int sub; int y; int bpl = (w+7)/8; unsigned char *subplane[2]; for (sub = 0; sub < 2 ; ++sub) { subplane[sub] = malloc(bpl * h); if (!subplane[sub]) error(3, "Cannot allocate space for subplane\n"); } pgm_subplanes(subplane, raw, w, h); oak_record(ofp, OAK_TYPE_START_PAGE, NULL, 0); // TODO: page parms source_arg = SourceCode; oak_record(ofp, OAK_TYPE_SOURCE, &source_arg, sizeof(source_arg)); recmedia.media = MediaCode; recmedia.unk8[0] = 2; // TODO recmedia.unk8[1] = 0; // TODO recmedia.unk8[2] = 0; // TODO memset(recmedia.string, ' ', sizeof(recmedia.string)); strcpy(recmedia.string, ""); // TODO oak_record(ofp, OAK_TYPE_MEDIA, &recmedia, sizeof(recmedia)); reccopies.copies = Copies; reccopies.unk = 0; // TODO oak_record(ofp, OAK_TYPE_COPIES, &reccopies, sizeof(reccopies)); recpaper.paper = PaperCode; recpaper.w1200 = PageWidth * 1200 / ResX; recpaper.h1200 = PageHeight * 1200 / ResY; recpaper.unk = 0; // TODO oak_record(ofp, OAK_TYPE_PAPER, &recpaper, sizeof(recpaper)); // image header (32/33) recmono.plane.unk0 = 0; recmono.plane.unk1 = 0; recmono.plane.w = w; recmono.plane.h = h; recmono.plane.resx = ResX; recmono.plane.resy = ResY; recmono.plane.nbits = 2; fill_image_plane_unknown(&recmono.plane); oak_record(ofp, OAK_TYPE_IMAGE_MONO, &recmono, sizeof(recmono)); oak_record(ofp, OAK_TYPE_START_IMAGE, NULL, 0); // // Mirror the bits in the image // // TODO: combine this operation with pgm_subplanes // for (sub = 0; sub < 2; ++sub) for (y = 0; y < h; ++y) mirror_bytes(subplane[sub] + y*bpl, bpl, Mirror1); // // Output the image stripes // #define N 256 for (y = 0; y < h; y += N) { struct jbg_enc_state se; unsigned char *bitmaps[1]; BIE_CHAIN *chain; BIE_CHAIN *current; OAK_IMAGE_DATA recdata; int chainlen; int padlen; static char pad[] = "PAD_PAD_PAD_PAD_"; int lines = (h-y) > N ? N : (h-y); for (sub = 0; sub < 2; ++sub) { bitmaps[0] = subplane[sub] + y * ((w+7)/8); chain = NULL; memset(&recdata.bih, 0, sizeof(recdata.bih)); recdata.datalen = 0; recdata.padlen = 0; recdata.unk1C = 0; // TODO recdata.y = y; recdata.plane = 3; //K recdata.subplane = sub; if (lines < N) JbgOptions[2] = lines; else JbgOptions[2] = N; jbg_enc_init(&se, w, lines, 1, bitmaps, output_jbig, &chain); jbg_enc_options(&se, JbgOptions[0], JbgOptions[1], JbgOptions[2], JbgOptions[3], JbgOptions[4]); jbg_enc_out(&se); jbg_enc_free(&se); if (chain->len != 20) error(1, "Program error: missing BIH at start of chain\n"); chainlen = 0; for (current = chain->next; current; current = current->next) chainlen += current->len; // Copy in the BIH memcpy(&recdata.bih, chain->data, sizeof(recdata.bih)); // Oak is little-endian, but JBIG-kit is big-endian swap32(&recdata.bih.xd); swap32(&recdata.bih.yd); swap32(&recdata.bih.l0); recdata.datalen = chainlen; recdata.padlen = (recdata.datalen + 15) & ~0x0f; oak_record(ofp, OAK_TYPE_IMAGE_DATA, &recdata, sizeof(recdata)); for (current = chain->next; current; current = current->next) fwrite(current->data, 1, current->len, ofp); padlen = recdata.padlen - recdata.datalen; fwrite(pad, 1, padlen, ofp); free_chain(chain); } } for (sub = 0; sub < 2; ++sub) free(subplane[sub]); oak_record(ofp, OAK_TYPE_END_IMAGE, NULL, 0); endpage_arg = 0; oak_record(ofp, OAK_TYPE_END_PAGE, &endpage_arg, sizeof(endpage_arg)); return 0;}intcups_page(unsigned char *raw, int w, int h, FILE *ofp){ WORD endpage_arg; DWORD source_arg; OAK_MEDIA recmedia; OAK_COPIES reccopies; OAK_PAPER recpaper; OAK_IMAGE_MONO recmono; OAK_IMAGE_COLOR reccolor; int p, p0, p3; int sub; int y; int bpl = (w+7)/8; unsigned char *plane[4][2]; if (Color2Mono) p0 = p3 = Color2Mono - 1; else { p0 = 0; p3 = 3; } for (p = p0; p <= p3 ; ++p) { for (sub = 0; sub < 2 ; ++sub) { plane[p][sub] = malloc(bpl * h); if (!plane[p][sub]) error(3, "Cannot allocate space for bit plane\n"); } } cups_planes(plane, raw, w, h); oak_record(ofp, OAK_TYPE_START_PAGE, NULL, 0); // TODO: page parms source_arg = SourceCode; oak_record(ofp, OAK_TYPE_SOURCE, &source_arg, sizeof(source_arg)); recmedia.media = MediaCode; recmedia.unk8[0] = 2; // TODO recmedia.unk8[1] = 0; // TODO recmedia.unk8[2] = 0; // TODO memset(recmedia.string, ' ', sizeof(recmedia.string)); strcpy(recmedia.string, ""); // TODO oak_record(ofp, OAK_TYPE_MEDIA, &recmedia, sizeof(recmedia)); reccopies.copies = Copies; reccopies.unk = 0; // TODO oak_record(ofp, OAK_TYPE_COPIES, &reccopies, sizeof(reccopies)); recpaper.paper = PaperCode; recpaper.w1200 = PageWidth * 1200 / ResX; recpaper.h1200 = PageHeight * 1200 / ResY; recpaper.unk = 0; // TODO oak_record(ofp, OAK_TYPE_PAPER, &recpaper, sizeof(recpaper)); // image header (32/33) if (p0 == p3) { recmono.plane.unk0 = 0; recmono.plane.unk1 = 0; recmono.plane.w = w; // TODO recmono.plane.h = h; // TODO recmono.plane.resx = ResX; recmono.plane.resy = ResY; recmono.plane.nbits = 2; fill_image_plane_unknown(&recmono.plane); oak_record(ofp, OAK_TYPE_IMAGE_MONO, &recmono, sizeof(recmono)); } else { for (p = p0; p <= p3; ++p) { reccolor.plane[p].unk0 = 0; reccolor.plane[p].unk1 = 0; reccolor.plane[p].w = w; // TODO reccolor.plane[p].h = h; // TODO reccolor.plane[p].resx = ResX; reccolor.plane[p].resy = ResY; reccolor.plane[p].nbits = 2; fill_image_plane_unknown(&reccolor.plane[p]); } oak_record(ofp, OAK_TYPE_IMAGE_COLOR, &reccolor, sizeof(reccolor)); } oak_record(ofp, OAK_TYPE_START_IMAGE, NULL, 0); // // Mirror the bits in the image // // TODO: combine this operation with cups_planes // for (p = p0; p <= p3; ++p) for (sub = 0; sub < 2; ++sub) for (y = 0; y < h; ++y) mirror_bytes(plane[p][sub] + y*bpl, bpl, Mirror1); // // Output the image stripes // #define N 256 for (y = 0; y < h; y += N) { struct jbg_enc_state se; unsigned char *bitmaps[1]; BIE_CHAIN *chain; BIE_CHAIN *current; OAK_IMAGE_DATA recdata; int chainlen; int padlen; static char pad[] = "PAD_PAD_PAD_PAD_"; int lines = (h-y) > N ? N : (h-y); for (p = p0; p <= p3; ++p) { for (sub = 0; sub < 2; ++sub) { bitmaps[0] = plane[p][sub] + y * ((w+7)/8); chain = NULL; memset(&recdata.bih, 0, sizeof(recdata.bih)); recdata.datalen = 0; recdata.padlen = 0; recdata.unk1C = 0; // TODO recdata.y = y; recdata.plane = p; recdata.subplane = sub; if (lines < N) JbgOptions[2] = lines; else JbgOptions[2] = N; jbg_enc_init(&se, w, lines, 1, bitmaps, output_jbig, &chain); jbg_enc_options(&se, JbgOptions[0], JbgOptions[1], JbgOptions[2], JbgOptions[3], JbgOptions[4]); jbg_enc_out(&se); jbg_enc_free(&se); if (chain->len != 20) error(1, "Program error: missing BIH at start of chain\n"); chainlen = 0; for (current = chain->next; current; current = current->next) chainlen += current->len; // Copy in the BIH memcpy(&recdata.bih, chain->data, sizeof(recdata.bih)); // Oak is little-endian, but JBIG-kit is big-endian swap32(&recdata.bih.xd); swap32(&recdata.bih.yd); swap32(&recdata.bih.l0); recdata.datalen = chainlen; recdata.padlen = (recdata.datalen + 15) & ~0x0f; oak_record(ofp, OAK_TYPE_IMAGE_DATA, &recdata, sizeof(recdata)); for (current = chain->next; current; current = current->next) fwrite(current->data, 1, current->len, ofp); padlen = recdata.padlen - recdata.datalen; fwrite(pad, 1, padlen, ofp); free_chain(chain); } } } for (p = p0; p <= p3; ++p) for (sub = 0; sub < 2; ++sub) free(plane[p][sub]); oak_record(ofp, OAK_TYPE_END_IMAGE, NULL, 0); endpage_arg = 0; oak_record(ofp, OAK_TYPE_END_PAGE, &endpage_arg, sizeof(endpage_arg)); return 0;}intread_and_clip_image(unsigned char *buf, int rawBpl, int rightBpl, int pixelsPerByte, int bpl, int h, FILE *ifp){ unsigned char *rowbuf, *rowp; int y; int rc; debug(1, "read_and_clip_image: rawBpl=%d, rightBpl=%d, pixelsePerByte=%d\n", rawBpl, rightBpl, pixelsPerByte); debug(1, "read_and_clip_image: bpl=%d, h=%d\n", bpl, h); debug(1, "read_and_clip_image: clipleft=%d data=%d clipright=%d\n", UpperLeftX/pixelsPerByte, bpl, rightBpl - bpl); rowbuf = malloc(rawBpl); if (!rowbuf) error(1, "Can't allocate row buffer\n"); // Clip top rows if (UpperLeftY) { for (y = 0; y < UpperLeftY; ++y) { rc = fread(rowbuf, rawBpl, 1, ifp); if (rc == 0) goto eof; if (rc != 1) error(1, "Premature EOF(1) on input at y=%d\n", y); } } // Copy the rows that we want to image rowp = buf; for (y = 0; y < h; ++y, rowp += bpl) { // Clip left pixel *bytes* if (UpperLeftX) { rc = fread(rowbuf, UpperLeftX / pixelsPerByte, 1, ifp); if (rc == 0 && y == 0 && !UpperLeftY) goto eof; if (rc != 1) error(1, "Premature EOF(2) on input at y=%d\n", y); } rc = fread(rowp, bpl, 1, ifp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -