Commit Graph
106 Commits
Author SHA1 Message Date
Vadim Zeitlin edde669769 Avoid warning about possibly uninitialized variable in a test
MSVS warns about "width" being possibly uninitialized, so do initialize
it and also initialize "height" for consistency.
2025-06-17 17:07:15 +02:00
Maarten Bent 312fa745d6 Update wxWEBPHandler tests 2025-05-10 17:19:30 +02:00
Hermann Höhne 15a2a622ec Add support for WebP image file format via libwebp. 2025-05-10 17:18:29 +02:00
Vadim Zeitlin 932bd6fa5e Add wxCursor constructor from wxBitmap
In all ports implementing creating wxCursor from wxImage the code for
creating it from wxBitmap was already there, so just factor it out to
allow using it directly, to avoid a conversion to and from wxImage when
we already have a wxBitmap.

For the other ports (wxX11 and wxDFB), leave this ctor unimplemented,
just as it was already the case for the one taking wxImage.
2025-05-05 21:48:33 +02:00
Vadim Zeitlin 376dcbff66 Add a pseudo-test to check wxImage resize quality
This provides at least some way of comparing the results of the
different rescaling algorithms.
2025-03-18 17:48:22 +01:00
Paul Cornett 4d5fbf5afa Fix BMP test under Wine
Unix builds / Ubuntu 24.04 wxGTK with ASAN (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxQt (push) Waiting to run
Unix builds / Ubuntu 18.04 wxX11 (push) Waiting to run
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Waiting to run
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Waiting to run
Unix builds / Ubuntu 24.04 wxGTK with UBSAN (push) Waiting to run
Unix builds / Ubuntu 18.04 wxDFB (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Waiting to run
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Waiting to run
CMake builds / Windows MSVC (push) Waiting to run
CMake builds / macOS 14 wxIOS (push) Waiting to run
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Waiting to run
CMake builds / macOS 14 wxOSX (push) Waiting to run
Mac builds / wxMac Universal C++14 (push) Waiting to run
Mac builds / wxMac ARM with ASAN (push) Waiting to run
Mac builds / wxiOS (push) Waiting to run
Mac builds / wxMac macOS 14 (push) Waiting to run
Mac builds / wxMac Intel C++17 (push) Waiting to run
Mac Xcode builds / iOS static Debug (push) Waiting to run
Mac Xcode builds / iOS Simulator static (push) Waiting to run
Mac Xcode builds / macOS dynamic Release (push) Waiting to run
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Waiting to run
MSW builds / wxMSW vs2019 DLL Release x64 (push) Waiting to run
MSW builds / wxMSW vs2019 Debug Win32 (push) Waiting to run
MSW builds / wxMSW vs2022 Release arm64 (push) Waiting to run
MSW builds / msw-msys2-clang (push) Waiting to run
MSW cross-builds / wxMSW 64 bits (push) Waiting to run
MSW cross-builds / wxMSW/Univ (push) Waiting to run
MSW cross-builds / wxMSW 32 bits (push) Waiting to run
Code Checks / Check Spelling (push) Waiting to run
Code Checks / Check Whitespace (push) Waiting to run
Code Checks / Check Mixed EOL (push) Waiting to run
Code Checks / Check C++ Style (push) Waiting to run
Code Checks / Check All Headers In allheaders.h (push) Waiting to run
Apparently Wine does not handle BMP exactly like Windows
2025-02-22 15:10:03 -08:00
Paul Cornett e7e352d5f4 Handle BMP alpha the same way Windows does
Windows ignores alpha unless the format is 8-bit ARGB, and alpha is not all zeros
2025-02-22 13:48:16 -08:00
Paul Cornett 45a7efd642 Up-scale BMP color components using Windows-compatible method
This allows tests to compare against native behavior under Windows
2025-02-22 13:01:52 -08:00
Vadim Zeitlin 7d2abd119b Save test images in the test if WX_TEST_SAVE_SCALED_IMAGES is set
Allow to easily dump the generated images without recompiling the test,
as was necessary before, by simply setting an environment variable.
2025-02-22 16:43:14 +01:00
Vadim Zeitlin 05c441ea55 Replace ASSERT_IMAGE_EQUAL_TO_FILE macro with a function
Don't use multiline macro when we can just use a function instead.
2025-02-22 16:43:14 +01:00
Paul Cornett 5ff83b400c Avoid assertion failure on BMP file with invalid or too-large size 2024-11-27 18:54:12 -08:00
Paul Cornett 05404fd379 Avoid negative shift count with valid BMP file
Detected by undefined behavior sanitizer, on a file with 16 bpp and a color
component of more than 8 bits. Fix by using a different, and more accurate,
method to scale color components to 8 bits.
2024-11-27 18:54:12 -08:00
Paul Cornett 443b64c11c Avoid memory overwrite on malformed BMP with invalid RLE data 2024-11-27 18:54:12 -08:00
Paul Cornett dc83c4ca0e Fix loading ICO files with fully transparent alpha
Windows behavior is to ignore alpha in that case. Broken by b21642b72b
2024-11-19 13:50:33 -08:00
Paul Cornett b321af212d Fix loading ICO files with alpha
The rules are different than for BMP files. Broken by b21642b72b (Fix loading
BMP files which use 32bpp but do not have valid alpha (#24939), 2024-11-04)
See #24955
2024-11-18 16:55:19 -08:00
paulcor b21642b72b Fix loading BMP files which use 32bpp but do not have valid alpha (#24939)
Based on the behavior of WIN32 LoadFile(), and the gdk-pixbuf BMP loader source
code, the alpha values are ignored unless the compression method is BI_BITFIELDS.
See #10915, #24219
2024-11-04 19:38:54 -08:00
Maarten Bent bab5e37c56 Add more wxCursor tests
Move tests to image.cpp.
2024-03-27 20:14:09 +01:00
Vadim ZeitlinandPB c2e5749443 Fix crash when reading truncated GIF image
Add a unit test case checking that we don't crash any longer and still
read the image meta data correctly, even if not the image itself.

Also add another check for EOF and possibly invalid "bits" value in
another place where we were not checking for it when reading from the
stream.

Closes #23409.

Co-authored-by: PB <PBfordev@gmail.com>
2023-07-02 18:06:03 +01:00
Brian Nixon e1e2e982e3 Restore old delta-RLE bitmap background setting
Revert the change introduced in b473163da2
and restore the setting of the background of delta-RLE bitmaps to the
first entry in the colour table. This retains earlier wxWidgets
behaviour and matches Windows `LoadImage()` with `LR_CREATEDIBSECTION`.

Closes #23638.

Closes #23657.
2023-06-20 22:19:47 +02:00
Brian Nixon b473163da2 Correct delta-RLE bitmap background colour
Use black instead of the first palette colour for the implicit
background for RLE bitmaps for consistency with Windows itself.

Closes #23599.
2023-06-04 00:38:39 +02:00
Brian Nixon d78e9fb1cb Correct loading of BI_BITFIELDS bitmaps
This fixes several minor bugs in the loading of `BI_BITFIELDS` bitmaps,
related to handling different header sizes and the colour and alpha
masks.

Closes #23601.
2023-06-03 21:07:40 +02:00
Brian Nixon 28d6234bfe Add image test to compare BMP creation methods
Check that loading BMP files directly using wxDIB and via wxImage
built-in support for them produces the same result (which wasn't the
case for the RLE-compressed bitmaps until the last commit).
2023-05-31 21:19:14 +01:00
Vadim Zeitlin 92664881fe Fix lack of unsharing in wxImage::Clear()
Calling Clear() wrongly modified any other wxImage objects reusing the
same data.

Fix this by adding the missing call to AllocExclusive() to this function
and also add a check for the image validity which was missing there as
well ever since this function was added back in fc3762b5fc (add
wxImage::Clear (patch by troelsk); closes #10141, 2009-01-09).

Also add a unit test.

Closes #23553.
2023-05-18 00:31:15 +02:00
Vadim Zeitlin d56d773a55 Remove CppUnit boilerplate in wxImage unit test
No real changes, just remove all the ugly compatibility macros.
2023-05-18 00:25:35 +02:00
Vadim Zeitlin 1afcac9ca5 Use wxSocketInitializer in the unit tests
Prefer using this RAII wrapper to explicit function calls, this is
shorter and more robust.
2023-05-18 00:06:21 +02:00
Vadim Zeitlin 338751756f Use std::vector<wxImage> instead of wxImageArray
Preserve the old dynamic array name but just define it as a thin class
deriving from std::vector and accept just vector in SaveAnimation().
2023-04-12 18:09:47 +01:00
Vadim Zeitlin 363f0988cf Replace wxScopedPtr with std::unique_ptr in the tests
Just use the standard class instead of the wx one, as they can be used
in exactly the same way.
2023-03-06 23:34:44 +01:00
Vadim Zeitlin 2b5bb6217d Disable test for loading images using wxURL
This requires an image accessible via HTTP (and not HTTPS) but we don't
have any such working URLs any longer since the recent change on
www.wxwidgets.org.

Still make it possible to test this manually by predefining an
environment variable containing the URL.
2022-12-31 19:21:33 +01:00
Vadim Zeitlin c9efe22763 Improve TIFF saving test code
Give more details in case of failure by using INFO() and use simple
CHECK()s instead of ugly WX_ASSERT_EQUAL_MESSAGE as they will show the
failing test anyhow.

No real changes.
2022-12-20 00:23:45 +01:00
Vadim Zeitlin 2ed4e6bee4 Improve wxImage::ChangeColours test code
Use a helper function to both make it shorter and provide more
information in case of a check failure: now the output will include the
name of the file, comparing with which failed, allowing to immediately
see which test failed.
2022-12-19 01:19:06 +01:00
Vadim Zeitlin f77390551f Relax checks for image equality in wxImage::ChangeColours
Allow difference of 1 as this is what we get when using -O2 with gcc 12.
2022-12-19 01:11:39 +01:00
Vadim Zeitlin 612dfa447a Log image information earlier in the image unit test
Use INFO() before some checks that may already fail to at least show in
which test the failures occur.
2022-12-18 03:30:44 +01:00
Vadim Zeitlin 895dd8424c Avoid harmless -Wunused-variable in unit tests
This warning used to be suppressed in Catch headers, but this is not the
case any longer, so work around it in the tests themselves now.
2022-10-18 18:39:13 +02:00
Vadim Zeitlin a3331c87d0 Stop using Catch::toString()
This function doesn't exist in Catch2 any longer, so prepare for the
upgrade by stopping to use it and converting things to string more
explicitly.

No real changes yet.
2022-10-18 18:39:13 +02:00
Vadim Zeitlin 4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
Vadim Zeitlin 0ef1cdcc21 Remove support for wxMotif
This port hasn't been updated for ages and is not used by anybody any
longer, so remove its code to facilitate maintenance.

Also remove references to this port from the documentation and most of
the other places (VMS-specific descrip.vms files still check for it
because it's not clear how to update them all), including configure.

Regenerate the latter and rebake all makefiles.

Finally document that this port is not available any longer.
2022-10-16 16:39:56 +02:00
Vadim Zeitlin 3ffc739e0e Only read BMP pixel data from stream in LoadBMPData()
This makes the code much more clear: LoadDib() now reads all the header
data while LoadBMPData() reads bitmap data only and doesn't read any
header values any more, unlike before.

It also allows not to have to pass neither bmpOffset nor IsBmp
parameters to LoadBMPData(), making its argument list much more
reasonable.

Finally, and, most importantly, it fixes loading bitmaps using
BI_BITFIELDS that was broken back in cccda9ef6b (Fix loading colour
palette from BMP file, 2019-12-28).

This commit also adds a unit test checking that this doesn't get broken
again without anyone noticing.

See #18634.

Closes #22499.
2022-06-08 23:49:18 +01:00
Vadim Zeitlin b918353306 Provide more details in case of image test failures
Add INFO() to show the file for which the error occurred.
2022-06-08 20:28:19 +01:00
Vadim Zeitlin 1a6c5746db Add a simple test allowing to load an arbitrary image
This test is disabled by default but useful for checking if the given
image can be loaded.
2022-06-08 19:27:11 +01:00
Vadim Zeitlin da05a3770f Use address of www.wxwidgets.org instead of its name in HTTP URLs
The name resolves to Cloudflare proxy which redirects all HTTP URLs to
HTTPS, which breaks the existing tests using HTTP, so prevent this from
happening by using the actual IP address instead.
2022-04-23 18:03:25 +01:00
Vadim Zeitlin 668563f2b0 Rewrite ImageTestCase using CATCH macros
Get rid of the ugly WX_ASSERT_MESSAGE() and also use REQUIRE/CATCH
directly instead of CppUnit compatibility macros.

Also use sections to execute the next loop iteration(s) even if the
current one fails.

This commit is best viewed ignoring whitespace-only changes.
2022-04-23 16:08:14 +01:00
Vadim Zeitlin 89a7a070ea Use WARN() instead of wxLogWarning() in the unit tests
The latter isn't shown at all by default while the former one is.
2022-04-23 15:36:40 +01:00
Vadim Zeitlin 684dd4a5a6 Use wxScopedPtr in wxImage unit test
Don't manage memory manually, this resulted in error leaks if any checks
failed.
2022-04-23 15:35:22 +01:00
Paul CornettandDavid Costanzo b04c1ace47 Avoid integer overflow when computing image data size in wxImage::Create()
See #19326

Co-Authored-By: David Costanzo <david_costanzo@yahoo.com>
2021-11-27 17:14:28 -08:00
David Costanzo 0985996d01 Fix loading of RLE bitmaps in wxBMPHandler
- Fix handling of delta encoding that change vertical position
- Fix handling of end-of-line encodings that are given mid-line
- Removed unnecessary computation for linepos

Add regression tests for the bitmaps using RLE and loading which
previously didn't work correctly.

Closes https://github.com/wxWidgets/wxWidgets/pull/2590

Closes #19318.
2021-11-18 15:37:03 +01:00
David Costanzo 20208cc81f Fix loading bitmaps with malformed biClrUsed field
Stop throwing std::bad_alloc when BMP has large/negative biClrUsed by
checking that biClrUsed has a reasonable value before attempting to
allocate however much memory it indicates.

Add unit tests showing the loading such invalid bitmaps now correctly
returns an error rather than throwing an exception.

Closes https://github.com/wxWidgets/wxWidgets/pull/2583

Closes #19295.
2021-11-06 16:12:04 +01:00
Artur Wieczorek 4a7ac90ce3 Fix wxImage::InitAlpha tests in release build
In release build exceptions are not thrown
so there is no need to check them.
2021-09-08 17:43:25 +02:00
Vadim Zeitlin 44a5cf78d1 Allow rescaling larger images in Win64 builds
Use wxUIntPtr rather than (unsigned) long in wxImage::ResampleNearest()
as long is still 32 bits under Win64 and so doesn't allow the code there
to work with images larger than 2^16 in either direction, when it could
be allowed in this case.

Document the current limits on the size of the image and add a unit test
checking that resizing images of size greater than 2^16 works in 64 bits.

See #18550.
2021-09-04 18:59:33 +01:00
Tomay 0e39566b3a Add wxImage Change{Saturation,Brightness,HSV,Lightness}()
Add more functions for manipulating wxImage colours.

Show using them in the same and add new unit tests for them.

This is a squashed commit of branch 'tomay3000/image-lightness'.

Closes https://github.com/wxWidgets/wxWidgets/pull/2310
2021-05-01 14:03:04 +02:00
Vadim Zeitlin 72500faf7c Add wxCursor ctor from XPM data to all ports
This just uses the existing wxImage ctor from XPM data and wxCursor ctor
from wxImage, but will allow the code creating cursors from XPM to still
work even when wxImage ctor from XPM is made explicit.

Add a trivial test just to check that the new ctor can be used.
2021-04-18 01:14:36 +01:00