Add support for YUV resource formats

* We handle 4:4:4, 4:2:2, and 4:2:0, with packed, 2-plane and 3-plane formats,
  for 8, 10, 12, and 16 bit depths.
* This covers most common formats but still leaves a few out - NV11, palettised
  formats, V208/V408 JPG formats.
This commit is contained in:
baldurk
2018-12-11 19:57:20 +00:00
parent 2411ce70ea
commit 68b23c5f62
17 changed files with 2726 additions and 1296 deletions
+77
View File
@@ -184,6 +184,42 @@ struct ResourceFormat
:rtype: ``bool``
)");
bool srgbCorrected() const { return (flags & ResourceFormat_SRGB) != 0; }
DOCUMENT(R"(Get the subsampling rate for a YUV format. Only valid when :data:`type` is
a YUV format like :attr:`ResourceFormatType.YUV8`.
For other formats, 0 is returned.
:return: The subsampling rate, e.g. 444 for 4:4:4 or 420 for 4:2:0
:rtype: ``int``
)");
uint32_t yuvSubsampling() const
{
if(flags & ResourceFormat_444)
return 444;
else if(flags & ResourceFormat_422)
return 422;
else if(flags & ResourceFormat_420)
return 420;
return 0;
}
DOCUMENT(R"(Get the number of planes for a YUV format. Only valid when :data:`type` is
a YUV format like :attr:`ResourceFormatType.YUV8`.
For other formats, 1 is returned.
:return: The number of planes
:rtype: ``int``
)");
uint32_t yuvPlaneCount() const
{
if(flags & ResourceFormat_3Planes)
return 3;
else if(flags & ResourceFormat_2Planes)
return 2;
return 1;
}
DOCUMENT(R"(Set BGRA order flag. See :meth:`bgraOrder`.
:param bool flag: The new flag value.
@@ -208,6 +244,38 @@ struct ResourceFormat
flags &= ~ResourceFormat_SRGB;
}
DOCUMENT(R"(Set YUV subsampling rate. See :meth:`yuvSubsampling`.
The value should be e.g. 444 for 4:4:4 or 422 for 4:2:2. Invalid values will result in 0 being set.
:param int subsample: The new subsampling rate.
)");
void setYUVSubsampling(uint32_t subsampling)
{
flags &= ~ResourceFormat_SubSample_Mask;
if(subsampling == 444)
flags |= ResourceFormat_444;
else if(subsampling == 422)
flags |= ResourceFormat_422;
else if(subsampling == 420)
flags |= ResourceFormat_420;
}
DOCUMENT(R"(Set number of YUV planes. See :meth:`yuvPlaneCount`.
Invalid values will result in 1 being set.
:param int planes: The new number of YUV planes.
)");
void setYUVPlaneCount(uint32_t planes)
{
flags &= ~ResourceFormat_Planes_Mask;
if(planes == 2)
flags |= ResourceFormat_2Planes;
else if(planes == 3)
flags |= ResourceFormat_3Planes;
}
ResourceFormatType type;
DOCUMENT("The :class:`type <CompType>` of each component.");
@@ -222,6 +290,15 @@ private:
{
ResourceFormat_BGRA = 0x001,
ResourceFormat_SRGB = 0x002,
ResourceFormat_444 = 0x004,
ResourceFormat_422 = 0x008,
ResourceFormat_420 = 0x010,
ResourceFormat_SubSample_Mask = 0x01C,
ResourceFormat_2Planes = 0x020,
ResourceFormat_3Planes = 0x040,
ResourceFormat_Planes_Mask = 0x060,
};
uint16_t flags;
+4 -1
View File
@@ -82,7 +82,10 @@ std::string DoStringise(const ResourceFormatType &el)
STRINGISE_ENUM_CLASS(D24S8);
STRINGISE_ENUM_CLASS(D32S8);
STRINGISE_ENUM_CLASS(S8);
STRINGISE_ENUM_CLASS(YUV);
STRINGISE_ENUM_CLASS(YUV8);
STRINGISE_ENUM_CLASS(YUV10);
STRINGISE_ENUM_CLASS(YUV12);
STRINGISE_ENUM_CLASS(YUV16);
}
END_ENUM_STRINGISE();
}
+22 -3
View File
@@ -1206,9 +1206,25 @@ or formats that don't have equal byte-multiple sizes for each channel.
Each pixel is an 8 bit stencil value.
.. data:: YUV
.. data:: YUV8
The pixel data is in an opaque YUV format.
The pixel data is 8-bit in YUV subsampled format. More information about subsampling setup is
stored separately
.. data:: YUV10
The pixel data is 10-bit in YUV subsampled format. More information about subsampling setup is
stored separately
.. data:: YUV12
The pixel data is 12-bit in YUV subsampled format. More information about subsampling setup is
stored separately
.. data:: YUV16
The pixel data is 16-bit in YUV subsampled format. More information about subsampling setup is
stored separately
.. data:: PVRTC
@@ -1239,7 +1255,10 @@ enum class ResourceFormatType : uint8_t
D24S8,
D32S8,
S8,
YUV,
YUV8,
YUV10,
YUV12,
YUV16,
PVRTC,
};