frame: implemented set pixel function
Counterpart to Frame::GetPixel()
This commit is contained in:
@@ -93,6 +93,19 @@ bool Frame::contains_pixel(int x, int y) const
|
||||
return (is_allocated() && x >= 0 && x < width() && y >= 0 && y < height());
|
||||
}
|
||||
|
||||
void Frame::set_pixel(int x, int y, const Color &c)
|
||||
{
|
||||
if (!contains_pixel(x, y)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int pixel_index = y * linesize_pixels() + x;
|
||||
|
||||
int byte_offset = PixelFormat::GetBufferSize(video_params().format(), pixel_index, 1);
|
||||
|
||||
c.toData(data_.data() + byte_offset, video_params().format());
|
||||
}
|
||||
|
||||
const rational &Frame::sample_aspect_ratio() const
|
||||
{
|
||||
return sample_aspect_ratio_;
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
|
||||
Color get_pixel(int x, int y) const;
|
||||
bool contains_pixel(int x, int y) const;
|
||||
void set_pixel(int x, int y, const Color& c);
|
||||
|
||||
const rational& sample_aspect_ratio() const;
|
||||
void set_sample_aspect_ratio(const rational& sample_aspect_ratio);
|
||||
|
||||
+27
-9
@@ -67,15 +67,7 @@ Color Color::fromHsv(const float &h, const float &s, const float &v)
|
||||
|
||||
Color::Color(const char *data, const PixelFormat::Format &format)
|
||||
{
|
||||
OIIO::convert_types(PixelFormat::GetOIIOTypeDesc(format),
|
||||
data,
|
||||
PixelFormat::GetOIIOTypeDesc(PixelFormat::PIX_FMT_RGB32F),
|
||||
data_,
|
||||
PixelFormat::FormatHasAlphaChannel(format) ? kRGBAChannels : kRGBChannels);
|
||||
|
||||
if (!PixelFormat::FormatHasAlphaChannel(format)) {
|
||||
set_alpha(1.0f);
|
||||
}
|
||||
*this = fromData(data, format);
|
||||
}
|
||||
|
||||
Color::Color(const QColor &c)
|
||||
@@ -202,6 +194,32 @@ float Color::lightness() const
|
||||
return l;
|
||||
}
|
||||
|
||||
void Color::toData(char *data, const PixelFormat::Format &format) const
|
||||
{
|
||||
OIIO::convert_types(PixelFormat::GetOIIOTypeDesc(PixelFormat::PIX_FMT_RGB32F),
|
||||
data_,
|
||||
PixelFormat::GetOIIOTypeDesc(format),
|
||||
data,
|
||||
PixelFormat::FormatHasAlphaChannel(format) ? kRGBAChannels : kRGBChannels);
|
||||
}
|
||||
|
||||
Color Color::fromData(const char *data, const PixelFormat::Format &format)
|
||||
{
|
||||
Color c;
|
||||
|
||||
OIIO::convert_types(PixelFormat::GetOIIOTypeDesc(format),
|
||||
data,
|
||||
PixelFormat::GetOIIOTypeDesc(PixelFormat::PIX_FMT_RGB32F),
|
||||
c.data_,
|
||||
PixelFormat::FormatHasAlphaChannel(format) ? kRGBAChannels : kRGBChannels);
|
||||
|
||||
if (!PixelFormat::FormatHasAlphaChannel(format)) {
|
||||
c.set_alpha(1.0f);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
QColor Color::toQColor() const
|
||||
{
|
||||
QColor c;
|
||||
|
||||
@@ -84,6 +84,8 @@ public:
|
||||
float* data() {return data_;}
|
||||
const float* data() const {return data_;}
|
||||
|
||||
void toData(char* data, const PixelFormat::Format& format) const;
|
||||
|
||||
static Color fromData(const char* data, const PixelFormat::Format& format);
|
||||
|
||||
QColor toQColor() const;
|
||||
|
||||
Reference in New Issue
Block a user