From e09bff9bf3c351c97d03da726319cb1333bad62a Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Sun, 5 Sep 2004 00:48:23 +0000 Subject: [PATCH] Added some utility classes which will make finishing work on DisplayDriver much easier and cleaner git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8854 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/servers/app/GraphicsBuffer.h | 60 +++++++++ headers/private/servers/app/IPoint.h | 116 +++++++++++++++++ headers/private/servers/app/PixelRenderer.h | 125 +++++++++++++++++++ headers/private/servers/app/SystemPalette.h | 2 +- 4 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 headers/private/servers/app/GraphicsBuffer.h create mode 100644 headers/private/servers/app/IPoint.h create mode 100644 headers/private/servers/app/PixelRenderer.h diff --git a/headers/private/servers/app/GraphicsBuffer.h b/headers/private/servers/app/GraphicsBuffer.h new file mode 100644 index 0000000000..28890afd1c --- /dev/null +++ b/headers/private/servers/app/GraphicsBuffer.h @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// 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: GraphicsBuffer.h +// Author: DarkWyrm +// +// Description: Convenience class for working with graphics buffers +// Based on concepts from the Anti-Grain Geometry vector gfx library +//------------------------------------------------------------------------------ +#ifndef GFX_BUFFER_H +#define GFX_BUFFER_H + +#include + +class GraphicsBuffer +{ +public: + GraphicsBuffer(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes); + ~GraphicsBuffer(); + + void SetTo(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes); + void Unset(void); + + uint8 *Bits(void) const { return fBuffer; } + uint8 *RowAt(uint32 row) { return fRowList[row]; } + + uint32 Width(void) const { return fWidth; } + uint32 Height(void) const { return fHeight; } + + uint32 BytesPerRow(void) const { return fBytesPerRow; } + +private: + + uint32 fWidth; + uint32 fHeight; + uint8 *fBuffer; + uint8 **fRowList; + uint32 fBytesPerRow; + uint32 fMaxHeight; +}; + +#endif diff --git a/headers/private/servers/app/IPoint.h b/headers/private/servers/app/IPoint.h new file mode 100644 index 0000000000..b7cedbc90e --- /dev/null +++ b/headers/private/servers/app/IPoint.h @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// 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: IPoint.h +// Author: DarkWyrm +// Based on BPoint code by Frans Van Nispen +// Description: Integer BPoint class +//------------------------------------------------------------------------------ +#ifndef _IPOINT_H +#define _IPOINT_H + +// System Includes ------------------------------------------------------------- +#include +#include +#include + +class BRect; + +class IPoint +{ +public: + int32 x; + int32 y; + + IPoint(void); + IPoint(int32 X, int32 Y); + IPoint(const IPoint &p); + IPoint(const BPoint &p); + + IPoint &operator=(const IPoint &p); + IPoint &operator=(const BPoint &p); + void Set(int32 X, int32 Y); + + void ConstrainTo(BRect r); + + void PrintToStream() const; + + IPoint operator+(const IPoint &p) const; + IPoint operator+(const BPoint &p) const; + IPoint operator-(const IPoint &p) const; + IPoint operator-(const BPoint &p) const; + IPoint &operator+=(const IPoint &p); + IPoint &operator+=(const BPoint &p); + IPoint &operator-=(const IPoint &p); + IPoint &operator-=(const BPoint &p); + + bool operator!=(const IPoint &p) const; + bool operator!=(const BPoint &p) const; + bool operator==(const IPoint &p) const; + bool operator==(const BPoint &p) const; +}; + +//------------------------------------------------------------------------------ +inline IPoint::IPoint(void) +{ + x = y = 0; +} +//------------------------------------------------------------------------------ +inline IPoint::IPoint(int32 X, int32 Y) +{ + x = X; + y = Y; +} +//------------------------------------------------------------------------------ +inline IPoint::IPoint(const IPoint& pt) +{ + x = pt.x; + y = pt.y; +} +//------------------------------------------------------------------------------ +inline IPoint::IPoint(const BPoint& pt) +{ + x = (int32)pt.x; + y = (int32)pt.y; +} +//------------------------------------------------------------------------------ +inline IPoint &IPoint::operator=(const IPoint& from) +{ + x = from.x; + y = from.y; + return *this; +} +//------------------------------------------------------------------------------ +inline IPoint &IPoint::operator=(const BPoint& from) +{ + x = (int32)from.x; + y = (int32)from.y; + return *this; +} +//------------------------------------------------------------------------------ +inline void IPoint::Set(int32 X, int32 Y) +{ + x = X; + y = Y; +} +//------------------------------------------------------------------------------ + +#endif diff --git a/headers/private/servers/app/PixelRenderer.h b/headers/private/servers/app/PixelRenderer.h new file mode 100644 index 0000000000..5bf066bd51 --- /dev/null +++ b/headers/private/servers/app/PixelRenderer.h @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// 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: PixelRenderer.cpp +// Author: DarkWyrm +// +// Description: Base class for pixel plotting renderers +// Based on concepts from the Anti-Grain Geometry vector gfx library +//------------------------------------------------------------------------------ +#ifndef PIXEL_RENDERER +#define PIXEL_RENDERER + +#include "GraphicsBuffer.h" +#include "GraphicsDefs.h" +#include "RGBColor.h" + +class IPoint; + +class PixelRenderer +{ +public: + PixelRenderer(GraphicsBuffer &buffer); + virtual ~PixelRenderer(void); + + virtual color_space ColorSpace(void) { return B_NO_COLOR_SPACE; } + + virtual RGBColor GetPixel(const IPoint &pt); + virtual void PutPixel(const IPoint &pt, RGBColor &c); + virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); + virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); + + virtual void SetBuffer(GraphicsBuffer &buffer) { fBuffer=&buffer; } + GraphicsBuffer *GetBuffer(void) const { return fBuffer; } + +private: + GraphicsBuffer *fBuffer; +}; + +class PixelRendererRGBA32 : public PixelRenderer +{ +public: + PixelRendererRGBA32(GraphicsBuffer &buffer); + virtual ~PixelRendererRGBA32(void); + + virtual color_space ColorSpace(void) { return B_RGBA32; } + + virtual RGBColor GetPixel(const IPoint &pt); + virtual void PutPixel(const IPoint &pt, RGBColor &c); + virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); + virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); +}; + +class PixelRendererRGB16 : public PixelRenderer +{ +public: + PixelRendererRGB16(GraphicsBuffer &buffer); + virtual ~PixelRendererRGB16(void); + + virtual color_space ColorSpace(void) { return B_RGB16; } + + virtual RGBColor GetPixel(const IPoint &pt); + virtual void PutPixel(const IPoint &pt, RGBColor &c); + virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); + virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); +}; + +class PixelRendererRGBA15 : public PixelRenderer +{ +public: + PixelRendererRGBA15(GraphicsBuffer &buffer); + virtual ~PixelRendererRGBA15(void); + + virtual color_space ColorSpace(void) { return B_RGBA15; } + + virtual RGBColor GetPixel(const IPoint &pt); + virtual void PutPixel(const IPoint &pt, RGBColor &c); + virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); + virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); +}; + +class PixelRendererCMAP8 : public PixelRenderer +{ +public: + PixelRendererCMAP8(GraphicsBuffer &buffer); + virtual ~PixelRendererCMAP8(void); + + virtual color_space ColorSpace(void) { return B_CMAP8; } + + virtual RGBColor GetPixel(const IPoint &pt); + virtual void PutPixel(const IPoint &pt, RGBColor &c); + virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); + virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); +}; + +// TODO: These inlines probably should go in ColorUtils +inline uint16 MakeRGB16Color(uint8 r, uint8 g, uint8 b) +{ + return (uint16)(((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)); +} + +// TODO: Doublecheck to make sure the shifting is correct in MakeRGBA15Color +inline uint16 MakeRGBA15Color(uint8 r, uint8 g, uint8 b, bool visible=true) +{ + return (uint16)(((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3)); +} + +#endif diff --git a/headers/private/servers/app/SystemPalette.h b/headers/private/servers/app/SystemPalette.h index 386a5406e6..e8a79da60f 100644 --- a/headers/private/servers/app/SystemPalette.h +++ b/headers/private/servers/app/SystemPalette.h @@ -31,6 +31,6 @@ #include void GenerateSystemPalette(rgb_color *palette); -extern rgb_color system_palette[]; +extern const rgb_color system_palette[]; #endif