home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
prnout
/
src
/
img.c
< prev
next >
Wrap
Text File
|
1990-06-14
|
11KB
|
485 lines
/*****************************************
グラフィック・イメ-ジをプリンタに出力
1989.12.08 make by Ken
*******************************************/
#include <stdio.h>
#include "defs.h"
#define DSP_X 0
#define DSP_Y 19
typedef struct {
short int tf_tag;
short int tf_type;
long int tf_len;
long int tf_data;
} TIF_IFD;
extern char *subname();
extern char skl_chr[];
static int off_x=0;
static int spc_x=0;
static int off_y=0;
static int max_x=0;
static int max_y=0;
static int img_s=0;
static int pam_x=0;
static int big_cnt=4;
static int skl_ptr=0;
static int skl_cnt=0;
static UNSIG bit2_ptn[]={ 0x00,0x10,0x21,0x13,0x33 };
static UNSIG bit3_ptn[]={
0x000,0x020,0x202,0x141,0x252,0x525,0x563,0x573,0x757,0x777 };
static UNSIG bit4_ptn[]={
0x0000, 0x0020, 0x0204, 0x2042, 0x4218, 0x4252, 0x2495, 0x5a45,
0xa5a5, 0xa7a5, 0xada7, 0xbdb8, 0xdbeb, 0xfd7d, 0xf7bf, 0xfbff,
0xffff };
static UCHAR img_buf[4096 * 3];
static struct {
UCHAR b,r,g;
} pal_tbl[256];
int swap(p)
char *p;
{
long i;
char *s;
s = (char *)&i;
p += 4;
*(s++) = *(--p);
*(s++) = *(--p);
*(s++) = *(--p);
*(s++) = *(--p);
return i;
}
int dsp_skl()
{
skl_ptr += 272;
while ( skl_ptr >= max_y ) {
locate(DSP_X+1+(skl_cnt / 8),DSP_Y+1);
repchr(1,skl_chr[skl_cnt % 8]);
skl_ptr -= max_y;
skl_cnt++;
}
if ( kbhit() != 0 ) {
getch();
return ERR;
}
return FALSE;
}
void dsp_img(x,y,fc)
int x,y;
{
x *= big_cnt;
y *= big_cnt;
x = (x >> 3) + off_x;
y = (y >> 3) + off_y;
line(off_x,off_y,x,y,PSET,0,fc,LINE_3);
}
void dsp_bit(x,y,c)
int x,y,c;
{
static int old_c=0,old_x;
if ( x == 0 )
old_c = c;
old_c = (old_c + c) / 2;
x *= big_cnt;
y *= big_cnt;
x = (x >> 3) + off_x;
y = (y >> 3) + off_y;
if ( old_x != x )
line(x,y,x,y,PSET,15 - (old_c >> 4),LINE,LINE_1);
old_x = x;
}
void prn_img(x,y)
int x,y;
{
char tmp[20];
if ( typ_flg == DUMMY )
return;
x *= big_cnt;
fnt_spc(spc_x);
switch(typ_flg) {
case FUJITU:
sprintf(tmp,"\x1bQ%d W",x);
prn_line_out(tmp);
break;
case ESCP:
PRB_byte("\x1b\x2a\x27",3);
PRB_chr(x & 0xFF);
PRB_chr(x >> 8);
break;
case PC98:
sprintf(tmp,"\x1bJ%04d",x);
PRB_byte(tmp,6);
break;
}
PRB_byte(img_buf,x * 3);
prn_line_out("\x0D\x0A");
memset(img_buf,0,4096*3);
}
void set_img(x,y,r,g,b)
int x,y,r,g,b;
{
int cl,ptn,bit,i;
UCHAR *p;
cl = (25500 - (r * 30 + g * 59 + b * 11)) / 100;
dsp_bit(x,y,cl);
cl >>= (8 - big_cnt);
if ( big_cnt == 1 ) {
y %= 24;
p = img_buf + x * 3 + y / 8;
if ( cl > 0 )
*p |= (0x80 >> (y % 8));
} else if ( big_cnt == 2 ) {
y %= 12;
p = img_buf + x * 6 + (y / 4);
ptn = bit2_ptn[cl];
for ( i = 0 ; i < 2 ; i++ ) {
bit = ptn & 0x0003; ptn >>= 4;
bit <<= (6 - ((y % 4) * 2));
*p |= bit;
p += 3;
}
} else if ( big_cnt == 3 ) {
y %= 8;
p = img_buf + x * 9 + (y / 3);
ptn = bit3_ptn[cl];
for ( i = 0 ; i < 3 ; i++ ) {
bit = ptn & 0x0007; ptn >>= 4;
switch(y) {
case 0: bit <<= 5; *p |= bit; break;
case 1: bit <<= 2; *p |= bit; break;
case 2: *p |= (bit >> 1); bit <<= 7; *(p+1) |= bit; break;
case 3: bit <<= 4; *p |= bit; break;
case 4: bit <<= 1; *p |= bit; break;
case 5: *p |= (bit >> 2); bit <<= 6; *(p+1) |= bit; break;
case 6: bit <<= 3; *p |= bit; break;
case 7: *p |= bit; break;
}
p += 3;
}
} else if ( big_cnt == 4 ) {
y %= 6;
p = img_buf + x * 12 + (y / 2);
ptn = bit4_ptn[cl];
for ( i = 0 ; i < 4 ; i++ ) {
bit = ptn & 0x000F; ptn >>= 4;
if ( (y & 1) == 0 )
bit <<= 4;
*p |= bit;
p += 3;
}
}
PRB_out();
}
void TIF_get1(fp)
FILE *fp;
{
int cl;
UCHAR bit,mask;
int x,y,i;
mask = 0;
for ( i = y = 0 ; y < max_y ; y++ ) {
for ( x = 0 ; x < max_x ; x++ ) {
if ( (mask >>= 1) == 0 ) {
fread(&bit,1,1,fp);
mask = 0x80;
}
cl = ((bit & mask) == 0 ? 0:255);
set_img(x,y,cl,cl,cl);
}
if ( ++i == (24 / big_cnt) ) {
prn_img(max_x,y);
i = 0;
}
if ( dsp_skl() != FALSE )
return;
}
if ( i > 0 )
prn_img(max_x,y);
}
void TIF_get4(fp)
FILE *fp;
{
UCHAR ch;
int cl;
int x,y,i;
static struct {
short int r,g,b;
} ct[]={
{0,0,0},{0,0,128},{128,0,0},{128,0,128},
{0,128,0},{0,128,128},{128,128,0},{128,128,128},
{64,64,64},{0,0,255},{255,0,0},{255,0,255},
{0,255,0},{0,255,255},{255,255,0},{255,255,255}
};
for ( i = y = 0 ; y < max_y ; y++ ) {
for ( x = 0 ; x < max_x ; x += 2 ) {
fread(&ch,1,1,fp);
cl = ch & 0x0F;
set_img(x,y,ct[cl].r,ct[cl].g,ct[cl].b);
cl = ch >> 4;
set_img(x+1,y,ct[cl].r,ct[cl].g,ct[cl].b);
}
if ( ++i == (24 / big_cnt) ) {
prn_img(max_x,y);
i = 0;
}
if ( dsp_skl() != FALSE )
return;
}
if ( i > 0 )
prn_img(max_x,y);
}
void TIF_get8(fp)
FILE *fp;
{
UCHAR bit;
int x,y,i;
for ( i = y = 0 ; y < max_y ; y++ ) {
for ( x = 0 ; x < max_x ; x++ ) {
fread(&bit,1,1,fp);
set_img(x,y,pal_tbl[bit].r,pal_tbl[bit].g,pal_tbl[bit].b);
}
if ( ++i == (24 / big_cnt) ) {
prn_img(max_x,y);
i = 0;
}
if ( dsp_skl() != FALSE )
return;
}
if ( i > 0 )
prn_img(max_x,y);
}
void TIF_get16(fp)
FILE *fp;
{
short int bit;
int r,g,b;
int x,y,i;
for ( i = y = 0 ; y < max_y ; y++ ) {
for ( x = 0 ; x < max_x ; x++ ) {
fread(&bit,1,2,fp);
b = (bit & 0x1F) << 3; bit >>= 5;
r = (bit & 0x1F) << 3; bit >>= 5;
g = (bit & 0x1F) << 3;
set_img(x,y,r,g,b);
}
if ( ++i == (24 / big_cnt) ) {
prn_img(max_x,y);
i = 0;
}
if ( dsp_skl() != FALSE )
return;
}
if ( i > 0 )
prn_img(max_x,y);
}
void gra_start()
{
int i;
pp_box(0,0);
locate(DSP_X+1,DSP_Y+1);
repchr(34,' ');
locate(DSP_X+1,DSP_Y+3);
printf("%-34s","只今グラフィック・デ-タを印刷してます");
switch(typ_flg) {
case FUJITU:
prn_line_out("\x1bQ3 \x5c\x1c%\x22\x74");
break;
case ESCP:
PRB_byte("\x1B\x33\x18",3);
break;
case PC98:
prn_line_out("\x1bT22");
break;
}
if ( typ_flg != DUMMY ) {
for ( i = yousi[paper].pmrg ; i > 0 ; i-- )
prn_line_out("\x0D\x0A");
}
memset(img_buf,0,4096*3);
}
void big_setup()
{
big_cnt = pam_x / max_x;
if ( big_cnt <= 0 ) big_cnt = 1;
if ( big_cnt > 4 ) big_cnt = 4;
dsp_img(max_x,max_y,SBOX);
}
void gra_end()
{
if ( typ_flg != DUMMY )
PRB_chr('\x0C');
locate(DSP_X+1,DSP_Y+3);
printf("%-34s","グラフィックの印刷を終了しました");
}
void pal_init()
{
int i,bit;
for ( i = 0 ; i < 256 ; i++ ) {
bit = i;
pal_tbl[i].b = (bit & 0x07) << 5; bit >>= 3;
pal_tbl[i].r = (bit & 0x07) << 5; bit >>= 3;
pal_tbl[i].g = (bit & 0x03) << 6;
}
}
int TIF_img(fp)
FILE *fp;
{
short int i;
long l;
TIF_IFD ifd;
char tmp[8];
gra_start();
if ( fread(tmp,1,4,fp) < 4 )
return ERR;
if ( tmp[0] != 0x49 || tmp[1] != 0x49 || tmp[2] != 0x2A )
return ERR;
if ( fread(&l,4,1,fp) < 1 )
return ERR;
fseek(fp,l,0);
if ( fread(&i,2,1,fp) < 1 )
return ERR;
while ( i-- > 0) {
if ( fread(&ifd,sizeof(TIF_IFD),1,fp) < 1 )
return ERR;
if ( ifd.tf_tag == 0 )
break;
switch(ifd.tf_tag){
case 0x0100: max_x = ifd.tf_data; break;
case 0x0101: max_y = ifd.tf_data; break;
case 0x0102: img_s = ifd.tf_data; break;
case 0x0111: l = ifd.tf_data; break;
}
}
big_setup();
fseek(fp,l,0);
switch(img_s) {
case 1: TIF_get1(fp); break;
case 4: TIF_get4(fp); break;
case 8: pal_init(); TIF_get8(fp); break;
case 16: TIF_get16(fp); break;
}
gra_end();
return FALSE;
}
void PIC_img(fp)
FILE *fp;
{
gra_start();
max_x = 320; max_y = 240;
img_s = 16;
big_setup();
TIF_get16(fp);
gra_end();
}
void GED_img(fp)
FILE *fp;
{
short int i;
gra_start();
fseek(fp,0x000Cl,0);
if ( fread(&i,2,1,fp) < 1 )
return;
max_x = i + 1;
if ( fread(&i,2,1,fp) < 1 )
return;
max_y = i + 1;
img_s = 16;
fseek(fp,0x0100l,0);
big_setup();
TIF_get16(fp);
gra_end();
}
void GRP_img(fp)
FILE *fp;
{
long l;
char tmp[8];
gra_start();
if ( fread(tmp,1,4,fp) < 4 )
return;
if ( fread(tmp,1,4,fp) < 4 )
return;
max_x = swap(tmp);
if ( fread(tmp,1,4,fp) < 4 )
return;
max_y = swap(tmp);
if ( fread(tmp,1,4,fp) < 4 )
return;
if ( (img_s = swap(tmp)) == 15 )
img_s = 16;
switch(img_s) {
case 4:
l = 0x0050l;
break;
case 8:
fseek(fp,0x0020l,0);
fread(pal_tbl,1,768,fp);
l = 0x0320l;
break;
case 16:
l = 0x0020l;
break;
}
fseek(fp,l,0);
big_setup();
switch(img_s) {
case 4: TIF_get4(fp); break;
case 8: TIF_get8(fp); break;
case 16: TIF_get16(fp); break;
}
gra_end();
}
int gra_img(fp,file)
FILE *fp;
char *file;
{
char *p;
off_x = (yousi[paper].lmrg * (yousi[paper].spc + 24));
spc_x = off_x / 2;
off_x += (printer[typ_flg].yoko * 1800L) / 254L;
off_x = (off_x >> 4) + GRA_OFFX;
pam_x = (yousi[paper].lmax * (yousi[paper].spc + 24)) / 2;
off_y = (printer[typ_flg].tate * 1800L) / 254L;
off_y += (yousi[paper].pmrg * (yousi[paper].lf + 24));
off_y = (off_y >> 3) + GRA_OFFY;
skl_cnt = skl_ptr = 0;
p = subname(file);
if ( strcmp(p,"TIF") == 0 )
TIF_img(fp);
else if ( strcmp(p,"PIC") == 0 )
PIC_img(fp);
else if ( strcmp(p,"GED") == 0 || strcmp(p,"FIG") == 0 )
GED_img(fp);
else if ( strcmp(p,"GRP") == 0 )
GRP_img(fp);
else
return FALSE;
return TRUE;
}