BBitmap: Introduce ImportBits variants that take BSizes.

The old versions used pixel-count dimensions, not pixel-span dimensions
as the entire rest of the API does, which was probably a mistake
in the first place. The new APIs using BSize always use pixel-span
dimensions.

The old versions will shortly be deprecated.

Discovered while working on Xlibe.

Change-Id: I604a5ac6e0588420ff0b667d9193d60ac27b92c6
This commit is contained in:
Augustin Cavalier
2022-01-07 22:03:01 -05:00
parent d66430ec52
commit edd3417172
2 changed files with 39 additions and 18 deletions
+15 -7
View File
@@ -79,20 +79,15 @@ public:
status_t SetDrawingFlags(uint32 flags);
uint32 Flags() const;
void SetBits(const void* data, int32 length,
int32 offset, color_space colorSpace);
// not part of the R5 API
status_t ImportBits(const void* data, int32 length,
int32 bpr, int32 offset,
color_space colorSpace);
status_t ImportBits(const void* data, int32 length,
int32 bpr, color_space colorSpace,
BPoint from, BPoint to, int32 width,
int32 height);
BPoint from, BPoint to, BSize size);
status_t ImportBits(const BBitmap* bitmap);
status_t ImportBits(const BBitmap* bitmap, BPoint from,
BPoint to, int32 width, int32 height);
BPoint to, BSize size);
status_t GetOverlayRestrictions(
overlay_restrictions* restrictions) const;
@@ -111,6 +106,19 @@ public:
BBitmap& operator=(const BBitmap& source);
class Private;
public:
// deprecated
void SetBits(const void* data, int32 length,
int32 offset, color_space colorSpace);
public:
status_t ImportBits(const void* data, int32 length,
int32 bpr, color_space colorSpace,
BPoint from, BPoint to, int32 width, int32 height);
status_t ImportBits(const BBitmap* bitmap, BPoint from,
BPoint to, int32 width, int32 height);
private:
friend class BView;
friend class BApplication;
+24 -11
View File
@@ -720,8 +720,7 @@ BBitmap::ImportBits(const void* data, int32 length, int32 bpr, int32 offset,
\param colorSpace Color space of the source data.
\param from The offset in the source where reading should begin.
\param to The offset in the bitmap where the source should be written.
\param width The width (in pixels) to be imported.
\param height The height (in pixels) to be imported.
\param size The size (in pixels) to be imported.
\return
- \c B_OK: Everything went fine.
- \c B_BAD_VALUE: \c NULL \a data, invalid \a bpr, unsupported
@@ -729,14 +728,14 @@ BBitmap::ImportBits(const void* data, int32 length, int32 bpr, int32 offset,
*/
status_t
BBitmap::ImportBits(const void* data, int32 length, int32 bpr,
color_space colorSpace, BPoint from, BPoint to, int32 width, int32 height)
color_space colorSpace, BPoint from, BPoint to, BSize size)
{
_AssertPointer();
if (InitCheck() != B_OK)
return B_NO_INIT;
if (!data || length < 0 || width < 0 || height < 0)
if (!data || length < 0 || size.IntegerWidth() < 0 || size.IntegerHeight() < 0)
return B_BAD_VALUE;
if (bpr <= 0) {
@@ -747,11 +746,20 @@ BBitmap::ImportBits(const void* data, int32 length, int32 bpr,
}
return BPrivate::ConvertBits(data, fBasePointer, length, fSize, bpr,
fBytesPerRow, colorSpace, fColorSpace, from, to, width, height);
fBytesPerRow, colorSpace, fColorSpace, from, to,
size.IntegerWidth() + 1, size.IntegerHeight() + 1);
}
/*! \briefly Assigns another bitmap's data to this bitmap.
status_t
BBitmap::ImportBits(const void* data, int32 length, int32 bpr,
color_space colorSpace, BPoint from, BPoint to, int32 width, int32 height)
{
return ImportBits(data, length, bpr, colorSpace, from, to, BSize(width - 1, height - 1));
}
/*! \brief Assigns another bitmap's data to this bitmap.
The supplied bitmap must have the exactly same dimensions as this bitmap.
Its data is converted to the color space of this bitmap.
@@ -792,15 +800,13 @@ BBitmap::ImportBits(const BBitmap* bitmap)
\param bitmap The source bitmap.
\param from The offset in the source where reading should begin.
\param to The offset in the bitmap where the source should be written.
\param width The width (in pixels) to be imported.
\param height The height (in pixels) to be imported.
\param size The size (in pixels) to be imported.
- \c B_OK: Everything went fine.
- \c B_BAD_VALUE: \c NULL \a bitmap, the conversion from or to one of
the color spaces is not supported, or invalid width/height.
*/
status_t
BBitmap::ImportBits(const BBitmap* bitmap, BPoint from, BPoint to, int32 width,
int32 height)
BBitmap::ImportBits(const BBitmap* bitmap, BPoint from, BPoint to, BSize size)
{
if (InitCheck() != B_OK)
return B_NO_INIT;
@@ -809,7 +815,14 @@ BBitmap::ImportBits(const BBitmap* bitmap, BPoint from, BPoint to, int32 width,
return B_BAD_VALUE;
return ImportBits(bitmap->Bits(), bitmap->BitsLength(),
bitmap->BytesPerRow(), bitmap->ColorSpace(), from, to, width, height);
bitmap->BytesPerRow(), bitmap->ColorSpace(), from, to, size);
}
status_t
BBitmap::ImportBits(const BBitmap* bitmap, BPoint from, BPoint to, int32 width, int32 height)
{
return ImportBits(bitmap, from, to, BSize(width - 1, height - 1));
}