TempleOSCD_150216.ISO
This commit is contained in:
1 parent
64f679eeb9
commit
401601816c
531 files changed
+23341
-22071
No files matched your search
+105
-64
@@ -24,23 +24,21 @@ class CFileBMP
|
||||
CBGR palette[16];
|
||||
};
|
||||
|
||||
public CFileBMP *BMPFile4To(CDC *dc)
|
||||
public CFileBMP *BMP4To(CDC *dc)
|
||||
{//To Windows 4-bit BMP.
|
||||
U8 *src,*ptr;
|
||||
I64 x,y,w=dc->width>>1,
|
||||
size=offset(CFileBMP.end)+dc->width*dc->height>>1+16*sizeof(CBGR);
|
||||
CFileBMP *r=CAlloc(size);
|
||||
r->type='BM';
|
||||
r->planes=1;
|
||||
r->file_size=size;
|
||||
r->data_offset=offset(CFileBMP.end);
|
||||
r->header_size=offset(CFileBMP.end)-
|
||||
offset(CFileBMP.header_size);
|
||||
r->width=dc->width;
|
||||
r->height=dc->height;
|
||||
r->bit_cnt=4;
|
||||
r->image_size=dc->width*dc->height>>1;
|
||||
r->data_offset+=16*sizeof(CBGR);
|
||||
size=sizeof(CFileBMP)+dc->width*dc->height>>1;
|
||||
CFileBMP *r =CAlloc(size);
|
||||
r->type ='BM';
|
||||
r->planes =1;
|
||||
r->file_size =size;
|
||||
r->data_offset=sizeof(CFileBMP);
|
||||
r->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
|
||||
r->width =dc->width;
|
||||
r->height =dc->height;
|
||||
r->bit_cnt =4;
|
||||
r->image_size =dc->width*dc->height>>1;
|
||||
GetVGAPalette4(r->palette);
|
||||
ptr=r(U8 *)+r->data_offset;
|
||||
for (y=dc->height-1;y>=0;y--) {
|
||||
@@ -54,23 +52,21 @@ public CFileBMP *BMPFile4To(CDC *dc)
|
||||
return r;
|
||||
}
|
||||
|
||||
public CFileBMP *BMPFileRLE4To(CDC *dc)
|
||||
public CFileBMP *BMPRLE4To(CDC *dc)
|
||||
{//To Windows RLE4 bit BMP.
|
||||
U8 *src,*ptr;
|
||||
U8 *src,*ptr,*start;
|
||||
I64 x,y,w=dc->width,cnt,pattern;
|
||||
CFileBMP *r=CAlloc(offset(CFileBMP.end)+2*(dc->width+1)*dc->height+16*sizeof(CBGR));
|
||||
r->type='BM';
|
||||
r->planes=1;
|
||||
r->data_offset=offset(CFileBMP.end);
|
||||
r->header_size=offset(CFileBMP.end)-
|
||||
offset(CFileBMP.header_size);
|
||||
r->width=dc->width;
|
||||
r->height=dc->height;
|
||||
r->bit_cnt=4;
|
||||
CFileBMP *r =CAlloc(sizeof(CFileBMP)+2*(dc->width+1)*dc->height);
|
||||
r->type ='BM';
|
||||
r->planes =1;
|
||||
r->data_offset=sizeof(CFileBMP);
|
||||
r->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
|
||||
r->width =dc->width;
|
||||
r->height =dc->height;
|
||||
r->bit_cnt =4;
|
||||
r->compression=2; //RLE4
|
||||
r->data_offset+=16*sizeof(CBGR);
|
||||
GetVGAPalette4(r->palette);
|
||||
ptr=r(U8 *)+r->data_offset;
|
||||
start=ptr=r(U8 *)+r->data_offset;
|
||||
for (y=dc->height-1;y>=0;y--) {
|
||||
src=y*dc->width_internal+dc->body;
|
||||
x=0;
|
||||
@@ -101,27 +97,26 @@ public CFileBMP *BMPFileRLE4To(CDC *dc)
|
||||
}
|
||||
*ptr(U16 *)++=0;
|
||||
}
|
||||
r->image_size=ptr-(&r->data_offset)(U8 *);
|
||||
r->file_size=offset(CFileBMP.end)+r->image_size+16*sizeof(CBGR);
|
||||
r->image_size=ptr-start;
|
||||
r->file_size=sizeof(CFileBMP)+r->image_size;
|
||||
return r;
|
||||
}
|
||||
|
||||
public CFileBMP *BMPFile24To(CDC *dc)
|
||||
public CFileBMP *BMP24To(CDC *dc)
|
||||
{//To Windows 24-bit BMP.
|
||||
U8 *src;
|
||||
I64 i,x,y,size=offset(CFileBMP.end)+dc->width*dc->height*sizeof(CRGB);
|
||||
CBGR *bgr;
|
||||
CFileBMP *r=CAlloc(size);
|
||||
r->type='BM';
|
||||
r->planes=1;
|
||||
r->file_size=size;
|
||||
CFileBMP *r =CAlloc(size);
|
||||
r->type ='BM';
|
||||
r->planes =1;
|
||||
r->file_size =size;
|
||||
r->data_offset=offset(CFileBMP.end);
|
||||
r->header_size=offset(CFileBMP.end)-
|
||||
offset(CFileBMP.header_size);
|
||||
r->width=dc->width;
|
||||
r->height=dc->height;
|
||||
r->bit_cnt=32;
|
||||
r->image_size=dc->width*dc->height<<2;
|
||||
r->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
|
||||
r->width =dc->width;
|
||||
r->height =dc->height;
|
||||
r->bit_cnt =32;
|
||||
r->image_size =dc->width*dc->height<<2;
|
||||
|
||||
bgr=r(U8 *)+r->data_offset;
|
||||
for (y=dc->height-1;y>=0;y--) {
|
||||
@@ -142,22 +137,22 @@ public CFileBMP *BMPFile24To(CDC *dc)
|
||||
return r;
|
||||
}
|
||||
|
||||
public I64 BMPFileWrite(U8 *filename,CDC *dc,I64 bits=4)
|
||||
public I64 BMPWrite(U8 *filename,CDC *dc,I64 bits=4)
|
||||
{//Window's BMP Files.
|
||||
I64 size;
|
||||
CFileBMP *r;
|
||||
if (bits==4) {
|
||||
if (IsDotZ(filename)) //.Z compression is better than RLE
|
||||
r=BMPFile4To(dc);
|
||||
r=BMP4To(dc);
|
||||
else {
|
||||
r=BMPFileRLE4To(dc);
|
||||
if (r->file_size>offset(CFileBMP.end)+dc->width*dc->height>>1+16*sizeof(CBGR)) {
|
||||
r=BMPRLE4To(dc);
|
||||
if (r->file_size>sizeof(CFileBMP)+dc->width*dc->height>>1) {
|
||||
Free(r);
|
||||
r=BMPFile4To(dc);
|
||||
r=BMP4To(dc);
|
||||
}
|
||||
}
|
||||
} else if (bits==24)
|
||||
r=BMPFile24To(dc);
|
||||
r=BMP24To(dc);
|
||||
else {
|
||||
"Format Not Supported.\n";
|
||||
return 0;
|
||||
@@ -168,7 +163,7 @@ public I64 BMPFileWrite(U8 *filename,CDC *dc,I64 bits=4)
|
||||
return size;
|
||||
}
|
||||
|
||||
U8 *BMPFilePaletteNew(CFileBMP *r)
|
||||
U8 *BMPPaletteNew(CFileBMP *r)
|
||||
{
|
||||
I64 i,j,best,score,best_score;
|
||||
CBGR palette[16];
|
||||
@@ -193,11 +188,39 @@ U8 *BMPFilePaletteNew(CFileBMP *r)
|
||||
|
||||
U8 ms_paint_palette[16]={0,4,2,6,1,5,3,8,7,12,10,14,9,13,11,15};
|
||||
|
||||
public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
I64 BMP24Color(CBGR *ptr,Bool dither_probability)
|
||||
{
|
||||
I64 result,k;
|
||||
if (dither_probability) {
|
||||
k=RandU32;
|
||||
if (SqrI64(ptr->r)+SqrI64(ptr->g)+SqrI64(ptr->b)>=3*SqrI64(k.u8[0]))
|
||||
result=8;
|
||||
else
|
||||
result=0;
|
||||
if (ptr->r>=k.u8[1]) result|=RED;
|
||||
if (ptr->g>=k.u8[2]) result|=GREEN;
|
||||
if (ptr->b>=k.u8[3]) result|=BLUE;
|
||||
} else {
|
||||
if (SqrI64(ptr->r)+SqrI64(ptr->g)+SqrI64(ptr->b)>=SqrI64(0x80)) {
|
||||
result=8;
|
||||
if (ptr->r>=0x80) result|=RED;
|
||||
if (ptr->g>=0x80) result|=GREEN;
|
||||
if (ptr->b>=0x80) result|=BLUE;
|
||||
} else {
|
||||
result=0;
|
||||
if (ptr->r>=0x40) result|=RED;
|
||||
if (ptr->g>=0x40) result|=GREEN;
|
||||
if (ptr->b>=0x40) result|=BLUE;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public CDC *BMPRead(U8 *filename,Bool dither_probability=FALSE,Bool use_ms_paint_palette=FALSE)
|
||||
{//Window's BMP Files.
|
||||
I64 i,j,cnt;
|
||||
U8 *palette_map,*ptr;
|
||||
Bool rle4;
|
||||
Bool rle;
|
||||
CFileBMP *r;
|
||||
CDC *result=NULL;
|
||||
if (ptr=FileRead(filename)) {
|
||||
@@ -205,17 +228,17 @@ public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
if (0<r->width<MAX_I32 && 0<r->height<MAX_I32) {
|
||||
result=DCNew(r->width,r->height);
|
||||
ptr+=r->data_offset;
|
||||
if (r->compression==2)
|
||||
rle=TRUE;
|
||||
else
|
||||
rle=FALSE;
|
||||
if (use_ms_paint_palette)
|
||||
palette_map=ms_paint_palette;
|
||||
else
|
||||
palette_map=BMPPaletteNew(r);
|
||||
if (r->bit_cnt==4) {
|
||||
if (r->compression==2)
|
||||
rle4=TRUE;
|
||||
else
|
||||
rle4=FALSE;
|
||||
if (use_ms_paint_palette)
|
||||
palette_map=ms_paint_palette;
|
||||
else
|
||||
palette_map=BMPFilePaletteNew(r);
|
||||
for (i=r->height-1;i>=0;i--)
|
||||
if (rle4) {//We don't support full RLE4, just our own subset
|
||||
if (rle) {//We don't support full RLE4, just our own subset
|
||||
j=0;
|
||||
while (cnt=*ptr++) {
|
||||
if (cnt==1) {
|
||||
@@ -238,7 +261,7 @@ public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
}
|
||||
ptr++;
|
||||
} else
|
||||
for (j=0;j<(r->width+7)&-8;) {
|
||||
for (j=0;j<(r->width+7)&~7;) {
|
||||
result->color=palette_map[*ptr&15];
|
||||
GrPlot(result,j+1,i);
|
||||
result->color=palette_map[*ptr>>4];
|
||||
@@ -248,6 +271,24 @@ public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else if (r->bit_cnt==24) {
|
||||
for (i=r->height-1;i>=0;i--) {
|
||||
for (j=0;j<r->width;j++,ptr+=3) {
|
||||
result->color=BMP24Color(ptr,dither_probability);
|
||||
GrPlot(result,j,i);
|
||||
}
|
||||
ptr+=r->width&3;
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else if (r->bit_cnt>=32) {
|
||||
for (i=r->height-1;i>=0;i--)
|
||||
for (j=0;j<r->width;j++,ptr+=4) {
|
||||
result->color=BMP24Color(ptr,dither_probability);
|
||||
GrPlot(result,j,i);
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else {
|
||||
"Format Not Supported.\n";
|
||||
DCDel(result);
|
||||
@@ -261,9 +302,9 @@ public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
}
|
||||
|
||||
#help_index "Graphics/Sprite;Graphics/Windows BMP Files;DolDoc/Output"
|
||||
public U0 DocBMPFile(CDoc *doc=NULL,U8 *filename,Bool use_ms_paint_palette=FALSE)
|
||||
public U0 DocBMP(CDoc *doc=NULL,U8 *filename,Bool dither_probability=FALSE,Bool use_ms_paint_palette=FALSE)
|
||||
{//Put a BMP file into a document as a sprite.
|
||||
CDC *dc=BMPFileRead(filename,use_ms_paint_palette);
|
||||
CDC *dc=BMPRead(filename,dither_probability,use_ms_paint_palette);
|
||||
CSprite *elems=DC2Sprite(dc);
|
||||
DocSprite(doc,elems);
|
||||
Free(elems);
|
||||
@@ -271,10 +312,10 @@ public U0 DocBMPFile(CDoc *doc=NULL,U8 *filename,Bool use_ms_paint_palette=FALSE
|
||||
}
|
||||
|
||||
#help_index "Graphics/Windows BMP Files;Graphics/Screen"
|
||||
public I64 BMPFileCaptureScreen(U8 *filename,I64 bits=4)
|
||||
public I64 BMPCaptureScreen(U8 *filename,I64 bits=4,Bool include_zoom=TRUE)
|
||||
{//Capture screen as BMP file.
|
||||
CDC *dc=DCCaptureScreen;
|
||||
I64 size=BMPFileWrite(filename,dc,bits);
|
||||
CDC *dc=DCCaptureScreen(include_zoom);
|
||||
I64 size=BMPWrite(filename,dc,bits);
|
||||
DCDel(dc);
|
||||
return size;
|
||||
}
|
||||
Reference in new issue
Block a user