Home > Back-end >  Under the DOS system by turboC2.0 implementation of 256 colors BMP images
Under the DOS system by turboC2.0 implementation of 256 colors BMP images

Time:03-19

# include "stdio.h"
# include "dir. H"
H # include "DOS."
# include "graphics. H"
Char * malloc ();/* * malloc conversion/
Char bmp_to_dat (char * BMP, char * dat)/* will be 16 color BMP file can be converted to use putimage output format, BMP for original BMP file, dat for conversion file */
{
Unsigned char c [8], scan_times scan_pixs;
Unsigned char workpos;
Int I, j, k, n, nowpos, iw, ih.
Static int color [16]=,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15 {0};
Scanline unsigned char workline [640], [640].
The FILE * fp, * targetfp;
The union {
Unsigned char value;
Struct {
Unsigned cl: 4;
Unsigned ch: 4;
} color; } mycolor;
If ((fp=fopen (BMP, "rb"))==NULL)
Return (0);
Targetfp=fopen (dat, "wb");
Fseek (fp, 18, SEEK_SET);
Iw=0;
Ih=0;
Fread (& amp; Iw, 4, 1, fp);/* * read image width/

Fread (& amp; Ih, 4, 1, fp);/* read image height */
If (iw==0 & amp; & Ih==0 & amp; & Iw> 640 & amp; & Ih> 480)
{
The fclose (fp);
The fclose (targetfp);
Return (0); }
Iw -;
Ih -;/* ∵ putimage width of less than 1 */actual numerical
Scan_times=iw/8 + 1;
/* line processing unit number */
Scan_pixs=scan_times * 4;/* line pixel bytes ∵=1 unit 4 bytes */
Fputc (iw % 256, targetfp);/* fill information: long, wide part */
Fputc (iw/256, targetfp);
Fputc (ih % 256, targetfp);
Fputc (ih/256, targetfp);
Fseek (fp - scan_pixs SEEK_END);
for(j=0; j{nowpos=0;
Fread (scanline scan_pixs, 1, fp);
Fseek (fp, - scan_pixs * 2, SEEK_CUR);
For (n=3; N>=0; N -)
/* decoding 4 bits face */
{the for (I=0; i/* decode various coding unit */
{workpos=0;
for(k=0; K<4. Isolated k++)/* */8 pixels
{mycolor.value=https://bbs.csdn.net/topics/scanline [I] * 4 + k;
C [k * 2]=color ch] is [mycolor. Color.
C=color [k * 2 + 1] [mycolor. Color. Cl]; }
for(k=0; K<8; K++)
Workpos +=(c [k] & gt;> N& 1) & lt; <(7 - k);
Workline [nowpos]=workpos;
Nowpos++; }}
Fwrite (workline, scan_pixs, 1, targetfp); }
The fclose (fp);
The fclose (targetfp);
The return (1);
}

Void main ()
{
Int gd=VGA, gm=VGAHI, n.
Char * buffer;
Char _16file [20]={" c: \ \ \ \ tc BMP \ \ 2. Dat "};
Char bmpfile [20]={" c: \ \ \ \ tc BMP \ \ 2. BMP "};
The FILE * fp.
Struct FFBLK ff;
Initgraph (& amp; Gd, & amp; Gm, "c: \ \ tc \ \ BGI");


/* the while (1)
{
N=getch ();
The switch (n)
{0 case: the continue;
Case '0' : exit (0);
Case '1' : strcpy (bmpfile, "1. BMP");
Goto OUT;
Case '2' : strcpy (bmpfile, "2. BMP");//bmpfile is the file name, can be understood as the picture name
Goto OUT;
Case '3' : {
Printf (" Input filename (*. BMP) : ");
Gets (bmpfile);
Goto OUT;
}
}
}
OUT: strncpy (_16file bmpfile, strlen (bmpfile) - 3);
Strcat (_16file, "dat"); */
if(! Bmp_to_dat (bmpfile _16file))
{
Puts (" File Error!" );
closegraph();
exit(0); }
Fp=fopen (_16file, "rb");
Findfirst (_16file, & amp; Ff, FA_ARCH);
If ((buffer=malloc (ff. Ff_fsize))==NULL)
exit(0);
N=0;
while(! The feof (fp))
{buffer [n]=fgetc (fp);
N++; }
For (n=0; n<100; N++)
{putimage (350 - n, n/2, and buffer, COPY_PUT); }
getch();
closegraph();
Free (buffer);
The fclose (fp); }
In this program, compiled through, but will show black screen, please god

CodePudding user response:

16 programming environment is the most basic mean int 16,
Your iw ih the space only 2 bytes, you read in 4 bytes are overstepping,
Image width are wrong cases, the other is not normal, I'm afraid would have a normal

So, I admit that only look at a few lines, the no.

CodePudding user response:

Ih and iw type int, isn't it

CodePudding user response:

reference 1st floor forever74 response:
16 programming environment is the most basic mean int 16,
Your iw ih the space only 2 bytes, you read in 4 bytes are overstepping,
Image width are wrong cases, the other is not normal, I'm afraid would have a normal

So, I admit that only look at a few lines, the following no.

You that I don't understand, I changed a long also not line

CodePudding user response:

Easyx?

CodePudding user response:

The use of TC in DosBox?

CodePudding user response:

quoted zhao 4, 4/f, the teacher's reply:
easyx?

No use easyx

CodePudding user response:

This shows 256 color figure, 16 color can
  • Related