📄 sxpngutils.pas
字号:
repeat
Byte(Dest^):=Owner.GammaTable[PByte(Longint(Src)+4)^]; Inc(Dest);
Byte(Dest^):=Owner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=Owner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,6);
Inc(Dest,ColumnIncrement[Pass]*3-3);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedPalette148(const Pass:Byte;Src,Dest,Trans:PChar);
const BitTable:array[1..8]of Integer=($1,$3,0,$F,0,0,0,$FF);
StartBit:array[1..8]of Integer=(7,0,0,4, 0,0,0,0);
var CurBit,Col:Integer;
Dest2:PChar;
begin
Col:=ColumnStart[Pass];
repeat
CurBit:=StartBit[Header.BitDepth];
repeat
Dest2:=PChar(Longint(Dest)+(Header.BitDepth*Col) div 8);
Byte(Dest2^):=Byte(Dest2^) or (((Byte(Src^) shr CurBit) and BitTable[Header.BitDepth]) shl
(StartBit[Header.BitDepth]-(Col*Header.BitDepth mod 8)));
Inc(Col,ColumnIncrement[Pass]);
Dec(CurBit,Header.BitDepth);
until CurBit<0;
Inc(Src);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedPalette2(const Pass:Byte;Src,Dest,Trans:PChar);
var CurBit,Col:Integer;
Dest2:PChar;
begin
Col:=ColumnStart[Pass];
repeat
CurBit:=6;
repeat
Dest2:=PChar(Longint(Dest)+Col div 2);
Byte(Dest2^):=Byte(Dest2^) or (((Byte(Src^) shr CurBit) and $3) shl (4-(4*Col) mod 8));
Inc(Col,ColumnIncrement[Pass]);
Dec(CurBit,2);
until CurBit<0;
Inc(Src);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedGray2(const Pass:Byte;Src,Dest,Trans:PChar);
var CurBit,Col:Integer;
Dest2:PChar;
begin
Col:=ColumnStart[Pass];
repeat
CurBit:=6;
repeat
Dest2:=PChar(Longint(Dest)+Col div 2);
Byte(Dest2^):=Byte(Dest2^) or ((((Byte(Src^) shr CurBit) shl 2) and $F) shl (4-(Col*4) mod 8));
Inc(Col,ColumnIncrement[Pass]);
Dec(CurBit,2);
until CurBit<0;
Inc(Src);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedGrayscale16(const Pass:Byte;Src,Dest,Trans:PChar);
var Col:Integer;
begin
Col:=ColumnStart[Pass];
Dest:=PChar(Longint(Dest)+Col);
repeat
Dest^:=Src^; Inc(Dest);
Inc(Src,2);
Inc(Dest,ColumnIncrement[Pass]-1);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedRGBAlpha8(const Pass:Byte;Src,Dest,Trans:PChar);
var Col:Integer;
begin
Col:=ColumnStart[Pass];
Dest:=PChar(Longint(Dest)+Col*3);
Trans:=PChar(Longint(Trans)+Col);
repeat
Trans^:=PChar(Longint(Src)+3)^;
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+1)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,4);
Inc(Dest,ColumnIncrement[Pass]*3-3);
Inc(Trans,ColumnIncrement[Pass]);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedRGBAlpha16(const Pass:Byte;Src,Dest,Trans:PChar);
var Col:Integer;
begin
Col:=ColumnStart[Pass];
Dest:=PChar(Longint(Dest)+Col*3);
Trans:=PChar(Longint(Trans)+Col);
repeat
Trans^:=PChar(Longint(Src)+6)^;
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+4)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,8);
Inc(Dest,ColumnIncrement[Pass]*3-3);
Inc(Trans,ColumnIncrement[Pass]);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedGrayscaleAlpha8(const Pass:Byte;Src,Dest,Trans:PChar);
var Col:Integer;
begin
Col:=ColumnStart[Pass];
Dest:=PChar(Longint(Dest)+Col);
Trans:=PChar(Longint(Trans)+Col);
repeat
Dest^:=Src^; Inc(Src);
Trans^:=Src^; Inc(Src);
Inc(Dest,ColumnIncrement[Pass]);
Inc(Trans,ColumnIncrement[Pass]);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.CopyInterlacedGrayscaleAlpha16(const Pass:Byte;Src,Dest,Trans:PChar);
var Col:Integer;
begin
Col:=ColumnStart[Pass];
Dest:=PChar(Longint(Dest)+Col);
Trans:=PChar(Longint(Trans)+Col);
repeat
Dest^:=Src^; Inc(Src,2);
Trans^:=Src^; Inc(Src,2);
Inc(Dest,ColumnIncrement[Pass]);
Inc(Trans,ColumnIncrement[Pass]);
Inc(Col,ColumnIncrement[Pass]);
until Col>=ImageWidth;
end;
procedure TChunkIDAT.DecodeInterlacedAdam7(Stream:TStream;
var ZLIBStream:TZStreamRec2;const Size:Integer;var crcfile:Cardinal);
var
CurrentPass:Byte;
PixelsThisRow:Integer;
CurrentRow:Integer;
Trans,Data:PChar;
CopyProc:procedure(const Pass:Byte;Src,Dest,
Trans:PChar) of object;
begin
CopyProc:=nil;
case Header.ColorType of
COLOR_RGB:
case Header.BitDepth of
8: CopyProc:=CopyInterlacedRGB8;
16: CopyProc:=CopyInterlacedRGB16;
end;
COLOR_PALETTE,COLOR_GRAYSCALE:
case Header.BitDepth of
1,4,8:CopyProc:=CopyInterlacedPalette148;
2:if Header.ColorType=COLOR_PALETTE then
CopyProc:=CopyInterlacedPalette2
else
CopyProc:=CopyInterlacedGray2;
16:CopyProc:=CopyInterlacedGrayscale16;
end;
COLOR_RGBALPHA:
case Header.BitDepth of
8: CopyProc:=CopyInterlacedRGBAlpha8;
16: CopyProc:=CopyInterlacedRGBAlpha16;
end;
COLOR_GRAYSCALEALPHA:
case Header.BitDepth of
8: CopyProc:=CopyInterlacedGrayscaleAlpha8;
16: CopyProc:=CopyInterlacedGrayscaleAlpha16;
end;
end;
for CurrentPass:=0 to 6 do
begin
PixelsThisRow:=(ImageWidth-ColumnStart[CurrentPass]+
ColumnIncrement[CurrentPass]-1) div ColumnIncrement[CurrentPass];
Row_Bytes:=BytesForPixels(PixelsThisRow,Header.ColorType,
Header.BitDepth);
ZeroMemory(Row_Buffer[not RowUsed],Row_Bytes);
CurrentRow:=RowStart[CurrentPass];
Data:=Ptr(Longint(Header.ImageData)+Header.BytesPerRow *
(ImageHeight-1-CurrentRow));
Trans:=Ptr(Longint(Header.ImageAlpha)+ImageWidth*CurrentRow);
if Row_Bytes>0 then
while CurrentRow<ImageHeight do
begin
if IDATZlibRead(ZLIBStream,@Row_Buffer[RowUsed][0],Row_Bytes+1,
EndPos,CRCFile)=0 then break;
FilterRow;
CopyProc(CurrentPass,@Row_Buffer[RowUsed][1],Data,Trans);
RowUsed:=not RowUsed;
Inc(CurrentRow,RowIncrement[CurrentPass]);
Dec(Data,RowIncrement[CurrentPass]*Header.BytesPerRow);
Inc(Trans,RowIncrement[CurrentPass]*ImageWidth);
end;
end;
end;
procedure TChunkIDAT.CopyNonInterlacedRGB8(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+1)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,3);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedRGB16(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+4)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,6);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedPalette148(Src,Dest,Trans:PChar);
begin
CopyMemory(Dest,Src,Row_Bytes);
end;
procedure TChunkIDAT.CopyNonInterlacedGray2(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to Row_Bytes do
begin
Byte(Dest^):=((Byte(Src^) shr 2) and $F) or ((Byte(Src^)) and $F0); Inc(Dest);
Byte(Dest^):=((Byte(Src^) shl 2) and $F) or ((Byte(Src^) shl 4) and $F0); Inc(Dest);
Inc(Src);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedPalette2(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to Row_Bytes do
begin
Byte(Dest^):=((Byte(Src^) shr 4) and $3) or ((Byte(Src^) shr 2) and $30); Inc(Dest);
Byte(Dest^):=(Byte(Src^) and $3) or ((Byte(Src^) shl 2) and $30); Inc(Dest);
Inc(Src);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedGrayscale16(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Dest^:=Src^; Inc(Dest);
Inc(Src,2);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedRGBAlpha8(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Trans^:=PChar(Longint(Src)+3)^;
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+1)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,4); Inc(Trans);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedRGBAlpha16(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Trans^:=PChar(Longint(Src)+6)^;
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+4)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src)+2)^]; Inc(Dest);
Byte(Dest^):=fOwner.GammaTable[PByte(Longint(Src))^]; Inc(Dest);
Inc(Src,8);Inc(Trans);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedGrayscaleAlpha8(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Dest^:=Src^; Inc(Src);
Trans^:=Src^; Inc(Src);
Inc(Dest); Inc(Trans);
end;
end;
procedure TChunkIDAT.CopyNonInterlacedGrayscaleAlpha16(Src,Dest,Trans:PChar);
var I:Integer;
begin
for I:=1 to ImageWidth do
begin
Dest^:=Src^; Inc(Src,2);
Trans^:=Src^; Inc(Src,2);
Inc(Dest); Inc(Trans);
end;
end;
procedure TChunkIDAT.DecodeNonInterlaced(Stream:TStream;
var ZLIBStream:TZStreamRec2;const Size:Integer;var crcfile:Cardinal);
var
j:Cardinal;
Trans,Data:PChar;
CopyProc:procedure(
Src,Dest,Trans:PChar) of object;
begin
CopyProc:=nil;
case Header.ColorType of
COLOR_RGB:
case Header.BitDepth of
8:CopyProc:=CopyNonInterlacedRGB8;
16:CopyProc:=CopyNonInterlacedRGB16;
end;
COLOR_PALETTE,COLOR_GRAYSCALE:
case Header.BitDepth of
1,4,8:CopyProc:=CopyNonInterlacedPalette148;
2:if Header.ColorType=COLOR_PALETTE then
CopyProc:=CopyNonInterlacedPalette2
else
CopyProc:=CopyNonInterlacedGray2;
16:CopyProc:=CopyNonInterlacedGrayscale16;
end;
COLOR_RGBALPHA:
case Header.BitDepth of
8:CopyProc:=CopyNonInterlacedRGBAlpha8;
16:CopyProc:=CopyNonInterlacedRGBAlpha16;
end;
COLOR_GRAYSCALEALPHA:
case Header.BitDepth of
8:CopyProc:=CopyNonInterlacedGrayscaleAlpha8;
16:CopyProc:=CopyNonInterlacedGrayscaleAlpha16;
end;
end;
Longint(Data):=Longint(Header.ImageData)+
Header.BytesPerRow*(ImageHeight-1);
Trans:=Header.ImageAlpha;
for j:=0 to ImageHeight-1 do
begin
if IDATZlibRead(ZLIBStream,@Row_Buffer[RowUsed][0],Row_Bytes+1,EndPos,
CRCFile)=0 then break;
FilterRow;
CopyProc(@Row_Buffer[RowUsed][1],Data,Trans);
RowUsed:=not RowUsed;
Dec(Data,Header.BytesPerRow);
Inc(Trans,ImageWidth);
end;
end;
procedure TChunkIDAT.FilterRow;
var pp:Byte;
vv,left:Integer;
above,aboveleft:Integer;
Col:Cardinal;
begin
case Row_Buffer[RowUsed]^[0]of
FILTER_NONE:begin end;
FILTER_SUB:
for Col:=Offset+1 to Row_Bytes do
Row_Buffer[RowUsed][Col]:=(Row_Buffer[RowUsed][Col]+
Row_Buffer[RowUsed][Col-Offset]) and 255;
FILTER_UP:
for Col:=1 to Row_Bytes do
Row_Buffer[RowUsed][Col]:=(Row_Buffer[RowUsed][Col]+
Row_Buffer[not RowUsed][Col]) and 255;
FILTER_AVERAGE:
for Col:=1 to Row_Bytes do
begin
above:=Row_Buffer[not RowUsed][Col];
if col-1<Offset then
left:=0
else
Left:=Row_Buffer[RowUsed][Col-Offset];
Row_Buffer[RowUsed][Col]:=(Row_Buffer[RowUsed][Col]+
(left+above) div 2) and 255;
end;
FILTER_PAETH:
begin
left:=0;
aboveleft:=0;
for Col:=1 to Row_Bytes do
begin
above:=Row_Buffer[not RowUsed][Col];
if (col-1>=offset) then
begin
left:=row_buffer[RowUsed][col-offset];
aboveleft:=row_buf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -