--- oup/current/Global/OniImgClass.pas 2007/05/26 14:24:55 193 +++ oup/current/Global/OniImgClass.pas 2007/05/26 20:41:34 199 @@ -15,6 +15,7 @@ type function GetHeight(MipGen: Integer): Integer; function GetImageFormat: TImageFormat; procedure SetImageFormat(Format: TImageFormat); + function pGetImageFormatInfo: TImageFormatInfo; function GetHasMipMaps: Boolean; protected public @@ -23,6 +24,7 @@ type property Width[MipGen: Integer]: Integer read GetWidth; property Height[MipGen: Integer]: Integer read GetHeight; property Format: TImageFormat read GetImageFormat write SetImageFormat; + property FormatInfo: TImageFormatInfo read pGetImageFormatInfo; property HasMipMaps: Boolean read GetHasMipMaps; constructor Create; @@ -45,7 +47,6 @@ type implementation -//uses Functions; uses Img_DDSTypes, ImagingComponents; @@ -130,6 +131,13 @@ begin end; +function TOniImage.pGetImageFormatInfo: TImageFormatInfo; +begin + if Length(FImages) > 0 then + GetImageFormatInfo(FImages[0].Format, Result); +end; + + function TOniImage.GetHasMipMaps: Boolean; begin Result := Length(FImages) > 1; @@ -170,26 +178,29 @@ type x_txmp, y_txmp: Word; x_pspc, y_pspc: Word; w, h: Word; - imgdata: TByteData; + imgdata: TImageData; used: Boolean; end; const PartMatch: array[0..8] of Byte = (0, 3, 6, 1, 4, 7, 2, 5, 8); + stretch_x: Integer = 1; + stretch_y: Integer = 1; var - x, y, pixel: Word; + x, y: Word; i: Integer; PSpc: TPSpc; txmpimg: TOniImage; - txmpdata: TByteData; +// txmpdata: TByteData; parts: array[0..8] of TPart; part: Byte; cols: array[0..2] of Word; rows: array[0..2] of Word; col, row: Byte; + + pspcimage: TImageData; begin -(* ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc); PSpc.TXMP := PSpc.TXMP div 256; if PSpc.TXMP = 0 then @@ -198,16 +209,11 @@ begin Exit; end; txmpimg := TOniImage.Create; - txmpimg.LoadFromTXMP(ConnectionID, PSpc.TXMP); - txmpimg.DecodeImageTo32bit; -// txmpimg.WriteToBMP('C:\file.bmp'); - txmpimg.GetAs32bit(txmpdata); -{ ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height)); - for i:=0 to High(txmpdata) do - txmpimg.Data[i]:=txmpdata[i]; - txmpimg.WriteToBMP('D:\file2.bmp'); -} - with PSpc do + txmpimg.Load(ConnectionID, PSpc.TXMP); + CloneImage(txmpimg.Image[1], pspcimage); + txmpimg.Free; + + with pspc do begin for i := 0 to 2 do begin @@ -221,8 +227,8 @@ begin row := i mod 3; if (p2[i].X > 0) or (p2[i].Y > 0) then begin - parts[part].x_txmp := p1[i].X - 1; - parts[part].y_txmp := p1[i].Y - 1; + parts[part].x_txmp := p1[i].X;// - 1; + parts[part].y_txmp := p1[i].Y;// - 1; parts[part].x_pspc := 0; if col > 0 then for x := 0 to col - 1 do @@ -231,24 +237,17 @@ begin if row > 0 then for y := 0 to row - 1 do Inc(parts[part].y_pspc, rows[y]); - parts[part].w := p2[i].X - p1[i].X + 1; - parts[part].h := p2[i].Y - p1[i].Y + 1; + parts[part].w := Max(p2[i].X - p1[i].X, 1);// + 1; + parts[part].h := Max(p2[i].Y - p1[i].Y, 1);// + 1; parts[part].used := True; cols[col] := parts[part].w; rows[row] := parts[part].h; - SetLength(parts[part].imgdata, parts[part].w * parts[part].h * 4); - for y := 0 to parts[part].h - 1 do - begin - for x := 0 to parts[part].w - 1 do - begin - for pixel := 0 to 3 do - begin - parts[part].imgdata[(y * parts[part].w + x) * 4 + pixel] := - txmpdata[((parts[part].y_txmp + y) * txmpimg.Width + - parts[part].x_txmp + x) * 4 + pixel]; - end; - end; - end; + + NewImage(parts[part].w, parts[part].h, pspcimage.Format, parts[part].imgdata); + + CopyRect(pspcimage, + parts[part].x_txmp, parts[part].y_txmp, parts[part].w, parts[part].h, + parts[part].imgdata, 0, 0); end else begin @@ -258,41 +257,62 @@ begin end; - txmpimg.Free; - txmpimg := TOniImage.Create; for i := 0 to 8 do begin if parts[i].used then begin - SetLength(txmpimg.FData, Length(parts[i].imgdata)); - for pixel := 0 to High(parts[i].imgdata) do - txmpimg.Data[pixel] := parts[i].imgdata[pixel]; - txmpimg.Width := parts[i].w; - txmpimg.Height := parts[i].h; - txmpimg.StoreType := 8; - txmpimg.DataType := [DT_Decoded32]; - txmpimg.Depth := 32; - txmpimg.WriteToBMP('M:\' + IntToStr(i) + '.bmp'); +// SaveImageToFile('M:\' + IntToStr(i) + '.bmp', parts[i].imgdata); end; end; - txmpimg.Free; - Self.FWidth := 0; - Self.FHeight := 0; - for i := 0 to 2 do + SetLength(FImages, 1); + x := cols[0] + cols[1] * stretch_x + cols[2]; + y := rows[0] + rows[1] * stretch_y + rows[2]; + + NewImage(x, y, pspcimage.Format, FImages[0]); + + x := 0; + for col := 0 to 2 do begin - Inc(Self.FWidth, cols[i]); - Inc(Self.FHeight, rows[i]); + y := 0; + for row := 0 to 2 do + begin + part := row*3 + col; + if parts[part].used then + begin + if (row = 1) and (col = 1) then + StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h, + FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest) + else + if (row = 1) then + StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h, + FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest) + else + if (col = 1) then + StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h, + FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest) + else + CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h, + FImages[0], x, y ); + if row = 1 then + y := y + parts[part].h * stretch_y + else + y := y + parts[part].h; + end; + end; + if cols[col] > 0 then + begin + if (col = 1) then + x := x + parts[part].w * stretch_x + else + x := x + parts[part].w; + end; end; - SetLength(Self.FData, Self.FWidth * Self.FHeight * 4); - - //Combine data parts - Self.FDepth := 32; - Self.FStoreType := 8; - Self.FDataType := [DT_Decoded32]; - // Self.RevertImage; -*) + FreeImage(pspcimage); + for i := 0 to 8 do + if parts[i].used then + FreeImage(parts[i].imgdata); end; @@ -455,7 +475,7 @@ end; function TOniImage.LoadFromTXMB(ConnectionID, FileID: Integer): Boolean; var - i, x, y, x2, y2, pixelid, imgid: Integer; + i, x, y, imgid: Integer; rows, cols: Word; linkcount: Integer; link: Integer;