2 |
|
|
3 |
|
interface |
4 |
|
|
5 |
< |
uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs; |
5 |
> |
uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs, |
6 |
> |
Imaging, ImagingTypes; |
7 |
|
|
8 |
|
type |
9 |
|
TImgDataType = set of (DT_OniReverted, DT_Oni, DT_Decoded32); |
10 |
|
|
11 |
+ |
|
12 |
|
type |
13 |
|
TOniImage = class |
14 |
|
private |
19 |
|
FDepth: Byte; |
20 |
|
FStoreType: Byte; |
21 |
|
|
22 |
+ |
FImage: TImageData; |
23 |
+ |
|
24 |
|
function ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData; |
25 |
|
procedure RevertImage; |
26 |
|
procedure DecompressImage; |
27 |
|
protected |
28 |
|
public |
29 |
+ |
property Image: TImageData Read FImage Write FImage; |
30 |
|
property Loaded: Boolean Read FLoaded Write FLoaded; |
31 |
|
property DataType: TImgDataType Read FDataType Write FDataType; |
32 |
|
property Width: Word Read FWidth Write FWidth; |
40 |
|
function LoadFromPSpc(ConnectionID, FileID: Integer): Boolean; |
41 |
|
function LoadFromTXMP(ConnectionID, FileID: Integer): Boolean; |
42 |
|
function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean; |
43 |
+ |
function GetImgSize(w,h, storetype: Integer): Integer; |
44 |
|
function GetImageDataSize(fading: Boolean): Integer; |
45 |
|
|
46 |
|
procedure DecodeImageTo32bit; |
62 |
|
implementation |
63 |
|
|
64 |
|
//uses Functions; |
65 |
< |
|
60 |
< |
|
65 |
> |
uses Img_DDSTypes; |
66 |
|
|
67 |
|
|
68 |
|
constructor TOniImage.Create; |
74 |
|
Self.FHeight := 0; |
75 |
|
Self.FDepth := 0; |
76 |
|
Self.FStoreType := 0; |
77 |
+ |
|
78 |
+ |
InitImage(FImage); |
79 |
|
end; |
80 |
|
|
81 |
|
|
479 |
|
function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean; |
480 |
|
var |
481 |
|
img_addr: Integer; |
482 |
+ |
data: TMemoryStream; |
483 |
+ |
hdr: TDDSDXTHeader; |
484 |
+ |
imginfo: Integer; |
485 |
+ |
x,y, i: Integer; |
486 |
|
begin |
487 |
|
Result := True; |
488 |
|
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth); |
489 |
|
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight); |
490 |
< |
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType), |
491 |
< |
@Self.FStoreType); |
490 |
> |
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType), @Self.FStoreType); |
491 |
> |
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo); |
492 |
|
if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then |
493 |
|
ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr) |
494 |
|
else |
496 |
|
|
497 |
|
case Self.FStoreType of |
498 |
|
0, 1, 2: |
488 |
– |
begin |
489 |
– |
SetLength(Self.FData, Self.FWidth * Self.FHeight * 2); |
499 |
|
Self.FDepth := 16; |
491 |
– |
end; |
500 |
|
8: |
493 |
– |
begin |
494 |
– |
SetLength(Self.FData, Self.FWidth * Self.FHeight * 4); |
501 |
|
Self.FDepth := 32; |
496 |
– |
end; |
502 |
|
9: |
498 |
– |
begin |
499 |
– |
SetLength(Self.FData, Self.FWidth * Self.FHeight div 2); |
503 |
|
Self.FDepth := 16; |
501 |
– |
end; |
504 |
|
else |
505 |
|
Result := False; |
506 |
|
Exit; |
507 |
|
end; |
508 |
|
|
509 |
|
if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then |
510 |
+ |
ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data)) |
511 |
+ |
else |
512 |
+ |
ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data)); |
513 |
+ |
|
514 |
+ |
with hdr do |
515 |
+ |
begin |
516 |
+ |
FOURCC := 'DDS '; |
517 |
+ |
with SURFACEDESC2 do |
518 |
+ |
begin |
519 |
+ |
Size := 124; |
520 |
+ |
Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT; |
521 |
+ |
if FStoreType = 9 then |
522 |
+ |
Flags := Flags or DDSD_LINEARSIZE |
523 |
+ |
else |
524 |
+ |
Flags := Flags or DDSD_PITCH; |
525 |
+ |
if (imginfo and $01) > 0 then |
526 |
+ |
Flags := Flags or DDSD_MIPMAPCOUNT; |
527 |
+ |
Height := FHeight; |
528 |
+ |
Width := FWidth; |
529 |
+ |
if FStoreType = 9 then |
530 |
+ |
PitchOrLinearSize := FWidth * FHeight div 2 |
531 |
+ |
else |
532 |
+ |
PitchOrLinearSize := FWidth * FDepth div 2; |
533 |
+ |
Depth := 0; |
534 |
+ |
MipMapCount := 1; |
535 |
+ |
x := FWidth; |
536 |
+ |
y := FHeight; |
537 |
+ |
while (x > 1) and (y > 1) do |
538 |
+ |
begin |
539 |
+ |
x := x div 2; |
540 |
+ |
y := y div 2; |
541 |
+ |
Inc(MipMapCount); |
542 |
+ |
end; |
543 |
+ |
for i := 1 to 11 do |
544 |
+ |
Reserved[i] := 0; |
545 |
+ |
with PIXELFORMAT do |
546 |
+ |
begin |
547 |
+ |
Size := 32; |
548 |
+ |
if FStoreType = 9 then |
549 |
+ |
Flags := DDPF_FOURCC |
550 |
+ |
else |
551 |
+ |
Flags := DDPF_RGB; |
552 |
+ |
end; |
553 |
+ |
end; |
554 |
+ |
end; |
555 |
+ |
LoadImageFromStream(data, FImage); |
556 |
+ |
{ |
557 |
+ |
if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then |
558 |
|
ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData) |
559 |
|
else |
560 |
|
ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData); |
561 |
< |
|
561 |
> |
} |
562 |
|
Self.FDataType := [DT_OniReverted, DT_Oni]; |
563 |
|
end; |
564 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
+ |
function TOniImage.GetImgSize(w,h, storetype: Integer): Integer; |
637 |
+ |
begin |
638 |
+ |
case storetype of |
639 |
+ |
0, 1, 2: |
640 |
+ |
Result := w*h*2; |
641 |
+ |
8: |
642 |
+ |
Result := w*h*4; |
643 |
+ |
9: |
644 |
+ |
Result := Max(1, w div 4) * Max(1, h div 4) * 8; |
645 |
+ |
else |
646 |
+ |
Result := -1; |
647 |
+ |
end; |
648 |
+ |
end; |
649 |
+ |
|
650 |
|
|
651 |
|
function TOniImage.GetImageDataSize(fading: Boolean): Integer; |
652 |
|
var |
653 |
|
size: Integer; |
654 |
|
x, y: Word; |
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 := -1; |
603 |
– |
end; |
604 |
– |
end; |
605 |
– |
|
655 |
|
begin |
656 |
|
x := Self.FWidth; |
657 |
|
y := Self.FHeight; |