electron/shell/common/skia_util.h
Charles Kerr 3d2f68a9df
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
2024-10-10 09:34:55 -04:00

45 lines
1.2 KiB
C++

// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_SKIA_UTIL_H_
#define ELECTRON_SHELL_COMMON_SKIA_UTIL_H_
#include <cstdint>
#include "base/containers/span.h"
namespace base {
class FilePath;
} // namespace base
namespace gfx {
class ImageSkia;
}
namespace electron::util {
bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
const base::FilePath& path);
bool AddImageSkiaRepFromBuffer(gfx::ImageSkia* image,
base::span<const uint8_t> data,
int width,
int height,
double scale_factor);
bool AddImageSkiaRepFromJPEG(gfx::ImageSkia* image,
base::span<const uint8_t> data,
double scale_factor);
bool AddImageSkiaRepFromPNG(gfx::ImageSkia* image,
base::span<const uint8_t> data,
double scale_factor);
#if BUILDFLAG(IS_WIN)
bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon);
#endif
} // namespace electron::util
#endif // ELECTRON_SHELL_COMMON_SKIA_UTIL_H_