mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Remove extra pixel consistently
This commit is contained in:
@@ -21,10 +21,10 @@ class ImageData : public QSharedData
|
||||
public:
|
||||
typedef Pixel_T pixel_type;
|
||||
|
||||
ImageData(unsigned width, unsigned height, const Pixel_T background) :
|
||||
ImageData(int width, int height, const Pixel_T background) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
_pixels(new Pixel_T[width * height + 1])
|
||||
_pixels(new Pixel_T[static_cast<ssize_t>(width * height)])
|
||||
{
|
||||
std::fill(_pixels, _pixels + width * height, background);
|
||||
}
|
||||
@@ -33,9 +33,9 @@ public:
|
||||
QSharedData(other),
|
||||
_width(other._width),
|
||||
_height(other._height),
|
||||
_pixels(new Pixel_T[other._width * other._height + 1])
|
||||
_pixels(new Pixel_T[other._width * other._height])
|
||||
{
|
||||
memcpy(_pixels, other._pixels, static_cast<ulong>(other._width) * static_cast<ulong>(other._height) * sizeof(Pixel_T));
|
||||
memcpy(_pixels, other._pixels, other._width * other._height * sizeof(Pixel_T));
|
||||
}
|
||||
|
||||
ImageData& operator=(ImageData rhs)
|
||||
@@ -71,42 +71,42 @@ public:
|
||||
delete[] _pixels;
|
||||
}
|
||||
|
||||
inline unsigned width() const
|
||||
inline int width() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
inline unsigned height() const
|
||||
inline int height() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
uint8_t red(unsigned pixel) const
|
||||
uint8_t red(int pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->red;
|
||||
}
|
||||
|
||||
uint8_t green(unsigned pixel) const
|
||||
uint8_t green(int pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->green;
|
||||
}
|
||||
|
||||
uint8_t blue(unsigned pixel) const
|
||||
uint8_t blue(int pixel) const
|
||||
{
|
||||
return (_pixels + pixel)->blue;
|
||||
}
|
||||
|
||||
const Pixel_T& operator()(unsigned x, unsigned y) const
|
||||
const Pixel_T& operator()(int x, int y) const
|
||||
{
|
||||
return _pixels[toIndex(x,y)];
|
||||
}
|
||||
|
||||
Pixel_T& operator()(unsigned x, unsigned y)
|
||||
Pixel_T& operator()(int x, int y)
|
||||
{
|
||||
return _pixels[toIndex(x,y)];
|
||||
}
|
||||
|
||||
void resize(unsigned width, unsigned height)
|
||||
void resize(int width, int height)
|
||||
{
|
||||
if (width == _width && height == _height)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
}
|
||||
|
||||
// Allocate a new buffer without initializing the content
|
||||
Pixel_T* newPixels = new Pixel_T[static_cast<size_t>(width) * static_cast<size_t>(height)];
|
||||
Pixel_T* newPixels = new Pixel_T[static_cast<ssize_t>(width * height)];
|
||||
|
||||
// Release the old buffer without copying data
|
||||
delete[] _pixels;
|
||||
@@ -143,9 +143,9 @@ public:
|
||||
image.resize(_width, _height);
|
||||
}
|
||||
|
||||
const unsigned imageSize = _width * _height;
|
||||
const int imageSize = _width * _height;
|
||||
|
||||
for (unsigned idx = 0; idx < imageSize; idx++)
|
||||
for (int idx = 0; idx < imageSize; idx++)
|
||||
{
|
||||
const Pixel_T & color = _pixels[idx];
|
||||
image.memptr()[idx] = ColorRgb{color.red, color.green, color.blue};
|
||||
@@ -154,40 +154,29 @@ public:
|
||||
|
||||
ssize_t size() const
|
||||
{
|
||||
return static_cast<ssize_t>(_width) * static_cast<ssize_t>(_height) * sizeof(Pixel_T);
|
||||
return static_cast<ssize_t>(_width * _height) * sizeof(Pixel_T);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (_width != 1 || _height != 1)
|
||||
{
|
||||
_width = 1;
|
||||
_height = 1;
|
||||
|
||||
// Allocate a new buffer without initializing the content
|
||||
Pixel_T* newPixels = new Pixel_T[static_cast<size_t>(_width) * static_cast<size_t>(_height)];
|
||||
|
||||
// Release the old buffer without copying data
|
||||
delete[] _pixels;
|
||||
|
||||
// Update the pointer to the new buffer
|
||||
_pixels = newPixels;
|
||||
resize(1,1);
|
||||
}
|
||||
|
||||
// Set the single pixel to the default background
|
||||
_pixels[0] = Pixel_T();
|
||||
}
|
||||
|
||||
private:
|
||||
inline unsigned toIndex(unsigned x, unsigned y) const
|
||||
inline int toIndex(int x, int y) const
|
||||
{
|
||||
return y * _width + x;
|
||||
}
|
||||
|
||||
/// The width of the image
|
||||
unsigned _width;
|
||||
int _width;
|
||||
/// The height of the image
|
||||
unsigned _height;
|
||||
int _height;
|
||||
/// The pixels of the image
|
||||
Pixel_T* _pixels;
|
||||
};
|
||||
|
Reference in New Issue
Block a user