| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestFPImage" -*- |
| 2 |
{ |
| 3 |
Copyright 2011-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Test FPC FpImage unit. } |
| 18 |
unit TestFPImage; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses |
| 23 |
CastleTester; |
| 24 |
|
| 25 |
type |
| 26 |
TTestFPImage = class(TCastleTestCase) |
| 27 |
published |
| 28 |
procedure TestJPEG; |
| 29 |
end; |
| 30 |
|
| 31 |
implementation |
| 32 |
|
| 33 |
uses Classes, FPImage, FPReadJPEG, SysUtils, |
| 34 |
CastleVectors, CastleImages, CastleUriUtils; |
| 35 |
|
| 36 |
procedure TTestFPImage.TestJPEG; |
| 37 |
|
| 38 |
procedure DoIt(const S: string; const GoodWidth, GoodHeight: Cardinal); |
| 39 |
var |
| 40 |
Stream: TMemoryStream; |
| 41 |
Reader: TFPCustomImageReader; |
| 42 |
Image: TFPMemoryImage; |
| 43 |
begin |
| 44 |
Stream := nil; |
| 45 |
Reader := nil; |
| 46 |
Image := nil; |
| 47 |
try |
| 48 |
// Stream := TFileStream.Create(S, fmOpenRead); |
| 49 |
Stream := TMemoryStream.Create; |
| 50 |
Stream.LoadFromFile(S); |
| 51 |
Stream.Position := 0; |
| 52 |
|
| 53 |
Reader := TFPReaderJPEG.Create; |
| 54 |
Image := TFPMemoryImage.Create(0, 0); |
| 55 |
|
| 56 |
Image.UsePalette := false; |
| 57 |
Image.LoadFromStream(Stream, Reader); |
| 58 |
{ test size, to test image was actually read } |
| 59 |
AssertTrue(GoodWidth = Image.Width); |
| 60 |
AssertTrue(GoodHeight = Image.Height); |
| 61 |
finally |
| 62 |
Image.Free; |
| 63 |
Reader.Free; |
| 64 |
Stream.Free; |
| 65 |
end; |
| 66 |
end; |
| 67 |
|
| 68 |
begin |
| 69 |
{ Reading this image fails with FPImage under FPC <= 2.4.0 } |
| 70 |
DoIt(UriToFilenameSafe('castle-data:/images/f023ours.jpg'), 512, 512); |
| 71 |
end; |
| 72 |
|
| 73 |
initialization |
| 74 |
RegisterTest(TTestFPImage); |
| 75 |
end. |