Files
tubestation/dom/media/ImageConversion.h
Andrew Osmond 53532e454e Bug 1953601 - Support encoding frames that require scaling with the OpenH264 platform encoder. r=media-playback-reviewers,chunmin
This patch teaches ConvertToI420 how to scale supported formats in
addition to performing the conversion to I420. It attempts to do the
scale early if downscaling, and scale late if upscaling, to reduce
the number of pixels that it needs to convert. This is not always
possible because libyuv doesn't support scaling for all of our supported
formats. In those cases, we always scale late as I420.

If the format is already I420, then we can avoid using an intermediate
buffer for the scaling, and scale directly into the destination.

Additionally, FFmpegVideoEncoder is now able to take advantage of this
unified copy/scale operation and we can remove its own internal scaling
logic.

Differential Revision: https://phabricator.services.mozilla.com/D241694
2025-03-18 18:43:21 +00:00

63 lines
2.0 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ImageToI420Converter_h
#define ImageToI420Converter_h
#include "mozilla/AlreadyAddRefed.h"
#include "nsError.h"
#include "mozilla/gfx/Point.h"
namespace mozilla {
namespace gfx {
class SourceSurface;
enum class SurfaceFormat : int8_t;
} // namespace gfx
namespace layers {
class Image;
} // namespace layers
/**
* Gets a SourceSurface from given image.
*/
already_AddRefed<gfx::SourceSurface> GetSourceSurface(layers::Image* aImage);
/**
* Converts aImage to an I420 image and writes it to the given buffers.
*/
nsresult ConvertToI420(layers::Image* aImage, uint8_t* aDestY, int aDestStrideY,
uint8_t* aDestU, int aDestStrideU, uint8_t* aDestV,
int aDestStrideV, const gfx::IntSize& aDestSize);
/**
* Converts aImage to an NV12 image and writes it to the given buffers.
*/
nsresult ConvertToNV12(layers::Image* aImage, uint8_t* aDestY, int aDestStrideY,
uint8_t* aDestUV, int aDestStrideUV,
gfx::IntSize aDestSize);
/**
* Converts aImage into an RGBA image in a specified format and writes it to the
* given buffer.
*/
nsresult ConvertToRGBA(layers::Image* aImage,
const gfx::SurfaceFormat& aDestFormat,
uint8_t* aDestBuffer, int aDestStride);
/*
* Convert the RGBA image data from SRGB color into DisplayP3 color.
* aSrcBuffer and aDestBuffer can be the same.
*/
nsresult ConvertSRGBBufferToDisplayP3(uint8_t* aSrcBuffer,
const gfx::SurfaceFormat& aSrcFormat,
uint8_t* aDestBuffer, int aWidth,
int aHeight);
} // namespace mozilla
#endif /* ImageToI420Converter_h */