Fixes & improvements to Image, including scaling#2
Fixes & improvements to Image, including scaling#2neildavis wants to merge 1 commit intowryan67:masterfrom
Conversation
This commit adds bilinear interpolation scaling 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 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. * Several examples and the `DisplayNeoPixel::showImage()` methods were passing `Image`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 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++
|
Closing as further work has identified a potential issue I need to resolve first. Will reopen when resolved. |
|
I really liked the idea of using the & (pass-by-reference) to speed up image processing. There were a lot of changes in this pull request and I've still not had time to review all of them. I may have some time this weekend, so I could work on the draw functions to switch them to pass-by-reference, but I'll wait if you'd rather incorporate the changes into your next pull request. |
|
BTW, one thing I've been wanting to work on is true-type fonts, wouldn't that be awesome! If only I had a clone of myself to work on Raspberry Pi projects all day long while the other me goes to my regular job. sigh. |
As it stands (prior to this PR), passing The reason I closed this is that I was doing further work to add arbitrary
Your call. I hope to open a new PR soon, but rebasing a few pass-by-ref changes shouldn't cause much disruption. |
|
Opened #3 which supercedes this PR. Few more changes in that one since I had to 'chase through' the |
This commit adds bilinear interpolation scaling methods to
Image. In the process, several issues withImagewere 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 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.Several examples and the
DisplayNeoPixel::showImage()methods were passingImageinstances 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
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++