Fixes & improvements to Image, including scaling & arbitrary rotation.#3
Open
neildavis wants to merge 2 commits intowryan67:masterfrom
Open
Fixes & improvements to Image, including scaling & arbitrary rotation.#3neildavis wants to merge 2 commits intowryan67:masterfrom
neildavis wants to merge 2 commits intowryan67:masterfrom
Conversation
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 call `close()` 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 for `Image` has been added to perform a 'deep copy' of the `canvas` memory. A C++11 'move' constructor has been added to avoid excessive deep copies being made when passing `Image` as a temporary. * The same logic for copy/move constructors also applies to assignment operators (operator=()) so these are added. * `Image` (and `Color`) 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` and `Color` that did not modify their members to be declared `const` as well as all `Color` preset constants. * New c'tors and getters added to `Color` to support RGBA access as required by the new scaling method on `Image` 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++
6f9ff62 to
d0299a3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Imagewere found & fixed:There was no destructor to free the
canvasmemory. 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
ImageThis 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 forImagehas been added to perform a 'deep copy' of thecanvasmemory. A C++11 'move' constructor has been added to avoid excessive deep copies being made when passingImageas 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
ImageandColorthat did not modify their members to be declaredconstas well as allColorpreset constants.New c'tors and getters added to
Colorto support RGBA access as required by the new scaling method onImageAlso tidied up c'tors to use common helper methods.Used new/delete instead of malloc/free for heap memory use in
ImageJust coz it's more conventional in C++