1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-08 00:40:17 +00:00

Add test for .ico & .cur loader

This commit is contained in:
Samuel Gomes 2024-07-21 19:29:12 +05:30
parent 5ae0893592
commit 34a6bdc2ce
54 changed files with 185 additions and 6 deletions

View file

@ -91,7 +91,7 @@ class CurIcoImage {
Header(Stream &stream) { ReadFromStream(stream); }
bool IsValid() { return reserved == 0 && (type == Type::Icon || type == Type::Cursor) && count > 0; }
auto IsValid() { return reserved == 0 && (type == Type::Icon || type == Type::Cursor) && count > 0; }
static auto GetStructSize() noexcept { return 6; } // sizeof(Header)
@ -285,7 +285,7 @@ class CurIcoImage {
/// @param fileName The name of the icon file
/// @param payloadData A pointer to the PNG payload
/// @param payloadSize The size of the PNG payload in bytes
static bool WriteToFile(const char *fileName, const uint8_t *payloadData, uint32_t payloadSize) {
static auto WriteToFile(const char *fileName, const uint8_t *payloadData, uint32_t payloadSize) {
if (fileName && fileName[0] && payloadData && payloadSize) {
auto file = fopen(fileName, "wb");
@ -601,9 +601,9 @@ class CurIcoImage {
auto src = input.GetData();
auto dst = *out_data;
auto pixels = width * height;
size_t pixels = width * height;
for (auto i = 0; i < pixels; i++) {
for (size_t i = 0; i < pixels; i++) {
auto r = *src;
++src;
auto g = *src;

View file

@ -0,0 +1,79 @@
DEFLNG A-Z
OPTION _EXPLICIT
$CONSOLE:ONLY
CHDIR _STARTDIR$
CONST ICON_DIR = "./icons/"
CONST TEST_FILE_FORMAT = "bmp"
CONST TOLERANCE_LIMIT = 0
RESTORE file_list
DIM fileName AS STRING: READ fileName
DO
DoImageFile ICON_DIR + fileName
READ fileName
LOOP WHILE LEN(fileName)
SYSTEM
file_list:
DATA 1bpp.ico
DATA 24bpp.ico
DATA 4bpp.cur
DATA 4bpp.ico
DATA 8bpp.ico
DATA 8bpp.cur
DATA bard.ico
DATA broom.ico
DATA cat.ico
DATA computer.ico
DATA dumb1.ico
DATA dumb2.ico
DATA pencil.ico
DATA please_wait.ico
DATA question.ico
DATA really_huge_duck.ico
DATA sample3.ico
DATA sample4.ico
DATA soft_drink.ico
DATA taco.ico
DATA terra_globe.ico
DATA thumbs_up.ico
DATA volme_dialog.ico
DATA word-icon.ico
DATA x.ico
DATA ""
SUB PrintImageDetails (handle AS LONG, testFileName AS STRING)
DIM fullTestFileName AS STRING: fullTestFileName = testFileName + "." + TEST_FILE_FORMAT
PRINT "Testing against "; fullTestFileName; " ("; _WIDTH(handle); "x"; _HEIGHT(handle); ")."
'_SAVEIMAGE fullTestFileName, handle
AssertImage2 handle, fullTestFileName, TOLERANCE_LIMIT
PRINT
END SUB
SUB DoImageFile (testFileName AS STRING)
DIM fileName AS STRING: fileName = testFileName
PRINT "Loading image from storage "; fileName; " ... ";
DIM h AS LONG: h = _LOADIMAGE(fileName, 32)
IF h < -1 THEN
PRINT "done."
PrintImageDetails h, testFileName
_FREEIMAGE h
ELSE
PRINT "failed!"
END IF
END SUB
'$INCLUDE:'../utilities/imageassert.bm'
'$INCLUDE:'../utilities/base64.bm'

View file

@ -0,0 +1,100 @@
Loading image from storage ./icons/1bpp.ico ... done.
Testing against ./icons/1bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!
Loading image from storage ./icons/24bpp.ico ... done.
Testing against ./icons/24bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!
Loading image from storage ./icons/4bpp.cur ... done.
Testing against ./icons/4bpp.cur.bmp ( 16 x 16 ).
Success, images are identical!
Loading image from storage ./icons/4bpp.ico ... done.
Testing against ./icons/4bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!
Loading image from storage ./icons/8bpp.ico ... done.
Testing against ./icons/8bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!
Loading image from storage ./icons/8bpp.cur ... done.
Testing against ./icons/8bpp.cur.bmp ( 32 x 32 ).
Success, images are identical!
Loading image from storage ./icons/bard.ico ... done.
Testing against ./icons/bard.ico.bmp ( 1360 x 1083 ).
Success, images are identical!
Loading image from storage ./icons/broom.ico ... done.
Testing against ./icons/broom.ico.bmp ( 600 x 600 ).
Success, images are identical!
Loading image from storage ./icons/cat.ico ... done.
Testing against ./icons/cat.ico.bmp ( 150 x 150 ).
Success, images are identical!
Loading image from storage ./icons/computer.ico ... done.
Testing against ./icons/computer.ico.bmp ( 474 x 474 ).
Success, images are identical!
Loading image from storage ./icons/dumb1.ico ... done.
Testing against ./icons/dumb1.ico.bmp ( 540 x 500 ).
Success, images are identical!
Loading image from storage ./icons/dumb2.ico ... done.
Testing against ./icons/dumb2.ico.bmp ( 540 x 500 ).
Success, images are identical!
Loading image from storage ./icons/pencil.ico ... done.
Testing against ./icons/pencil.ico.bmp ( 256 x 256 ).
Success, images are identical!
Loading image from storage ./icons/please_wait.ico ... done.
Testing against ./icons/please_wait.ico.bmp ( 404 x 325 ).
Success, images are identical!
Loading image from storage ./icons/question.ico ... done.
Testing against ./icons/question.ico.bmp ( 512 x 512 ).
Success, images are identical!
Loading image from storage ./icons/really_huge_duck.ico ... done.
Testing against ./icons/really_huge_duck.ico.bmp ( 4293 x 4293 ).
Success, images are identical!
Loading image from storage ./icons/sample3.ico ... done.
Testing against ./icons/sample3.ico.bmp ( 256 x 171 ).
Success, images are identical!
Loading image from storage ./icons/sample4.ico ... done.
Testing against ./icons/sample4.ico.bmp ( 256 x 192 ).
Success, images are identical!
Loading image from storage ./icons/soft_drink.ico ... done.
Testing against ./icons/soft_drink.ico.bmp ( 256 x 256 ).
Success, images are identical!
Loading image from storage ./icons/taco.ico ... done.
Testing against ./icons/taco.ico.bmp ( 966 x 764 ).
Success, images are identical!
Loading image from storage ./icons/terra_globe.ico ... done.
Testing against ./icons/terra_globe.ico.bmp ( 772 x 769 ).
Success, images are identical!
Loading image from storage ./icons/thumbs_up.ico ... done.
Testing against ./icons/thumbs_up.ico.bmp ( 463 x 294 ).
Success, images are identical!
Loading image from storage ./icons/volme_dialog.ico ... done.
Testing against ./icons/volme_dialog.ico.bmp ( 32 x 32 ).
Success, images are identical!
Loading image from storage ./icons/word-icon.ico ... done.
Testing against ./icons/word-icon.ico.bmp ( 512 x 512 ).
Success, images are identical!
Loading image from storage ./icons/x.ico ... done.
Testing against ./icons/x.ico.bmp ( 256 x 256 ).
Success, images are identical!

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

View file

@ -118,7 +118,7 @@ END SUB
FUNCTION GetColorDelta~& (color1 AS _UNSIGNED LONG, color2 AS _UNSIGNED LONG)
GetColorDelta = ABS(_RED32(color1) - _RED32(color2)) + ABS(_GREEN32(color1) - _GREEN32(color2)) + ABS(_BLUE32(color1) - _BLUE32(color2)) + ABS(_ALPHA32(color1) - _ALPHA32(color2))
GetColorDelta = ABS(_RED32(color1) - _RED32(color2)) + ABS(_GREEN32(color1) - _GREEN32(color2)) + ABS(_BLUE32(color1) - _BLUE32(color2))
END FUNCTION
@ -178,7 +178,7 @@ SUB AssertImage2 (originalActualImage AS LONG, expectedFileName AS STRING, toler
actualPixel = _MEMGET(actual, actual.OFFSET + pixelOffset, _UNSIGNED LONG)
expectedPixel = _MEMGET(expected, expected.OFFSET + pixelOffset, _UNSIGNED LONG)
IF actualPixel <> expectedPixel _ANDALSO GetColorDelta(actualPixel, expectedPixel) > toleranceLimit THEN
IF actualPixel <> expectedPixel _ANDALSO _ALPHA32(actualPixel) <> 0 _ANDALSO _ALPHA32(expectedPixel) <> 0 _ANDALSO GetColorDelta(actualPixel, expectedPixel) > toleranceLimit THEN
PRINT "Failure! Image pixels at ("; x&; ","; y&; ") differ, actual: 0x"; HEX$(actualPixel); ", expected: 0x"; HEX$(expectedPixel)
GOTO freeImages
END IF