2003-01-13 01:51:01 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2004-09-21 02:50:02 +04:00
|
|
|
// Copyright (c) 2001-2002, Haiku, Inc.
|
2003-01-13 01:51:01 +03:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
// File Name: ServerBitmap.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: Bitmap class used by the server
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include "ServerBitmap.h"
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Constructor called by the BitmapManager (only).
|
2003-01-20 02:04:58 +03:00
|
|
|
\param rect Size of the bitmap.
|
|
|
|
\param space Color space of the bitmap
|
|
|
|
\param flags Various bitmap flags to tweak the bitmap as defined in Bitmap.h
|
|
|
|
\param bytesperline Number of bytes in each row. -1 implies the default value. Any
|
|
|
|
value less than the the default will less than the default will be overridden, but any value
|
2003-01-13 01:51:01 +03:00
|
|
|
greater than the default will result in the number of bytes specified.
|
2003-01-20 02:04:58 +03:00
|
|
|
\param screen Screen assigned to the bitmap.
|
2003-01-13 01:51:01 +03:00
|
|
|
*/
|
|
|
|
ServerBitmap::ServerBitmap(BRect rect,color_space space, int32 flags,
|
2003-06-23 06:54:52 +04:00
|
|
|
int32 bytesperline, screen_id screen)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fInitialized=false;
|
2003-01-13 01:51:01 +03:00
|
|
|
|
2004-06-26 06:15:48 +04:00
|
|
|
// WARNING: '1' is added to the width and height. Same is done in FBBitmap
|
|
|
|
// subclass, so if you modify here make sure to do the same under FBBitmap::SetSize(...)
|
2004-09-21 02:50:02 +04:00
|
|
|
fWidth=rect.IntegerWidth()+1;
|
|
|
|
fHeight=rect.IntegerHeight()+1;
|
|
|
|
fSpace=space;
|
|
|
|
fArea=B_ERROR;
|
|
|
|
fBuffer=NULL;
|
|
|
|
fFlags=flags;
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
_HandleSpace(space, bytesperline);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Copy constructor does not copy the buffer.
|
|
|
|
ServerBitmap::ServerBitmap(const ServerBitmap *bmp)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fInitialized=false;
|
|
|
|
fArea=B_ERROR;
|
|
|
|
fBuffer=NULL;
|
2003-01-13 01:51:01 +03:00
|
|
|
|
|
|
|
if(bmp)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fWidth=bmp->fWidth;
|
|
|
|
fHeight=bmp->fHeight;
|
|
|
|
fBytesPerRow=bmp->fBytesPerRow;
|
|
|
|
fSpace=bmp->fSpace;
|
|
|
|
fFlags=bmp->fFlags;
|
|
|
|
fBitsPerPixel=bmp->fBitsPerPixel;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fWidth=0;
|
|
|
|
fHeight=0;
|
|
|
|
fBytesPerRow=0;
|
|
|
|
fSpace=B_NO_COLOR_SPACE;
|
|
|
|
fFlags=0;
|
|
|
|
fBitsPerPixel=0;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Empty. Defined for subclasses.
|
|
|
|
*/
|
|
|
|
ServerBitmap::~ServerBitmap(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Gets the number of bytes occupied by the bitmap, including padding bytes.
|
|
|
|
\return The number of bytes occupied by the bitmap, including padding.
|
|
|
|
*/
|
2004-02-07 16:50:36 +03:00
|
|
|
uint32 ServerBitmap::BitsLength(void) const
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
return (uint32)(fBytesPerRow*fHeight);
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
|
2003-02-22 23:23:22 +03:00
|
|
|
/*!
|
|
|
|
\brief Internal function used by subclasses
|
|
|
|
|
|
|
|
Subclasses should call this so the buffer can automagically
|
|
|
|
be allocated on the heap.
|
|
|
|
*/
|
|
|
|
void ServerBitmap::_AllocateBuffer(void)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(fBuffer!=NULL)
|
|
|
|
delete fBuffer;
|
|
|
|
fBuffer=new uint8[BitsLength()];
|
2003-02-22 23:23:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Internal function used by subclasses
|
|
|
|
|
|
|
|
Subclasses should call this to free the internal buffer.
|
|
|
|
*/
|
|
|
|
void ServerBitmap::_FreeBuffer(void)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(fBuffer!=NULL)
|
2003-02-22 23:23:22 +03:00
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
delete fBuffer;
|
|
|
|
fBuffer=NULL;
|
2003-02-22 23:23:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-13 01:51:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Internal function used to translate color space values to appropriate internal
|
|
|
|
values.
|
2003-01-20 02:04:58 +03:00
|
|
|
\param space Color space for the bitmap.
|
|
|
|
\param bytesperline Number of bytes per row.
|
2003-01-13 01:51:01 +03:00
|
|
|
*/
|
2003-06-23 06:54:52 +04:00
|
|
|
void ServerBitmap::_HandleSpace(color_space space, int32 bytesperline)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
|
|
|
// Big convoluted mess just to handle every color space and dword align
|
|
|
|
// the buffer
|
|
|
|
switch(space)
|
|
|
|
{
|
|
|
|
// Buffer is dword-aligned, so nothing need be done
|
|
|
|
// aside from allocate the memory
|
|
|
|
case B_RGB32:
|
|
|
|
case B_RGBA32:
|
|
|
|
case B_RGB32_BIG:
|
|
|
|
case B_RGBA32_BIG:
|
|
|
|
case B_UVL32:
|
|
|
|
case B_UVLA32:
|
|
|
|
case B_LAB32:
|
|
|
|
case B_LABA32:
|
|
|
|
case B_HSI32:
|
|
|
|
case B_HSIA32:
|
|
|
|
case B_HSV32:
|
|
|
|
case B_HSVA32:
|
|
|
|
case B_HLS32:
|
|
|
|
case B_HLSA32:
|
|
|
|
case B_CMY32:
|
|
|
|
case B_CMYA32:
|
|
|
|
case B_CMYK32:
|
|
|
|
|
|
|
|
// 24-bit = 32-bit with extra 8 bits ignored
|
|
|
|
case B_RGB24_BIG:
|
|
|
|
case B_RGB24:
|
|
|
|
case B_LAB24:
|
|
|
|
case B_UVL24:
|
|
|
|
case B_HSI24:
|
|
|
|
case B_HSV24:
|
|
|
|
case B_HLS24:
|
|
|
|
case B_CMY24:
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(bytesperline<(fWidth*4))
|
|
|
|
fBytesPerRow=fWidth*4;
|
2003-01-13 01:51:01 +03:00
|
|
|
else
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=bytesperline;
|
|
|
|
fBitsPerPixel=32;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Calculate size and dword-align
|
|
|
|
|
|
|
|
// 1-bit
|
|
|
|
case B_GRAY1:
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
int32 numbytes=fWidth>>3;
|
|
|
|
if((fWidth % 8) != 0)
|
2003-01-13 01:51:01 +03:00
|
|
|
numbytes++;
|
|
|
|
if(bytesperline<numbytes)
|
|
|
|
{
|
|
|
|
for(int8 i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
if( (numbytes+i)%4==0)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=numbytes+i;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=bytesperline;
|
|
|
|
fBitsPerPixel=1;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 8-bit
|
|
|
|
case B_CMAP8:
|
|
|
|
case B_GRAY8:
|
|
|
|
case B_YUV411:
|
|
|
|
case B_YUV420:
|
|
|
|
case B_YCbCr422:
|
|
|
|
case B_YCbCr411:
|
|
|
|
case B_YCbCr420:
|
|
|
|
case B_YUV422:
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(bytesperline<fWidth)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
|
|
|
for(int8 i=0;i<4;i++)
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if( (fWidth+i)%4==0)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=fWidth+i;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=bytesperline;
|
|
|
|
fBitsPerPixel=8;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 16-bit
|
|
|
|
case B_YUV9:
|
|
|
|
case B_YUV12:
|
|
|
|
case B_RGB15:
|
|
|
|
case B_RGBA15:
|
|
|
|
case B_RGB16:
|
|
|
|
case B_RGB16_BIG:
|
|
|
|
case B_RGB15_BIG:
|
|
|
|
case B_RGBA15_BIG:
|
|
|
|
case B_YCbCr444:
|
|
|
|
case B_YUV444:
|
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if(bytesperline<fWidth*2)
|
2003-01-13 01:51:01 +03:00
|
|
|
{
|
2004-09-21 02:50:02 +04:00
|
|
|
if( (fWidth*2) % 4 !=0)
|
|
|
|
fBytesPerRow=(fWidth+1)*2;
|
2003-01-13 01:51:01 +03:00
|
|
|
else
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=fWidth*2;
|
2003-01-13 01:51:01 +03:00
|
|
|
}
|
|
|
|
else
|
2004-09-21 02:50:02 +04:00
|
|
|
fBytesPerRow=bytesperline;
|
|
|
|
fBitsPerPixel=16;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_NO_COLOR_SPACE:
|
2004-09-21 02:50:02 +04:00
|
|
|
fBitsPerPixel=0;
|
2003-01-13 01:51:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-07 16:50:36 +03:00
|
|
|
|
|
|
|
UtilityBitmap::UtilityBitmap(BRect rect,color_space space, int32 flags,
|
|
|
|
int32 bytesperline, screen_id screen)
|
|
|
|
: ServerBitmap(rect,space,flags,bytesperline,screen)
|
|
|
|
{
|
|
|
|
_AllocateBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
UtilityBitmap::UtilityBitmap(const ServerBitmap *bmp)
|
|
|
|
: ServerBitmap(bmp)
|
|
|
|
{
|
|
|
|
_AllocateBuffer();
|
|
|
|
if(bmp->Bits())
|
|
|
|
memcpy(Bits(),bmp->Bits(),bmp->BitsLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
UtilityBitmap::~UtilityBitmap(void)
|
|
|
|
{
|
|
|
|
_FreeBuffer();
|
|
|
|
}
|