aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb/PixelBuffer.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-11-07 10:37:53 +0100
committerPierre Ossman <ossman@cendio.se>2024-11-07 10:37:53 +0100
commitf7507aea98b1a428d02fe5c41d25ee69dd5436bb (patch)
tree49f9349a1d7441874d1cb6d4428e2bcb0d63b422 /common/rfb/PixelBuffer.cxx
parent7508e9887de022e127d8fadb9f6a6bd8e9778864 (diff)
parent2b7857283b834391266e414adcff8c20f8fe3067 (diff)
downloadtigervnc-f7507aea98b1a428d02fe5c41d25ee69dd5436bb.tar.gz
tigervnc-f7507aea98b1a428d02fe5c41d25ee69dd5436bb.zip
Merge branch 'stdexcept' of github.com:CendioOssman/tigervnc
Diffstat (limited to 'common/rfb/PixelBuffer.cxx')
-rw-r--r--common/rfb/PixelBuffer.cxx80
1 files changed, 46 insertions, 34 deletions
diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx
index 0a287544..5590c214 100644
--- a/common/rfb/PixelBuffer.cxx
+++ b/common/rfb/PixelBuffer.cxx
@@ -28,9 +28,11 @@
#include <string.h>
-#include <rfb/Exception.h>
+#include <stdexcept>
+
#include <rfb/LogWriter.h>
#include <rfb/PixelBuffer.h>
+#include <rfb/util.h>
using namespace rfb;
@@ -70,9 +72,10 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const
const uint8_t* end;
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(),
- r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
data = getBuffer(r, &inStride);
@@ -106,9 +109,10 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf,
}
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(),
- r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
if (stride == 0)
stride = r.width();
@@ -122,9 +126,9 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf,
void PixelBuffer::setSize(int width, int height)
{
if ((width < 0) || (width > maxPixelBufferWidth))
- throw rfb::Exception("Invalid PixelBuffer width of %d pixels requested", width);
+ throw std::out_of_range(rfb::format("Invalid PixelBuffer width of %d pixels requested", width));
if ((height < 0) || (height > maxPixelBufferHeight))
- throw rfb::Exception("Invalid PixelBuffer height of %d pixels requested", height);
+ throw std::out_of_range(rfb::format("Invalid PixelBuffer height of %d pixels requested", height));
width_ = width;
height_ = height;
@@ -153,8 +157,10 @@ void ModifiablePixelBuffer::fillRect(const Rect& r, const void* pix)
int w, h, b;
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(), r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
w = r.width();
h = r.height();
@@ -203,9 +209,10 @@ void ModifiablePixelBuffer::imageRect(const Rect& r,
uint8_t* end;
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(),
- r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
bytesPerPixel = getPF().bpp/8;
@@ -242,15 +249,17 @@ void ModifiablePixelBuffer::copyRect(const Rect &rect,
drect = rect;
if (!drect.enclosed_by(getRect()))
- throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- drect.width(), drect.height(),
- drect.tl.x, drect.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ drect.width(), drect.height(),
+ drect.tl.x, drect.tl.y,
+ width(), height()));
srect = drect.translate(move_by_delta.negate());
if (!srect.enclosed_by(getRect()))
- throw rfb::Exception("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- srect.width(), srect.height(),
- srect.tl.x, srect.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ srect.width(), srect.height(),
+ srect.tl.x, srect.tl.y,
+ width(), height()));
bytesPerPixel = format.bpp/8;
@@ -303,9 +312,10 @@ void ModifiablePixelBuffer::imageRect(const PixelFormat& pf, const Rect &dest,
int dstStride;
if (!dest.enclosed_by(getRect()))
- throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
- dest.width(), dest.height(),
- dest.tl.x, dest.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d",
+ dest.width(), dest.height(),
+ dest.tl.x, dest.tl.y,
+ width(), height()));
if (stride == 0)
stride = dest.width();
@@ -332,9 +342,10 @@ FullFramePixelBuffer::~FullFramePixelBuffer() {}
uint8_t* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_)
{
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(),
- r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
*stride_ = stride;
return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)];
@@ -347,9 +358,10 @@ void FullFramePixelBuffer::commitBufferRW(const Rect& /*r*/)
const uint8_t* FullFramePixelBuffer::getBuffer(const Rect& r, int* stride_) const
{
if (!r.enclosed_by(getRect()))
- throw rfb::Exception("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d",
- r.width(), r.height(),
- r.tl.x, r.tl.y, width(), height());
+ throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d",
+ r.width(), r.height(),
+ r.tl.x, r.tl.y,
+ width(), height()));
*stride_ = stride;
return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)];
@@ -359,13 +371,13 @@ void FullFramePixelBuffer::setBuffer(int width, int height,
uint8_t* data_, int stride_)
{
if ((width < 0) || (width > maxPixelBufferWidth))
- throw rfb::Exception("Invalid PixelBuffer width of %d pixels requested", width);
+ throw std::out_of_range(rfb::format("Invalid PixelBuffer width of %d pixels requested", width));
if ((height < 0) || (height > maxPixelBufferHeight))
- throw rfb::Exception("Invalid PixelBuffer height of %d pixels requested", height);
+ throw std::out_of_range(rfb::format("Invalid PixelBuffer height of %d pixels requested", height));
if ((stride_ < 0) || (stride_ > maxPixelBufferStride) || (stride_ < width))
- throw rfb::Exception("Invalid PixelBuffer stride of %d pixels requested", stride_);
+ throw std::invalid_argument(rfb::format("Invalid PixelBuffer stride of %d pixels requested", stride_));
if ((width != 0) && (height != 0) && (data_ == nullptr))
- throw rfb::Exception("PixelBuffer requested without a valid memory area");
+ throw std::logic_error(rfb::format("PixelBuffer requested without a valid memory area"));
ModifiablePixelBuffer::setSize(width, height);
stride = stride_;
@@ -375,7 +387,7 @@ void FullFramePixelBuffer::setBuffer(int width, int height,
void FullFramePixelBuffer::setSize(int /*w*/, int /*h*/)
{
// setBuffer() should be used
- throw rfb::Exception("Invalid call to FullFramePixelBuffer::setSize()");
+ throw std::logic_error("Invalid call to FullFramePixelBuffer::setSize()");
}
// -=- Managed pixel buffer class