refactor: avoid minor code repetition in native_image.cc (#43703)

chore: delegate handle creation in NativeImage::Resize()

chore: delegate handle creation in NativeImage::Crop()

chore: delegate handle creation in NativeImage::CreateEmpty()

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-09-12 17:10:01 -05:00 коммит произвёл GitHub
Родитель 763d3983a1
Коммит 6c670c3f1f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 6 добавлений и 9 удалений

Просмотреть файл

@ -374,18 +374,15 @@ gin::Handle<NativeImage> NativeImage::Resize(gin::Arguments* args,
else if (quality && *quality == "better")
method = skia::ImageOperations::ResizeMethod::RESIZE_BETTER;
gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage(
image_.AsImageSkia(), method, size);
return gin::CreateHandle(
args->isolate(), new NativeImage(args->isolate(), gfx::Image(resized)));
return Create(args->isolate(),
gfx::Image{gfx::ImageSkiaOperations::CreateResizedImage(
image_.AsImageSkia(), method, size)});
}
gin::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
gfx::ImageSkia cropped =
gfx::ImageSkiaOperations::ExtractSubset(image_.AsImageSkia(), rect);
return gin::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(cropped)));
return Create(isolate, gfx::Image{gfx::ImageSkiaOperations::ExtractSubset(
image_.AsImageSkia(), rect)});
}
void NativeImage::AddRepresentation(const gin_helper::Dictionary& options) {
@ -437,7 +434,7 @@ bool NativeImage::IsTemplateImage() {
// static
gin::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new NativeImage(isolate, gfx::Image()));
return Create(isolate, gfx::Image{});
}
// static