Fixes & improvements to Image, including scaling #2
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 methods to
Image
. In the process, several issues withImage
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 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.Several examples and the
DisplayNeoPixel::showImage()
methods were passingImage
instances by value. This is now inefficient due to the deep copy. Since pass-by-reference semantics are required in these cases they are now passed by reference.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++