|
@@ -19,6 +19,7 @@
|
|
|
#include "gin/handle.h"
|
|
|
#include "shell/common/gin_converters/image_converter.h"
|
|
|
#include "shell/common/gin_helper/promise.h"
|
|
|
+#include "shell/common/mac_util.h"
|
|
|
#include "ui/gfx/color_utils.h"
|
|
|
#include "ui/gfx/geometry/size.h"
|
|
|
#include "ui/gfx/image/image_skia.h"
|
|
@@ -26,19 +27,6 @@
|
|
|
|
|
|
namespace electron::api {
|
|
|
|
|
|
-namespace {
|
|
|
-
|
|
|
-base::span<const uint8_t> as_byte_span(NSData* data) {
|
|
|
- // SAFETY: There is no NSData API that passes the UNSAFE_BUFFER_USAGE
|
|
|
- // test, so let's isolate the unsafe API use into this function. Instead of
|
|
|
- // calling '[data bytes]' and '[data length]' directly, the rest of our
|
|
|
- // code should prefer to use spans returned by this function.
|
|
|
- return UNSAFE_BUFFERS(base::span{
|
|
|
- reinterpret_cast<const uint8_t*>([data bytes]), [data length]});
|
|
|
-}
|
|
|
-
|
|
|
-} // namespace
|
|
|
-
|
|
|
NSData* bufferFromNSImage(NSImage* image) {
|
|
|
CGImageRef ref = [image CGImageForProposedRect:nil context:nil hints:nil];
|
|
|
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCGImage:ref];
|
|
@@ -140,7 +128,8 @@ gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
|
|
|
NSData* png_data = bufferFromNSImage(image);
|
|
|
|
|
|
if (args->GetNext(&hsl_shift) && hsl_shift.size() == 3) {
|
|
|
- auto gfx_image = gfx::Image::CreateFrom1xPNGBytes(as_byte_span(png_data));
|
|
|
+ auto gfx_image = gfx::Image::CreateFrom1xPNGBytes(
|
|
|
+ electron::util::as_byte_span(png_data));
|
|
|
color_utils::HSL shift = {safeShift(hsl_shift[0], -1),
|
|
|
safeShift(hsl_shift[1], 0.5),
|
|
|
safeShift(hsl_shift[2], 0.5)};
|
|
@@ -150,7 +139,8 @@ gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
|
|
|
.AsNSImage());
|
|
|
}
|
|
|
|
|
|
- return CreateFromPNG(args->isolate(), as_byte_span(png_data));
|
|
|
+ return CreateFromPNG(args->isolate(),
|
|
|
+ electron::util::as_byte_span(png_data));
|
|
|
}
|
|
|
}
|
|
|
|