Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calculations for YUV / planar images #479

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/ppx/graphics_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ class TextureOptions
const std::filesystem::path& path,
grfx::Texture** ppTexture,
const TextureOptions& options);

// Splits the frames from a raw video, based on the format of the frames,
// and metadata such as height and width. This assumes raw video, with no
// metadata in the file itself, and no audio tracks (such as a camera
// feed). Returns if the operation succeeded.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Returns if the operation succeeded"? Did you mean to say "Returns X", cause couldn't it return error code as well?

// path: The path to the file containing the video.
// format: Describes the video format; this is important for determining
// the size of a frame.
// width: The width of each frame, in pixels, with no subsampling applied.
// height: The height of each frame, in pixels, with no subsampling applied.
// pFrames: A vector where resulting frames will be stored. This should not
// be null.
friend Result LoadFramesFromRawVideo(
anishmgoyal marked this conversation as resolved.
Show resolved Hide resolved
Keenuts marked this conversation as resolved.
Show resolved Hide resolved
const std::filesystem::path& path,
grfx::Format format,
uint32_t width,
uint32_t height,
std::vector<std::vector<char>>* pFrames);
};

//! @fn CreateTextureFromBitmap
Expand Down
68 changes: 68 additions & 0 deletions include/ppx/grfx/grfx_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define ppx_grfx_format_h

#include <cstdint>
#include <optional>
#include <vector>

namespace ppx {
namespace grfx {
Expand Down Expand Up @@ -150,6 +152,8 @@ enum Format
FORMAT_BC7_UNORM,
FORMAT_BC7_SRGB,

FORMAT_G8_B8R8_2PLANE_420_UNORM,

FORMAT_COUNT,
};

Expand All @@ -163,6 +167,14 @@ enum FormatAspectBit
FORMAT_ASPECT_DEPTH_STENCIL = FORMAT_ASPECT_DEPTH | FORMAT_ASPECT_STENCIL,
};

enum FormatChromaSubsampling
{
FORMAT_CHROMA_SUBSAMPLING_UNDEFINED = 0x0,
FORMAT_CHROMA_SUBSAMPLING_444 = 0x1,
FORMAT_CHROMA_SUBSAMPLING_422 = 0x2,
FORMAT_CHROMA_SUBSAMPLING_420 = 0x3,
};

enum FormatComponentBit
{
FORMAT_COMPONENT_UNDEFINED = 0x0,
Expand Down Expand Up @@ -255,11 +267,67 @@ struct FormatDesc
// In case of packed or compressed formats, this field is invalid
// and the offsets will be set to -1.
FormatComponentOffset componentOffset;

// In chroma-based formats, there can be subsampling of chroma color components
// of an image, to reduce image size.
FormatChromaSubsampling chromaSubsampling;

// If true, this is a planar format that does not store all image components
// in a single block. E.G. YCbCr formats, where Cb and Cr may be defined in
// a separate plane than Y values, and have a different resolution.
bool isPlanar;
};

enum FormatPlaneChromaType
{
FORMAT_PLANE_CHROMA_TYPE_UNDEFINED,
FORMAT_PLANE_CHROMA_TYPE_LUMA,
FORMAT_PLANE_CHROMA_TYPE_CHROMA,
};

// Note: this is distinct from FormatComponentBit because in the case of a
// member of an image plane, we only want to be able to specify one component
// bit.
enum FormatPlaneComponentType
{
FORMAT_PLANE_COMPONENT_TYPE_UNDEFINED,
FORMAT_PLANE_COMPONENT_TYPE_RED,
FORMAT_PLANE_COMPONENT_TYPE_GREEN,
FORMAT_PLANE_COMPONENT_TYPE_BLUE,
};

struct FormatPlaneDesc
{
struct Member
{
// For debugging purposes: the color component that this plane member
// describes.
FormatPlaneComponentType component;
// This defines whether this is a luma value, chroma value, or neither
// (will be set to undefined for non-YCbCr types).
FormatPlaneChromaType type;
// Number of bits used to describe this component.
int bitCount;
};

struct Plane
{
std::vector<Member> members;
};

FormatPlaneDesc(std::initializer_list<std::initializer_list<Member>>&& planes);

std::vector<Plane> planes;
};

//! @brief Gets a description of the given /b format.
const FormatDesc* GetFormatDescription(grfx::Format format);

// Gets a description of planes in the format, if the format is planar.
// If the format is not planar, returns nullopt.
const std::optional<FormatPlaneDesc> GetFormatPlaneDescription(
grfx::Format format);

const char* ToString(grfx::Format format);

} // namespace grfx
Expand Down
Loading
Loading