oakdecode.c
来自「Linux下的无线网卡通用驱动程序」· C语言 代码 · 共 644 行 · 第 1/2 页
C
644 行
switch (hdr.type) { case 0x0d: // first record rc = fread(&hdr0d, len = sizeof(hdr0d), 1, fp); if (rc != 1) goto out; curOff += len; printf(" %x %s", hdr0d.unk, hdr0d.string); break; case 0x0c: // time rc = fread(&hdr0c, len = sizeof(hdr0c), 1, fp); if (rc != 1) goto out; curOff += len; p = strchr(hdr0c.datetime, '\n'); if (p) *p = 0; printf(" %s", hdr0c.datetime); printf(", %d", hdr0c.time_t); printf(", %d/%02d/%02d %02d:%02d:%02d", hdr0c.year, hdr0c.tm_mon+1, hdr0c.tm_mday, hdr0c.tm_hour, hdr0c.tm_min, hdr0c.tm_sec); break; case 0x0a: // filename printf(" "); curOff += size; while (size--) { c = fgetc(fp); if (c == EOF) break; else if (c) putchar(c); else break; } while (size--) fgetc(fp); break; case 0x14: printf(" (no args)"); ++pageNum; curOff += size; while (size--) fgetc(fp); break; case 0x28: rc = fread(dwords, len = 1*4, 1, fp); if (rc != 1) goto out; curOff += len; switch (dwords[0]) { case 1: printf(" Source=Tray1"); break; case 4: printf(" Source=ManualFeed"); break; case 7: printf(" Source=Auto"); break; default: printf(" Source=%d", dwords[0]); break; } break; case 0x29: rc = fread(bytes, len = 17*4, 1, fp); if (rc != 1) goto out; curOff += len; printf(" PaperType=%d UNK8=%d,%d,%d,%d, blanks(63)", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4]); // PaperType: 0=AutoSelect, 1=Plain, 2=Preprinted, 3=Letterhead // 4=GrayscaleTransparency, 5=Prepunched, 6=Labels, 7=Bond // 8=Recycled, 9=Color, 10=Cardstock, 11=Heavy, 12=Envelope // 13=Light, 14=Tough break; case 0x2a: rc = fread(dwords, len = 5*4, 1, fp); if (rc != 1) goto out; curOff += len; printf(" Copies=%x UNK=%x", dwords[0], dwords[1]); break; case 0x2b: rc = fread(dwords, len = 5*4, 1, fp); if (rc != 1) goto out; curOff += len; printf(" papercode=%x", dwords[0]); printf(" xwid=%d", dwords[1]); printf(" ywid=%d", dwords[2]); printf(" UNK=%x", dwords[3]); break; case 0x32: firstPlane = 0; goto prplanes; case 0x33: firstPlane = 3; prplanes: printf("\n\tu0 u1 w h resx resy nBits"); for (i = firstPlane; i < 4; ++i) { rc = fread(&hdr3x[i], len = sizeof(HDR_3X), 1, fp); if (rc != 1) goto out; curOff += len; size -= len; printf("\n\tx%x\tx%x\t%d\t%d\t%d\t%d\tx%x", hdr3x[i].unk0, hdr3x[i].unk1, hdr3x[i].w, hdr3x[i].h, hdr3x[i].resx, hdr3x[i].resy, hdr3x[i].nbits); } curOff += size; while (size-- > 0) fgetc(fp); break; case 0x15: printf(" (no args)"); curOff += size; while (size--) fgetc(fp); break; case 0x3c: // rc = fread(dwords, len = 48, 1, fp); rc = fread(&hdr3c, len = sizeof(hdr3c), 1, fp); if (rc != 1) { debug(0, "Short read of hdr3c\n"); goto out; } curOff += len; plane = hdr3c.plane; subplane = hdr3c.subplane; if (!SupressImage || !ImageRec[plane]) { printf( "\t%08x %4d %4d %4d %08x %5d %5d %03x %4d %d %d\n", hdr3c.bih.opt1, hdr3c.bih.xd, hdr3c.bih.yd, hdr3c.bih.l0, hdr3c.bih.opt2, hdr3c.datalen, hdr3c.padlen, hdr3c.unk1C, hdr3c.y, hdr3c.plane, hdr3c.subplane); } if (RawFile && !FpRaw[plane][subplane]) { sprintf(buf, "%s-%02d-%d-%d.jbg", RawFile, pageNum, plane, subplane); FpRaw[plane][subplane] = fopen(buf, "w"); } if (DecFile && !FpDec[plane][subplane]) { height[plane][subplane] = 0; sprintf(buf, "%s-%02d-%d-%d.pbm", DecFile, pageNum, plane, subplane); FpDec[plane][subplane] = fopen(buf, "w"); fprintf(FpDec[plane][subplane], "P4\n%8d %8d\n", 0, 0); } if (FpDec[plane][subplane]) jbg_dec_init(&s[plane][subplane]); if (1||hdr3c.subplane == 0) { static int testend = 1; static char *cp = (char *) &testend; static int first_bih = 1; // JBIGKIT is bigendian, Oak is little-endian // swap the BIH header words before passing it to // jbig-kit. N.B. - is there any issues with endianess // inside the compressed stream itself???? if (*cp == 1) { swap32(&hdr3c.bih.xd); swap32(&hdr3c.bih.yd); swap32(&hdr3c.bih.l0); } if (!SupressImage || !ImageRec[plane]) if (first_bih) { first_bih = 0; print_bih((unsigned char *) &hdr3c); } if (0 && *cp == 1) { swap32(&hdr3c.bih.xd); swap32(&hdr3c.bih.yd); swap32(&hdr3c.bih.l0); } if (FpRaw[plane][subplane]) fwrite(&hdr3c.bih, 1, 20, FpRaw[plane][subplane]); if (FpDec[plane][subplane]) { rc = jbg_dec_in(&s[plane][subplane], (unsigned char *)&hdr3c.bih, 20, &cnt); } } ImageRec[plane]++; // image data if (!hdr3c.padlen) break; size = hdr3c.datalen; ibuf = malloc(size); rc = fread(ibuf, 1, size, fp); if (rc <= 0) break; curOff += size; if (FpRaw[plane][subplane]) fwrite(ibuf, 1, size, FpRaw[plane][subplane]); if (FpDec[plane][subplane]) { unsigned char *image; rc = JBG_EAGAIN; p = ibuf; while (size > 0 && (rc == JBG_EAGAIN || rc == JBG_EOK)) { rc = jbg_dec_in(&s[plane][subplane], (unsigned char *) p, size, &cnt); p += cnt; size -= cnt; } if (rc) debug(0, "rc= %d size=%d\n", rc, size); height[plane][subplane] += jbg_dec_getheight(&s[plane][subplane]); width[plane][subplane] = jbg_dec_getwidth(&s[plane][subplane]); image = jbg_dec_getimage(&s[plane][subplane], 0); if (image) fwrite(image, 1, jbg_dec_getsize(&s[plane][subplane]), FpDec[plane][subplane]); else debug(0, "Missing image p=%d/%d %dx%d!\n", plane, subplane, jbg_dec_getwidth(&s[plane][subplane]), jbg_dec_getheight(&s[plane][subplane])); jbg_dec_free(&s[plane][subplane]); } free(ibuf); size = hdr3c.padlen - hdr3c.datalen; curOff += size; while (size--) c = fgetc(fp); continue; case 0x17: printf(" (no args)"); for (i = 0; i < 4; ++i) { for (j = 0; j < 2; ++j) { if (FpRaw[i][j]) { fclose(FpRaw[i][j]); FpRaw[i][j] = NULL; } if (FpDec[i][j]) { fseek(FpDec[i][j], 0, 0); fprintf(FpDec[i][j], "P4\n%8d %8d\n", width[i][j], height[i][j]); fclose(FpDec[i][j]); FpDec[i][j] = NULL; } } } while (size--) fgetc(fp); break; case 0x18: rc = fread(words, len = (1+1)*2, 1, fp); if (rc != 1) goto out; curOff += len; printf(" UNK=%x", words[0]); break; case 0x0b: printf(" (no args)"); curOff += size; while (size--) fgetc(fp); break; default: curOff += size; while (size--) fgetc(fp); } printf("\n"); }out: return;}intmain(int argc, char *argv[]){ extern int optind; extern char *optarg; int c; while ( (c = getopt(argc, argv, "d:ior:D:?h")) != EOF) switch (c) { case 'd': DecFile = optarg; break; case 'r': RawFile = optarg; break; case 'i': SupressImage = 1; break; case 'o': PrintOffset = 1; break; case 'D': Debug = atoi(optarg); break; default: usage(); exit(1); } argc -= optind; argv += optind; decode(stdin); exit(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?