/programs/media/imgview/formats/bmp.cpp |
---|
0,0 → 1,122 |
#include "..\kosSyst.h" |
#include "bmp.h" |
int BMPFile::LoadBMPFile(Byte* filebuff, Dword filesize) |
{ |
Dword offset; |
memcpy((Byte*)&Bmp_head,(Byte*)filebuff,sizeof(tagBITMAPFILEHEADER)); |
memcpy((Byte*)&Info_head,(Byte*)filebuff+14,sizeof(tagBITMAPINFOHEADER)); |
width=Info_head.biWidth; |
height=Info_head.biHeight; |
offset=(Dword)Bmp_head.bfOffbits; |
int state=0; |
if (Bmp_head.bfType==0x4d42 && !Info_head.biCompression) |
{ |
Byte* cBuffer; |
Byte* pImg; |
Byte* pPal; |
Dword x,y; |
Byte r; |
Dword s,p; |
Dword cWidth; |
int i; |
buffer=kos_GetMemory(width*height*3); |
pImg=filebuff+offset; |
pPal=filebuff+53; |
int align_bytes = (4 - ((width * 3) % 4)) % 4; |
Dword bpp = Info_head.biBitCount; |
switch(Info_head.biBitCount) |
{ |
/* 16,24,32-bit decoding */ |
case 32: |
case 24: |
case 16: |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
cBuffer=buffer+(y*width*3)+x*3; |
if (Info_head.biBitCount==16) |
{ |
*(cBuffer+0)=(Byte)((*(Word*)(pImg)) & 31)<<3; |
*(cBuffer+1)=(Byte)((*(Word*)(pImg)>>5) & 31)<<3; |
*(cBuffer+2)=(Byte)((*(Word*)(pImg)>>10) & 31)<<3; |
} else { |
*(cBuffer+0)=*(pImg+0); |
*(cBuffer+1)=*(pImg+1); |
*(cBuffer+2)=*(pImg+2); |
} |
pImg=pImg+Info_head.biBitCount/8; |
} |
pImg=pImg+align_bytes; |
} |
break; |
/* 8-bit decoding */ |
case 8: |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
r=*(pImg); pImg++; |
cBuffer=buffer+(y*width*3)+x*3; |
*(cBuffer+0)=(Byte)(pPal[r*4+1]); |
*(cBuffer+1)=(Byte)(pPal[r*4+2]); |
*(cBuffer+2)=(Byte)(pPal[r*4+3]); |
} |
} |
break; |
/* 1,4-bit decode */ |
case 4: |
case 1: |
for(y=height-1;y!=-1;y--) |
{ |
x=0; |
while(x<width-1) |
{ |
s=*(Dword*)(pImg); |
pImg=pImg+4; |
__asm |
{ |
mov eax,s |
bswap eax |
mov s,eax |
} |
for(i=0;i<32/bpp;i++) |
{ |
if (x>=width) break; |
__asm |
{ |
mov eax,s |
mov ecx,bpp |
rol eax,cl |
mov s,eax |
mov ebx,1 |
shl ebx,cl |
dec ebx |
and eax,ebx |
mov p,eax |
} |
cBuffer=buffer+(y*width*3)+x*3; |
*(cBuffer+0)=(Byte)(pPal[p*4+1]); |
*(cBuffer+1)=(Byte)(pPal[p*4+2]); |
*(cBuffer+2)=(Byte)(pPal[p*4+3]); |
x++; |
} |
} |
} |
break; |
default: |
state=1; |
break; |
} |
} else { |
state=1; |
} |
return state; |
} |
/programs/media/imgview/formats/bmp.h |
---|
0,0 → 1,45 |
#pragma pack(push, 1) |
typedef struct tagBITMAPFILEHEADER |
{ |
Word bfType; //òèï ôàéëà (äëÿ áèòîâîãî îáðàçà - BM) |
Dword bfSize; //ðàçìåð ôàéëà â dword |
Word bfReserved1; //íå èñïîëüçóåòñÿ |
Word bfReserved2; //íå èñïîëüçóåòñÿ |
Dword bfOffbits; //ñìåùåíèå äàííûõ áèòîâîãî îáðàçà îò çàãîëîâêà â áàéòàõ |
} tagBITMAPFILEHEADER; |
typedef struct tagBITMAPINFOHEADER |
{ |
Dword biSize; //÷èñëî áàéò, çàíèìàåìûõ ñòðóêòóðîé BITMAPINFOHEADER |
Dword biWidth; //øèðèíà áèòîâîãî îáðàçà â ïèêñåëàõ |
Dword biHeight; //âûñîòà áèòîâîãî îáðàçà â ïèêñåëàõ |
Word biPlanes; //÷èñëî áèòîâûõ ïëîñêîñòåé óñòðîéñòâà |
Word biBitCount; //÷èñëî áèòîâ íà ïèêñåëü |
Dword biCompression; //òèï ñæàòèÿ |
Dword biSizeImage; //ðàçìåð êàðòèíêè â áàéòàõ |
Dword biXPelsPerMeter; //ãîðèçîíòàëüíîå ðàçðåøåíèå óñòðîéñòâà, ïèêñåë/ì |
Dword biYPelPerMeter; //âåðòèêàëüíîå ðàçðåøåíèå óñòðîéñòâà, ïèêñåë/ì |
Dword biClrUsed; //÷èñëî èñïîëüçóåìûõ öâåòîâ |
Dword biClrImportant; //÷èñëî "âàæíûõ" öâåòîâ |
} tagBITMAPINFOHEADER; |
typedef struct tagRGBQUAD |
{ |
Byte rgbBlue; |
Byte rgbGreen; |
Byte rgbRed; |
Byte rgbReserved; |
} tagRGBQUAD; |
#pragma pack(pop) |
class BMPFile |
{ |
protected: |
tagBITMAPFILEHEADER Bmp_head; |
tagBITMAPINFOHEADER Info_head; |
public: |
Dword width; |
Dword height; |
Byte* buffer; |
int BMPFile::LoadBMPFile(Byte* filebuff, Dword filesize); |
}; |
/programs/media/imgview/formats/pcx.cpp |
---|
0,0 → 1,55 |
#include "..\kosSyst.h" |
#include "pcx.h" |
int PCXFile::LoadPCXFile(Byte* filebuff, Dword filesize) |
{ |
memcpy((Byte*)&Pcx_head,(Byte*)filebuff,sizeof(PCXHeader)); |
int state=0; |
if (Pcx_head.bManufacturer==0x0a && Pcx_head.bVersion==0x05) |
{ |
width=Pcx_head.dwWidth-Pcx_head.dwX+1; |
height=Pcx_head.dwHeight-Pcx_head.dwY+1; |
buffer=kos_GetMemory(width*height*3); |
Byte* pPal=filebuff+filesize-768; |
Byte* pImg=filebuff+128; |
Byte* cBuffer=(Byte*)buffer; |
if (Pcx_head.bNPlanes==1) |
{ |
/* 8-bit decoding */ |
Dword y,i; |
Byte cur_byte,counter; |
Dword cWidth; |
for(y=0;y<height;y++) |
{ |
cWidth=width; |
while(cWidth!=0) |
{ |
cur_byte=*(pImg); pImg++; |
counter=1; |
if (cur_byte>=192) |
{ |
counter=(cur_byte & 0x3F); |
cur_byte=*(pImg); pImg++; |
} |
for(i=0;i<counter;i++) |
{ |
*(cBuffer+0)=(pPal[cur_byte*3+0]); |
*(cBuffer+1)=(pPal[cur_byte*3+1]); |
*(cBuffer+2)=(pPal[cur_byte*3+2]); |
cBuffer=cBuffer+3; |
cWidth--; |
} |
} |
} |
} else if (Pcx_head.bNPlanes==3) { |
/* 24-bit decoding */ |
state=1; |
} |
} else { |
state=1; |
} |
return state; |
} |
/programs/media/imgview/formats/pcx.h |
---|
0,0 → 1,31 |
#pragma pack(push, 1) |
typedef struct PCXHeader |
{ |
Byte bManufacturer; |
Byte bVersion; |
Byte bEncoding; |
Byte bBPP; |
Word dwX; |
Word dwY; |
Word dwWidth; |
Word dwHeight; |
Word dwHRes; |
Word dwVRes; |
Byte colormap[48]; |
Byte bReserved; |
Byte bNPlanes; |
Word iBPL; |
Word iPalInfo; |
} PCXHeader; |
#pragma pack(pop) |
class PCXFile |
{ |
protected: |
PCXHeader Pcx_head; |
public: |
Word width; |
Word height; |
Byte* buffer; |
int LoadPCXFile(Byte* filebuff, Dword filesize); |
}; |
/programs/media/imgview/formats/tga.cpp |
---|
0,0 → 1,103 |
#include "..\kosSyst.h" |
#include "tga.h" |
int TGAFile::LoadTGAFile(Byte* filebuff, Dword filesize) |
{ |
memcpy((Byte*)&Tga_head,(Byte*)filebuff,sizeof(sTGAHeader)); |
width=Tga_head.Width; |
height=Tga_head.Height; |
Byte* pImg=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin+(Tga_head.ColorMapLength*Tga_head.ColorMapEntrySize/8); |
Byte* pPal=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin; |
Byte* cBuffer; |
int x,y; |
Byte r; |
int sm; |
int state=1; |
if (Tga_head.ImageDescByte >= 32) sm=height-1; else sm=0; |
// Èçîáðàæåíèå ñ ïàëèòðîé (ïàëèòðà 24 èëè 32-áèòíàÿ) |
if (Tga_head.ImageTypeCode==1) |
{ |
if (Tga_head.ColorMapEntrySize>=24) |
{ |
buffer=kos_GetMemory(width*height*3); |
int bpp=Tga_head.ColorMapEntrySize/8; |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
r=*(pImg); pImg++; |
cBuffer=buffer+(abs(sm-y)*width*3)+x*3; |
*(cBuffer+0)=(Byte)(pPal[r*bpp+1]); |
*(cBuffer+1)=(Byte)(pPal[r*bpp+2]); |
*(cBuffer+2)=(Byte)(pPal[r*bpp+3]); |
} |
} |
state=0; |
} |
} |
// ÖÂåòíîå èçîáðàæåíèå áåç ñæàòèÿ è ïàëèòðû |
else if (Tga_head.ImageTypeCode==2) |
{ |
switch (Tga_head.ImagePixelSize) |
{ |
case 32: |
case 24: |
buffer=kos_GetMemory(width*height*3); |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
cBuffer=buffer+(abs(sm-y)*width*3)+x*3; |
*(cBuffer+0)=*(pImg+0); |
*(cBuffer+1)=*(pImg+1); |
*(cBuffer+2)=*(pImg+2); |
pImg=pImg+Tga_head.ImagePixelSize/8; |
} |
} |
state=0; |
break; |
case 16: |
buffer=kos_GetMemory(width*height*3); |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
cBuffer=buffer+(abs(sm-y)*width*3)+x*3; |
*(cBuffer+0)=(Byte)((*(Word*)(pImg)) & 31)<<3; |
*(cBuffer+1)=(Byte)((*(Word*)(pImg)>>5) & 31)<<3; |
*(cBuffer+2)=(Byte)((*(Word*)(pImg)>>10) & 31)<<3; |
pImg=pImg+2; |
} |
} |
state=0; |
break; |
} |
} |
// Ìîíîõðîìíîå èçîáðàæåíèå |
else if (Tga_head.ImageTypeCode==3) |
{ |
switch (Tga_head.ImagePixelSize) |
{ |
case 8: |
buffer=kos_GetMemory(width*height*3); |
for(y=height-1;y!=-1;y--) |
{ |
for(x=0;x<width;x++) |
{ |
cBuffer=buffer+(abs(sm-y)*width*3)+x*3; |
*(cBuffer+0)=*(pImg); |
*(cBuffer+1)=*(pImg); |
*(cBuffer+2)=*(pImg); |
pImg++; |
} |
} |
state=0; |
break; |
} |
} |
return state; |
} |
/programs/media/imgview/formats/tga.h |
---|
0,0 → 1,37 |
#pragma pack(push, 1) |
typedef struct sTGAHeader |
{ |
Byte BytesInIdentField; |
Byte ColorMapType; // Color map type - 0 [no map] 1 [256 entry] |
Byte ImageTypeCode; /* Image type |
[0] No image data included |
[1] Uncompressed color map image [4,6] |
[2] Uncompressed RGB Image [16,24] |
[3] Uncompressed Black & White |
[9] RLE Color map image |
[10] RLE RGB Image |
[11] RLE Black & White |
[32 | 33] compressed color map by Huffman, Delta, RLE |
*/ |
Word ColorMapOrigin; // Offset of first color map entry |
Word ColorMapLength; // Number of color map entries |
Byte ColorMapEntrySize; // Number of bits per color map entries |
Word XOrigin; |
Word YOrigin; |
Word Width; |
Word Height; |
Byte ImagePixelSize; // BPP |
Byte ImageDescByte; // Flags |
} sTGAHeader; |
#pragma pack(pop) |
class TGAFile |
{ |
protected: |
sTGAHeader Tga_head; |
public: |
Word width; |
Word height; |
Byte* buffer; |
int LoadTGAFile(Byte* filebuff, Dword filesize); |
}; |
/programs/media/imgview/formats/. |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |