home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-18 | 2.7 KB | 116 lines | [TEXT/CWIE] |
- // BufferAccessor.cp, the BufferAccessor abstract base class, to be used for direct
- // access to GWorld pixel-maps, window pixel-maps, and video pixel-maps.
-
- // copyright © 1995, Macneil Shonle. All rights reserved.
-
- #ifndef __BUFFERACCESSOR__
- #include <BufferAccessor.h>
- #endif
-
- #ifndef __MMUMODESWAPPER__
- #include <MMUModeSwapper.h>
- #endif
-
- // initializes the QuickRowArray pointer
- QuickRowArray::QuickRowArray()
- : array(0)
- {
- }
-
- // cleans up allocated memory
- QuickRowArray::~QuickRowArray()
- {
- delete array;
- }
-
- // given (1) the base address, (2) the row-bytes and (3) the height, a quick-row array will
- // be made to be used for fast row address access without multiplication
- // may throw: xalloc
- void QuickRowArray::setArray(PixelPtr base, RowBytes rowBytes, PixelCord height)
- throw(xalloc)
- {
- delete array;
- array = new PixelPtr[height];
- if (array == 0) throw xalloc("new failed", "QuickRowArray::setArray");
-
- for (PixelCord y=0; y<height; y++)
- array[y] = base + (y * rowBytes);
- }
-
- // intentionally left blank
- BufferAccessor::BufferAccessor()
- {
- }
-
- // intentionally left blank
- BufferAccessor::~BufferAccessor()
- {
- }
-
- // makes a copy of the given BufferAccessor
- // may throw: xalloc
- BufferAccessor& BufferAccessor::operator=(const BufferAccessor& buff) throw(xalloc)
- {
- theHeight = buff.theHeight;
- theWidth = buff.theWidth;
- theRowBytes = buff.theRowBytes;
- setArray(buff.baseAddr(), buff.rowBytes(), buff.height());
- mmuMode = buff.mmuMode;
- return *this;
- }
-
- // returns the base-address of the buffer
- PixelPtr BufferAccessor::baseAddr() const
- {
- return rowAddrs.array[0];
- }
-
- // returns the row-bytes of the buffer
- RowBytes BufferAccessor::rowBytes() const
- {
- return theRowBytes;
- }
-
- // returns the height of the buffer
- PixelCord BufferAccessor::height() const
- {
- return theHeight;
- }
-
- // returns the width of the buffer
- PixelCord BufferAccessor::width() const
- {
- return theWidth;
- }
-
- // returns the address of the pixel at the given co-ordinates
- PixelPtr BufferAccessor::pixelAddr(PixelCord h, PixelCord v) const
- {
- return rowAddrs.array[v] + h;
- }
-
- // returns the address of the row at the given co-ordinate
- PixelPtr BufferAccessor::rowAddr(PixelCord r) const
- {
- return rowAddrs.array[r];
- }
-
- // whether or not 32-bit addressing should be used to access the buffer's memory
- int BufferAccessor::use32Bit() const
- {
- return mmuMode;
- }
-
- // sets the pixel at co-ordinate (h, v) to the color specified in the last parameter
- void BufferAccessor::setPixel(PixelCord h, PixelCord v, Pixel color)
- {
- MMUModeSwapper swapTo(use32Bit());
- *pixelAddr(h, v) = color;
- }
-
- // protected member-function, for derived classes to change the quick-row array
- // may throw: xalloc
- void BufferAccessor::setArray(PixelPtr base, RowBytes rb, PixelCord high) throw(xalloc)
- {
- rowAddrs.setArray(base, rb, high);
- }