-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api(IB)!: Add span based ImageBuf methods for getpixel/setpixel
Next round of making safer interfaces. Primarily, this adds new ImageBuf::get_pixels, set_pixels, setpixel, getpixel, interppixel, interppixel_NDC, interppixel_bucibuc, interppixel_bicubic_NDC. The old ones took raw pointers and implied sizes -- these still exist but are considered "unsafe" and aimed at experts and special cases. (If a downstream project wants to be sure not to use them, they can define symbol "OIIO_IMAGEBUF_DEPRECATE_RAW_PTR" before including imagebuf.h to force deprecation warnings.) The new additions instead take a span -- a combined pointer and length that can be bounds-checked (in debug mode). I strongly encourage people to use the new interface, as it forces the caller to think hard about the exact region of memory that's ok to read from or write to, and then for the OIIO side to honor that and enfoce/debug with bounds checks against that if we add such plumbing. Along the way, I added some interesting helper functions: In span.h: * `span_within()` checks that one byte span lies entirely within another. * `check_span()` checks if a pointer and length lies entirely within a span. * `OIIO_ALLOCA_SPAN` is a macro much like OIIO_ALLOCA, except what it returns is a span rather than a raw pointer to the stack-allocated region. In imageio.h: * `span_from_buffer()`/`cspan_from_bufffer()` : Given a raw pointer, pixel data type (TypeDesc), and image dimensions and strides, returns a byte stride describing the extend of memory that encompasses all pixels laid out by that description. I hope the switch to spans it not very onerous for people. I really think that this will help us write more solid and deliberate code to begin with, and when things do go wrong, the various debug-mode checks and assertions that spans provide should help us more quickly identify exactly where buffer overruns and the like occurred. Signed-off-by: Larry Gritz <lg@larrygritz.com>
- Loading branch information
Showing
21 changed files
with
538 additions
and
220 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.