⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foo2oak.c

📁 Linux下的无线网卡通用驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    rectime.tm_min = tm->tm_min;    rectime.tm_sec = tm->tm_sec;    oak_record(fp, OAK_TYPE_TIME, &rectime, sizeof(rectime));    memset(&recfile, 0, sizeof(recfile));    strcpy(recfile.string, Filename ? Filename : "stdin");    oak_record(fp, OAK_TYPE_FILENAME, &recfile, sizeof(recfile));#if 0    chunk_write(ZJT_START_DOC, nitems, size, fp);    item_uint32_write(ZJI_DMCOLLATE, 0,		fp);    item_uint32_write(ZJI_DMDUPLEX,  Duplex,	fp);    item_uint32_write(ZJI_PAGECOUNT, 0,		fp);    item_uint32_write(ZJI_QUANTITY,  1,		fp);    // item_uint32_write(ZJI_QMS_FINEMODE,0,	fp);    // item_uint32_write(ZJI_QMS_OUTBIN,  1,	fp);    if (Username)	item_str_write(ZJI_MINOLTA_USERNAME, Username, fp);    if (Filename)	item_str_write(ZJI_MINOLTA_FILENAME, Filename, fp);#endif}voidend_doc(FILE *fp){    oak_record(fp, OAK_TYPE_END_DOC, NULL, 0);}voidcmyk_planes(unsigned char *plane[4], unsigned char *raw, int w, int h){    int			rawbpl = (w + 1) / 2;    int			bpl = (w + 7) / 8;    int			i;    int			x, y;    unsigned char	byte;    unsigned char	mask[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };    int			aib = AllIsBlack;    int			bc = BlackClears;    for (i = 0; i < 4; ++i)	memset(plane[i], 0, bpl * h);    //    // Unpack the combined plane into individual color planes    //    // TODO: this can be speeded up using a 256 or 65536 entry lookup table    //    for (y = 0; y < h; ++y)    {	for (x = 0; x < w; ++x)	{	    byte = raw[y*rawbpl + x/2];	    if (aib && (byte & 0xE0) == 0xE0)	    {		plane[PL_K][y*bpl + x/8] |= mask[x&7];	    }	    else if (byte & 0x10)	    {		plane[PL_K][y*bpl + x/8] |= mask[x&7];		if (!bc)		{		    if (byte & 0x80) plane[PL_C][y*bpl + x/8] |= mask[x&7];		    if (byte & 0x40) plane[PL_M][y*bpl + x/8] |= mask[x&7];		    if (byte & 0x20) plane[PL_Y][y*bpl + x/8] |= mask[x&7];		}	    }	    else	    {		if (byte & 0x80) plane[PL_C][y*bpl + x/8] |= mask[x&7];		if (byte & 0x40) plane[PL_M][y*bpl + x/8] |= mask[x&7];		if (byte & 0x20) plane[PL_Y][y*bpl + x/8] |= mask[x&7];	    }	    ++x;	    if (aib && (byte & 0x0E) == 0x0E)	    {		plane[PL_K][y*bpl + x/8] |= mask[x&7];	    }	    else if (byte & 0x1)	    {		plane[PL_K][y*bpl + x/8] |= mask[x&7];		if (!bc)		{		    if (byte & 0x8) plane[PL_C][y*bpl + x/8] |= mask[x&7];		    if (byte & 0x4) plane[PL_M][y*bpl + x/8] |= mask[x&7];		    if (byte & 0x2) plane[PL_Y][y*bpl + x/8] |= mask[x&7];		}	    }	    else	    {		if (byte & 0x8) plane[PL_C][y*bpl + x/8] |= mask[x&7];		if (byte & 0x4) plane[PL_M][y*bpl + x/8] |= mask[x&7];		if (byte & 0x2) plane[PL_Y][y*bpl + x/8] |= mask[x&7];	    }	}    }}voidpgm_subplanes(unsigned char *subplane[2], unsigned char *raw, int w, int h){    int			bpl = (w + 7) / 8;    int			x, y;    unsigned char	byte;    unsigned char	ormask[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };    unsigned char	andmask[8] = { 0x7f, ~64, ~32, ~16, ~8, ~4, ~2, ~1 };    double		*carry0, *carry1, *carrytmp;    double		sum;    static int		dir = 1;    int			xs, xe;static int cnt[4];int tot = 0;    // TODO: convert this to scaled integer arithmetic    carry0 = (double *) calloc((w+2), sizeof(*carry0));    if (!carry0)	error(1, "Could not allocate space for carries\n");    carry1 = (double *) calloc((w+2), sizeof(*carry0));    if (!carry1)	error(1, "Could not allocate space for carries\n");    ++carry0; ++carry1;    for (y = 0; y < h; ++y)    {	if (dir > 0)	    { dir = -1; xs = w-1; xe = -1; }	else	    { dir = 1; xs = 0; xe = w; }	for (x = xs; x != xe; x += dir)	{	    byte = 255 - raw[y*w + x];	    sum = byte + carry0[x];++tot;	    if (byte == 255 || sum >= 255)	    {	// Full black++cnt[2];		byte = 255;		subplane[1][y*bpl + x/8] |= ormask[x&7];		subplane[0][y*bpl + x/8] &= andmask[x&7];	    }	    else if (sum >= (70.0/100)*255)	    {	// Dark gray++cnt[3];		byte = 255;		subplane[1][y*bpl + x/8] |= ormask[x&7];		subplane[0][y*bpl + x/8] |= ormask[x&7];	    }	    else if (sum > 0)	    {	// Light gray++cnt[1];		byte = (40.0/100)*255;		subplane[1][y*bpl + x/8] &= andmask[x&7];		subplane[0][y*bpl + x/8] |= ormask[x&7];	    }	    else	    {	// Full white++cnt[0];		byte = 0;		subplane[1][y*bpl + x/8] &= andmask[x&7];		subplane[0][y*bpl + x/8] &= andmask[x&7];	    }	    // Compute the carry that must be distributed	    sum -= byte;	    carry0[x+dir] += (sum*7)/16.0;	    carry1[x-dir] += (sum*3)/16.0;	    carry1[x    ] += (sum*5)/16.0;	    carry1[x+dir] += (sum*1)/16.0;	}	// Advance carry buffers	carrytmp = carry0; carry0 = carry1; carry1 = carrytmp;	memset(carry1-1, 0, (w+2) * sizeof(*carry1));    }debug(1, "%d	%d %d %d %d\n", tot, cnt[3], cnt[2], cnt[1], cnt[0]);    free(--carry0); free(--carry1);}voidcups_planes(unsigned char *plane[4][2], unsigned char *raw, int w, int h){    int			bpl = (w + 7) / 8;    int			i, sub;    int			x, y;    unsigned char	byte;    unsigned char	mask[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };    int			aib = AllIsBlack;    int			bc = BlackClears;    // Whitewash all planes    for (i = 0; i < 4; ++i)	for (sub = 0; sub < 2; ++sub)	    memset(plane[i][sub], 0, bpl * h);    //    // Unpack the combined plane into individual color planes    //    // TODO: this can be speeded up using a 256 or 65536 entry lookup table    //    for (y = 0; y < h; ++y)    {	for (x = 0; x < w; ++x)	{	    byte = raw[y*w + x];	    if (aib && (byte & 0xfc) == 0xfc)	    {		plane[PL_K][1][y*bpl + x/8] |= mask[x&7];		plane[PL_K][0][y*bpl + x/8] |= mask[x&7];	    }	    else if (bc && (byte & 0x03) == 0x03)	    {		plane[PL_K][1][y*bpl + x/8] |= mask[x&7];		plane[PL_K][0][y*bpl + x/8] |= mask[x&7];	    }	    else	    {		if (byte & 128) plane[PL_C][1][y*bpl + x/8] |= mask[x&7];		if (byte & 64)  plane[PL_C][0][y*bpl + x/8] |= mask[x&7];		if (byte & 32)  plane[PL_M][1][y*bpl + x/8] |= mask[x&7];		if (byte & 16)  plane[PL_M][0][y*bpl + x/8] |= mask[x&7];		if (byte & 8)   plane[PL_Y][1][y*bpl + x/8] |= mask[x&7];		if (byte & 4)   plane[PL_Y][0][y*bpl + x/8] |= mask[x&7];		if (byte & 2)   plane[PL_K][1][y*bpl + x/8] |= mask[x&7];		if (byte & 1)   plane[PL_K][0][y*bpl + x/8] |= mask[x&7];	    }	}    }}long JbgOptions[5] ={    /* Order */    JBG_ILEAVE | JBG_SMID,    /* Options */    JBG_DELAY_AT | JBG_LRLTWO | JBG_TPDON | JBG_TPBON,    /* L0 */    128,    /* MX */    16,    /* MY */    0};void            swap32(void *p)     {    char *cp = (char *) p;    char tmp;    tmp = cp[0];    cp[0] = cp[3];    cp[3] = tmp;    tmp = cp[1];    cp[1] = cp[2];    cp[2] = tmp;}static voidfill_image_plane_unknown(OAK_IMAGE_PLANE *ip){    int	i;    for (i = 0; i < 16; ++i)	ip->unk[i] = i;}intcmyk_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			y;    int			bpl = (w+7)/8;    unsigned char	*plane[4];    debug(1, "cmyk_page: w=%d, h=%d, bitbpl=%d\n", w, h, bpl);    if (Color2Mono)	p0 = p3 = Color2Mono - 1;    else	{ p0 = 0; p3 = 3; }    for (p = p0; p <= p3 ; ++p)    {	plane[p] = malloc(bpl * h);	if (!plane[p]) error(3, "Cannot allocate space for bit plane\n");    }    cmyk_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 = 1;	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 = 1;	    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 cmyk_planes    //    for (p = p0; p <= p3; ++p)	for (y = 0; y < h; ++y)	    mirror_bytes(plane[p] + 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)	{	    bitmaps[0] = plane[p] + 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 = 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);	}    }    for (p = p0; p <= p3; ++p)	free(plane[p]);     oak_record(ofp, OAK_TYPE_END_IMAGE, NULL, 0);    endpage_arg = 1;	// Color    oak_record(ofp, OAK_TYPE_END_PAGE, &endpage_arg, sizeof(endpage_arg));    return 0;}intpbm_page(unsigned char *buf, 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			y;    int			bpl = (w+7)/8;    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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -