📄 6.3
字号:
#ifndef XGIFDATA
#include <STDIO.H>
#include <STDLIB.H>
#include <ALLOC.H>
#include <STRING.H>
#include <GRAPHICS.H>
#include <DOS.H>
#include <BIOS.H>
typedef struct tagGLOBAL{
char version=A3=DB3=A3=DD;
char subversion=A3=DB3=A3=DD;
int screen_width;
int screen_height;
unsigned char global_flag;
unsigned char bg_color;
unsigned char zero;
}GLOBAL;
typedef struct tagLOCAL{
unsigned char comma;
int image_top;
int image_left;
int image_width;
int image_height;
unsigned char local_flag;
unsigned char first_char;
}LOCAL;
extern void pack_gif(FILE * , FILE *);
#endif // XGIFDATA
//=D2=D4=CF=C2=CA=C7GIFSAVE.C
#include "gif.h"
void pack_gif(FILE * , FILE *);
void pack_image(FILE *, FILE *, int, int, int);
void pack_init(int clear);
short lookup_ct(short code, unsigned char thischar);
void flush(void);
void putcode(short code);
FILE *fpout;
int index =3D 0, pixmask =3D 0xff;
int first_ch;
int code, oldcode;
int nextcode, nextlim;
int remcnt, reqcnt;
unsigned char rem;
int EOI, CLEAR;
unsigned char DataBuff=A3=DB4096 * 5=A3=DD;
int *CTlink =3D (int*)DataBuff;
unsigned char *CTfirst =3D DataBuff + 4096 * 2;
int *CTnext =3D (int *)(DataBuff + 4096 * 3);
unsigned char strbuf=A3=DB256=A3=DD;
void pack_gif(FILE * SourceRaw, FILE * DestGif)
{
char palette=A3=DB256*3=A3=DD;
int width, height, bps;
GLOBAL global;
LOCAL local;
if (fread(&width, sizeof(width), 1, SourceRaw) !=3D 1){
fclose(SourceRaw);
fclose(DestGif);
fprintf(stderr, "Reading from source file failed 1.\n");
exit(-1);
}
if (fread(&height, sizeof(height), 1, SourceRaw) !=3D 1){
fclose(SourceRaw);
fclose(DestGif);
fprintf(stderr, "Reading from source file failed 2.\n");
exit(-1);
}
if (fread(&bps, sizeof(bps), 1, SourceRaw) !=3D 1){
fclose(SourceRaw);
fclose(DestGif);
fprintf(stderr, "Reading from source file failed 3.\n");
exit(-1);
}
if (fread(&palette, sizeof(palette), 1, SourceRaw) !=3D 1){
fclose(SourceRaw);
fclose(DestGif);
fprintf(stderr, "Reading from source file failed 4.\n");
exit(-1);
}
strncpy(global.version, "GIF", 3);
strncpy(global.subversion, "87a", 3);
global.screen_width =3D width;
global.screen_height =3D height;
global.bg_color =3D 0;
global.zero =3D 0;
global.global_flag =3D 0x80 | (bps - 1);
local.comma =3D ',';
local.image_top =3D 0;
local.image_left =3D 0;
local.image_width =3D width;
local.image_height =3D height;
local.local_flag =3D global.global_flag & 0x07;
local.first_char =3D bps;=20
if (fwrite(&global, 1L, sizeof(global), DestGif) !=3D =
(size_t)sizeof(global)
){
fclose(SourceRaw);
fclose(DestGif);
fprintf(stderr, "Save GIF: error writing file.\n");
return;
}
if (fwrite(palette, 1L, (1<<BPS)*3, (nextcode if } oldcode=3D"-1;" =
putcode(oldcode); { else !=3D"(size_t)((1<<bps)*3)){" (code thischar); =
code=3D"lookup_ct(oldcode," exit(-1); 5.\n?); failed file source from =
?Reading fprintf(stderr, fclose(DestGif); fclose(SourceRaw); SourceRaw) =
1, sizeof(thischar), (fread(&thischar, thischar=3D"*ptr++;" j++){ width; =
< j for(j=3D"0;" (long)width*i); ptr=3D"farptr(bitmap," i++){ i<height; =
(i=3D"0;" for putcode(CLEAR); pack_init(CLEAR); 1; + EOI=3D"CLEAR" =
alphabet. the of size as defined is CLEAR=3D"1" bps; << ???? =
first_ch=3D"bps;" rem=3D"0;" remcnt=3D"0;" index=3D"1;" =
fpout=3D"DestGif;" *ptr; far char unsigned thischar; j; i, int register =
code; short bps){ height, width, DestGif, * FILE SourceRaw, =
pack_image(FILE* void return; bps); pack_image(SourceRaw, file.\n?); =
writing error GIF: ?Save DestGif) sizeof(local), 1L, (fwrite(&local,> =
nextlim){
if (reqcnt =3D=3D 12){
putcode(oldcode);
putcode(CLEAR);
pack_init(CLEAR);
}else{
reqcnt++;
nextlim =3D nextlim << 1;
if (reqcnt =3D=3D 12) nextlim--;
}
}
} // for j
} // for i
putcode(oldcode);
putcode(EOI);
flush();
fputc(0, fpout);
fputc(0x3b, fpout);
}
void pack_init(int clear)
{
register int i;
nextcode =3D clear + 2;
oldcode =3D -1;
for(i =3D 0; i < clear; i++){
CTfirst=A3=DBi=A3=DD =3D i;
for(i =3D 0; i < 4096; i++){
CTlink=A3=DBi=A3=DD =3D -2;
CTnext=A3=DBi=A3=DD =3D -1;
}
reqcnt =3D first_ch + 1; // first_ch =3D=3D bps -- BitsPerPixel.
nextlim =3D 1 << reqcnt;
}
short lookup_ct(short code, unsigned char thischar)
{
if (code =3D=3D -1) return(unsigned int) thischar;
if (CTlink=A3=DBcode=A3=DD =3D=3D -2){
CTlink=A3=DBcode=A3=DD =3D nextcode;
}else{
code =3D CTlink=A3=DBcode=A3=DD;
while((CTnext=A3=DBcode=A3=DD !=3D -1) && =
(CTfirst=A3=DBcode=A3=DD !=3D thischar))
code =3D CTnext=A3=DBcode=A3=DD;
if (CTfirst=A3=DBcode=A3=DD =3D=3D thischar) return code;
CTnext=A3=DBcode=A3=DD =3D nextcode;
}
CTfirst=A3=DBnextcode++=A3=DD =3D thischar;
return -1;
}
void putcode(short code)
{
int allcnt, used, codelen;
codelen =3D reqcnt;
allcnt =3D remcnt + reqcnt;
while(allcnt >=3D 8){
if (remcnt > 0){
used =3D 8 - remcnt;
strbuf=A3=DBindex++=A3=DD =3D rem | (unsigned char)
code =3D code >> used;
codelen -=3D used;
remcnt =3D 0;
}else{
strbuf=A3=DBindex++=A3=DD =3D (unsigned char)(code & pixmask);
codelen -=3D 8;
code =3D code >> 8;
}
allcnt -=3D 8;
if (index =3D=3D 256){
strbuf=A3=DB0=A3=DD =3D 0xff;
fwrite(strbuf, index, 1, fpout);
index =3D 1;
}
}
if (remcnt =3D=3D 0){
rem =3D code;
remcnt =3D codelen;
}else{
rem |=3D (code << remcnt);
remcnt +=3D codelen;
}
}
void flush()
{
if (remcnt !=3D 0) strbuf=A3=DBindex++=A3=DD =3D rem;
if (index =3D=3D 1) return;
strbuf=A3=DB0=A3=DD =3D (unsigned char) (index - 1);
fwrite(strbuf, index, 1, fpout);
index =3D 1;
}
//=D2=D4=CF=C2=CA=C7GIFMAIN.C
#include "gif.h"
int main(int argc, char *argv=A3=DB=A3=DD)
{
char SourceName=A3=DB256=A3=DD, DestName=A3=DB256=A3=DD;
FILE *SourceRaw, *DestGif;
if (argc < 3){
printf("Usage : %s SOURCE-RAW DEST-GIF\n", argv=A3=DB0=A3=DD);
exit(0);
}
SourceRaw =3D fopen(argv=A3=DB1=A3=DD, "rb");
if (SourceRaw =3D=3D NULL){
printf("Can not open source file %s.\n", argv=A3=DB1=A3=DD);
exit(0);
}
DestGif =3D fopen(argv=A3=DB2=A3=DD, "wb");
if (DestGif =3D=3D NULL){
fclose(SourceRaw);
printf("Can not create destination file %s.\n", argv=A3=DB2=A3=DD);
exit(0);
}
pack_gif(SourceRaw, DestGif);
return 0;
}</PRE></UL><PRE></PRE>
<P></P>
<P>
<HR width=3D"100%">
<CENTER><FONT color=3D#008040>
<TABLE border=3D1>
<TBODY>
<TR>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/notice=
.htm">=D4=C4=B6=C1=CB=B5=C3=F7</A></FONT></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/pref1.=
htm">=D0=F2=D1=D4=D2=BB</A></FONT></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/pref2.=
htm">=D0=F2=D1=D4=B6=FE</A></FONT></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/conten=
t.htm">=C4=BF=C2=BC</A></FONT></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/101.ht=
m">1</A></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/201.ht=
m">2</A></TD>
<TD><A=20
=
href=3D"http://www.phil.pku.edu.cn/personal/huajie/fractalart/html/301.ht=
m">3</A></TD>
<TD><A=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -