| 19 |
|
|
| 20 |
|
function ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData; |
| 21 |
|
procedure RevertImage; |
| 22 |
– |
procedure DecodeImage; |
| 22 |
|
procedure DecompressImage; |
| 23 |
|
protected |
| 24 |
|
public |
| 37 |
|
function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean; |
| 38 |
|
function GetImageDataSize(fading: Boolean): Integer; |
| 39 |
|
|
| 40 |
< |
function GetAsData: TByteData; |
| 41 |
< |
function GetAs32bit: TByteData; |
| 42 |
< |
procedure GetAsBMP(var Target: TByteData); overload; |
| 40 |
> |
procedure DecodeImageTo32bit; |
| 41 |
> |
|
| 42 |
> |
procedure GetAsData(var Target: TStream); overload; |
| 43 |
> |
procedure GetAsData(var Target: TByteData); overload; |
| 44 |
> |
procedure GetAs32bit(var Target: TStream); overload; |
| 45 |
> |
procedure GetAs32bit(var Target: TByteData); overload; |
| 46 |
|
procedure GetAsBMP(var Target: TStream); overload; |
| 47 |
+ |
procedure GetAsBMP(var Target: TByteData); overload; |
| 48 |
|
function LoadFromBMP(filename: String): Boolean; |
| 49 |
|
function WriteToBMP(filename: String): Boolean; |
| 50 |
< |
function GetMipMappedImage(var faded: TByteData): Boolean; |
| 50 |
> |
function GetMipMappedImage(var Target: TStream): Boolean; overload; |
| 51 |
> |
function GetMipMappedImage(var Target: TByteData): Boolean; overload; |
| 52 |
|
published |
| 53 |
|
end; |
| 54 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
< |
procedure TOniImage.DecodeImage; |
| 135 |
> |
procedure TOniImage.DecodeImageTo32bit; |
| 136 |
|
var |
| 137 |
|
x, y: Integer; |
| 138 |
|
tempd: TByteData; |
| 141 |
|
begin |
| 142 |
|
SetLength(tempd, Self.FWidth * Self.FHeight * 4); |
| 143 |
|
case Self.FStoreType of |
| 144 |
< |
0: |
| 144 |
> |
0: // 16bit, RGB444, A4? |
| 145 |
|
begin |
| 146 |
|
for y := 0 to Self.FHeight - 1 do |
| 147 |
|
begin |
| 160 |
|
end; |
| 161 |
|
end; |
| 162 |
|
end; |
| 163 |
< |
1, 2: |
| 163 |
> |
1, 2: // 16bit, RGB555, A1? |
| 164 |
|
begin |
| 165 |
|
for y := 0 to Self.FHeight - 1 do |
| 166 |
|
begin |
| 179 |
|
end; |
| 180 |
|
end; |
| 181 |
|
end; |
| 182 |
< |
9: |
| 182 |
> |
8: // 32bit, RGB888, A8? |
| 183 |
> |
begin end; |
| 184 |
> |
9: // Compressed, RGB565 |
| 185 |
|
begin |
| 186 |
|
DecompressImage; |
| 187 |
|
end; |
| 312 |
|
function TOniImage.Load(ConnectionID, FileID: Integer): Boolean; |
| 313 |
|
var |
| 314 |
|
FileInfo: TFileInfo; |
| 309 |
– |
ext: String; |
| 315 |
|
begin |
| 316 |
|
FileInfo := ConManager.Connection[ConnectionID].GetFileInfo(fileid); |
| 317 |
|
if FileInfo.Extension = 'PSpc' then |
| 371 |
|
end; |
| 372 |
|
txmpimg := TOniImage.Create; |
| 373 |
|
txmpimg.LoadFromTXMP(ConnectionID, PSpc.TXMP); |
| 374 |
< |
txmpimg.DecodeImage; |
| 374 |
> |
txmpimg.DecodeImageTo32bit; |
| 375 |
|
// txmpimg.WriteToBMP('C:\file.bmp'); |
| 376 |
< |
txmpdata := txmpimg.GetAs32bit; |
| 376 |
> |
txmpimg.GetAs32bit(txmpdata); |
| 377 |
|
{ ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height)); |
| 378 |
|
for i:=0 to High(txmpdata) do |
| 379 |
|
txmpimg.Data[i]:=txmpdata[i]; |
| 536 |
|
link := link div 256; |
| 537 |
|
images_decoded[i] := TOniImage.Create; |
| 538 |
|
images_decoded[i].LoadFromTXMP(ConnectionID, link); |
| 539 |
< |
images_decoded[i].DecodeImage; |
| 539 |
> |
images_decoded[i].DecodeImageTo32bit; |
| 540 |
|
images_decoded[i].RevertImage; |
| 541 |
|
end; |
| 542 |
|
SetLength(Self.FData, Self.FWidth * Self.FHeight * 4); |
| 588 |
|
var |
| 589 |
|
size: Integer; |
| 590 |
|
x, y: Word; |
| 591 |
< |
bpp: Byte; |
| 592 |
< |
begin |
| 593 |
< |
case Self.FStoreType of |
| 594 |
< |
9: |
| 595 |
< |
bpp := 8; |
| 596 |
< |
0, 1, 2: |
| 597 |
< |
bpp := 16; |
| 598 |
< |
8: |
| 599 |
< |
bpp := 32; |
| 591 |
> |
|
| 592 |
> |
function GetImgSize(w,h, storetype: Integer): Integer; |
| 593 |
> |
begin |
| 594 |
> |
case storetype of |
| 595 |
> |
0, 1, 2: |
| 596 |
> |
Result := w*h*2; |
| 597 |
> |
8: |
| 598 |
> |
Result := w*h*4; |
| 599 |
> |
9: |
| 600 |
> |
Result := Max(1, w div 4) * Max(1, h div 4) * 8; |
| 601 |
|
else |
| 602 |
< |
Result := 0; |
| 603 |
< |
Exit; |
| 602 |
> |
Result := -1; |
| 603 |
> |
end; |
| 604 |
|
end; |
| 605 |
|
|
| 606 |
+ |
begin |
| 607 |
|
x := Self.FWidth; |
| 608 |
|
y := Self.FHeight; |
| 609 |
< |
size := x * y * bpp div 8; |
| 609 |
> |
size := GetImgSize(x, y, FStoreType); |
| 610 |
|
if fading then |
| 611 |
|
begin |
| 612 |
|
repeat |
| 613 |
< |
x := x div 2; |
| 614 |
< |
y := y div 2; |
| 615 |
< |
size := size + x * y * bpp div 8; |
| 616 |
< |
until (x = 1) or (y = 1); |
| 613 |
> |
x := Max(x div 2, 1); |
| 614 |
> |
y := Max(y div 2, 1); |
| 615 |
> |
size := size + GetImgSize(x, y, FStoreType); |
| 616 |
> |
until (x = 1) and (y = 1); |
| 617 |
|
end; |
| 618 |
|
Result := size; |
| 619 |
|
end; |
| 621 |
|
|
| 622 |
|
|
| 623 |
|
|
| 624 |
< |
function TOniImage.GetAsData: TByteData; |
| 624 |
> |
procedure TOniImage.GetAsData(var Target: TStream); |
| 625 |
|
var |
| 619 |
– |
i: Integer; |
| 626 |
|
revert: Boolean; |
| 627 |
|
begin |
| 628 |
|
// if not (DT_Decoded32 in Self.FDataType) then |
| 634 |
|
end |
| 635 |
|
else |
| 636 |
|
revert := False; |
| 637 |
< |
SetLength(Result, Length(Self.FData)); |
| 638 |
< |
for i := 0 to High(Result) do |
| 639 |
< |
Result[i] := Self.FData[i]; |
| 637 |
> |
if not Assigned(Target) then |
| 638 |
> |
Target := TMemoryStream.Create; |
| 639 |
> |
Target.Write(FData[0], Length(FData)); |
| 640 |
> |
Target.Seek(0, soFromBeginning); |
| 641 |
|
if revert then |
| 642 |
|
Self.RevertImage; |
| 643 |
|
end; |
| 644 |
|
|
| 645 |
< |
|
| 639 |
< |
|
| 640 |
< |
|
| 641 |
< |
function TOniImage.GetAs32bit: TByteData; |
| 645 |
> |
procedure TOniImage.GetAsData(var Target: TByteData); |
| 646 |
|
var |
| 647 |
< |
i: Integer; |
| 647 |
> |
mem: TStream; |
| 648 |
|
begin |
| 649 |
< |
if not (DT_Decoded32 in Self.FDataType) then |
| 650 |
< |
Self.DecodeImage; |
| 651 |
< |
SetLength(Result, Length(Self.FData)); |
| 652 |
< |
for i := 0 to High(Result) do |
| 653 |
< |
Result[i] := Self.FData[i]; |
| 649 |
> |
mem := TMemoryStream.Create; |
| 650 |
> |
GetAsData(mem); |
| 651 |
> |
SetLength(Target, mem.Size); |
| 652 |
> |
mem.Read(Target[0], mem.Size); |
| 653 |
> |
mem.Free; |
| 654 |
|
end; |
| 655 |
|
|
| 656 |
|
|
| 657 |
+ |
procedure TOniImage.GetAs32bit(var Target: TStream); |
| 658 |
+ |
begin |
| 659 |
+ |
if not (DT_Decoded32 in Self.FDataType) then |
| 660 |
+ |
Self.DecodeImageTo32bit; |
| 661 |
+ |
if not Assigned(Target) then |
| 662 |
+ |
Target := TMemoryStream.Create; |
| 663 |
+ |
Target.Write(FData[0], Length(FData)); |
| 664 |
+ |
Target.Seek(0, soFromBeginning); |
| 665 |
+ |
end; |
| 666 |
+ |
|
| 667 |
+ |
procedure TOniImage.GetAs32bit(var Target: TByteData); |
| 668 |
+ |
var |
| 669 |
+ |
mem: TStream; |
| 670 |
+ |
begin |
| 671 |
+ |
mem := TMemoryStream.Create; |
| 672 |
+ |
GetAs32bit(mem); |
| 673 |
+ |
SetLength(Target, mem.Size); |
| 674 |
+ |
mem.Read(Target[0], mem.Size); |
| 675 |
+ |
mem.Free; |
| 676 |
+ |
end; |
| 677 |
|
|
| 678 |
|
|
| 679 |
|
procedure TOniImage.GetAsBMP(var Target: TByteData); |
| 686 |
|
i, x, y: Integer; |
| 687 |
|
begin |
| 688 |
|
if not (DT_Decoded32 in Self.FDataType) then |
| 689 |
< |
Self.DecodeImage; |
| 689 |
> |
Self.DecodeImageTo32bit; |
| 690 |
|
|
| 691 |
|
SetLength(Target, Self.FWidth * Self.FHeight * 3 + 54); |
| 692 |
|
for y := 0 to Self.FHeight - 1 do |
| 723 |
|
procedure TOniImage.GetAsBMP(var Target: TStream); |
| 724 |
|
var |
| 725 |
|
data: TByteData; |
| 726 |
+ |
streampos: Integer; |
| 727 |
|
begin |
| 728 |
|
GetAsBMP(data); |
| 729 |
+ |
streampos := Target.Position; |
| 730 |
|
Target.Write(data[0], Length(data)); |
| 731 |
+ |
Target.Seek(streampos, soFromBeginning); |
| 732 |
|
end; |
| 733 |
|
|
| 734 |
|
|
| 809 |
|
|
| 810 |
|
|
| 811 |
|
|
| 812 |
< |
|
| 786 |
< |
function TOniImage.GetMipMappedImage(var faded: TByteData): Boolean; |
| 812 |
> |
function TOniImage.GetMipMappedImage(var Target: TByteData): Boolean; |
| 813 |
|
var |
| 814 |
|
i: Integer; |
| 815 |
|
x, y: Word; |
| 832 |
|
|
| 833 |
|
x := Self.FWidth; |
| 834 |
|
y := Self.FHeight; |
| 835 |
< |
SetLength(faded, x * y * Self.FDepth div 8); |
| 835 |
> |
SetLength(Target, x * y * Self.FDepth div 8); |
| 836 |
|
SetLength(fadelvldata, x * y * Self.FDepth div 8); |
| 837 |
< |
for i := 0 to Length(faded) - 1 do |
| 837 |
> |
for i := 0 to Length(Target) - 1 do |
| 838 |
|
begin |
| 839 |
< |
faded[i] := Self.FData[i]; |
| 839 |
> |
Target[i] := Self.FData[i]; |
| 840 |
|
fadelvldata[i] := Self.FData[i]; |
| 841 |
|
end; |
| 842 |
|
repeat |
| 843 |
|
fadelvldata := Self.ResizeImage(x, y, fadelvldata); |
| 844 |
|
x := x div 2; |
| 845 |
|
y := y div 2; |
| 846 |
< |
SetLength(faded, Length(faded) + x * y * Self.FDepth div 8); |
| 846 |
> |
SetLength(Target, Length(Target) + x * y * Self.FDepth div 8); |
| 847 |
|
for i := 0 to Length(fadelvldata) - 1 do |
| 848 |
< |
faded[Length(faded) - x * y * Self.FDepth div 8 + i] := fadelvldata[i]; |
| 848 |
> |
Target[Length(Target) - x * y * Self.FDepth div 8 + i] := fadelvldata[i]; |
| 849 |
|
until (x = 1) or (y = 1) or ((x mod 2) = 1) or ((y mod 2) = 1); |
| 850 |
|
if (x > 1) and (y > 1) then |
| 851 |
|
Exit; |
| 856 |
|
end; |
| 857 |
|
|
| 858 |
|
|
| 859 |
+ |
function TOniImage.GetMipMappedImage(var Target: TStream): Boolean; |
| 860 |
+ |
var |
| 861 |
+ |
data: TByteData; |
| 862 |
+ |
streampos: Integer; |
| 863 |
+ |
begin |
| 864 |
+ |
Result := GetMipMappedImage(data); |
| 865 |
+ |
if not Assigned(Target) then |
| 866 |
+ |
Target := TMemoryStream.Create; |
| 867 |
+ |
streampos := Target.Position; |
| 868 |
+ |
Target.Write(data[0], Length(data)); |
| 869 |
+ |
Target.Seek(streampos, soFromBeginning); |
| 870 |
+ |
end; |
| 871 |
+ |
|
| 872 |
+ |
|
| 873 |
|
end. |