refactor: spanify image utils (#44127)
* refactor: electron::util::AddImageSkiaRepFromJPEG() takes a span arg * refactor: electron::util::AddImageSkiaRepFromPNG() takes a span arg * refactor: electron::util::AddImageSkiaRepFromBuffer() takes a span arg * feat: add Node-buffer-to-base-span helper function * refactor: electron::api::NativeImage::CreateFromPNG() now takes a span param * refactor: electron::api::NativeImage::CreateFromJPEG() now takes a span param * refactor: use base::as_byte_span() * fix: -Wunsafe-buffer-usage warning in NativeImage::CreateFromNamedImage() Warning fixed by this commit: ../../electron/shell/common/api/electron_api_native_image_mac.mm:131:11: error: function introduces unsafe buffer manipulation [-Werror,-Wunsafe-buffer-usage] 131 | {reinterpret_cast<const uint8_t*>((char*)[png_data bytes]), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 132 | [png_data length]}); | ~~~~~~~~~~~~~~~~~~ ../../electron/shell/common/api/electron_api_native_image_mac.mm:131:11: note: See //docs/unsafe_buffers.md for help. * chore: add // SAFETY comment for Node-buffer-to-span func * chore: add // SAFETY comment for NSData-to-span func
This commit is contained in:
parent
d51ef7d794
commit
3d2f68a9df
7 changed files with 77 additions and 57 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/values.h"
|
||||
#include "gin/wrappable.h"
|
||||
|
@ -61,11 +62,10 @@ class NativeImage final : public gin::Wrappable<NativeImage> {
|
|||
static gin::Handle<NativeImage> Create(v8::Isolate* isolate,
|
||||
const gfx::Image& image);
|
||||
static gin::Handle<NativeImage> CreateFromPNG(v8::Isolate* isolate,
|
||||
const char* buffer,
|
||||
size_t length);
|
||||
static gin::Handle<NativeImage> CreateFromJPEG(v8::Isolate* isolate,
|
||||
const char* buffer,
|
||||
size_t length);
|
||||
base::span<const uint8_t> data);
|
||||
static gin::Handle<NativeImage> CreateFromJPEG(
|
||||
v8::Isolate* isolate,
|
||||
base::span<const uint8_t> data);
|
||||
static gin::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
|
||||
const base::FilePath& path);
|
||||
static gin::Handle<NativeImage> CreateFromBitmap(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue