Fixes & improvements to Image, including scaling & arbitrary rotation. #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds bilinear interpolation scaling and arbirary rotation methods to
Image
.In the process, several issues with
Image
were found & fixed:There was no destructor to free the
canvas
memory. This would cause a memory leak unless the client remembered to callclose()
A virtual destructor has been added to free this memory.There was no explicit copy & move constructor for
Image
This means whenever Image was copied or passed by value a 'shallow copy' was performed resulting in both instances referencing the same shared canvas memory. This works, and several examples were depending on it, but after the addition of the destructor it caused seg faults since the memory was free()'d several times. An explicit copy constuctor forImage
has been added to perform a 'deep copy' of thecanvas
memory. A C++11 'move' constructor has been added to avoid excessive deep copies being made when passingImage
as a temporary.The same logic for copy/move constructors also applies to assignment operators (operator=()) so these are added.
Image
(andColor
) are extensively passed by value within the library. This now potentially inefficient due to the deep copy. (if the move c'tor is not used) Since pass-by-reference semantics are required in these cases they are now passed by reference.Pass-by-(const)-reference changes also required many methods on
Image
andColor
that did not modify their members to be declaredconst
as well as allColor
preset constants.New c'tors and getters added to
Color
to support RGBA access as required by the new scaling method onImage
Also tidied up c'tors to use common helper methods.Used new/delete instead of malloc/free for heap memory use in
Image
Just coz it's more conventional in C++