📄 picture.h
字号:
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_DVD_SPU_PICTURE_H#define DXR3PLAYER_DVD_SPU_PICTURE_H//------------------------------------------------------------------------------#include "buffer/DynamicBuffer.h"#include "util/Area.h"#include <cstdlib>#include <cassert>//------------------------------------------------------------------------------namespace dvd { namespace spu {//------------------------------------------------------------------------------class SPUBufferBitReader;//------------------------------------------------------------------------------/** * An SPU picture. */class Picture{private: /** * The reference counter. */ size_t referenceCount; /** * The display area. */ Area area; /** * The X-coordinate of the upper left corner of the area that is * visible. */ size_t visibleStartX; /** * The Y-coordinate of the upper left corner of the area that is * visible. */ size_t visibleStartY; /** * The X-coordinate of the lower right corner of the area that is * visible. */ size_t visibleEndX; /** * The Y-coordinate of the lower right corner of the area that is * visible. */ size_t visibleEndY; /** * The display data. */ unsigned char* data; /** * Dynamic buffer for the compressed data. */ DynamicBuffer compressedData; /** * The length of the top field (compressed) */ size_t topFieldLength; /** * The length of the bottom field (compressed) */ size_t bottomFieldLength;public: /** * Construct an empty picture. */ Picture(); /** * Destroy the picture. */ ~Picture(); /** * Assignment operator. */ Picture& operator=(const Picture& other); /** * Increment the reference counter. */ void addReference(); /** * Decrement the reference counter and delete the object if it * reached 0. */ void removeReference(); /** * Determine if the picture information is valid. */ bool isValid() const; /** * Set the area from the given area. */ void setArea(const Area& a); /** * Set the area. It will allocate the data array. */ void setArea(size_t startX, size_t endX, size_t startY, size_t endY); /** * Set the area by reading it from the given reader. */ void setArea(SPUBufferBitReader& reader); /** * Get the area the picture is displayed in. */ const Area& getArea() const; /** * Get the starting X coordinate. */ size_t getXOffset() const; /** * Get the width of the image. */ size_t getWidth() const; /** * Get the starting Y coordinate. */ size_t getYOffset() const; /** * Get the height of the image. */ size_t getHeight() const; /** * Get the visible area into the given area object, if there is a * visible area. */ void getVisibleArea(Area& area) const; /** * Set the color of the given coordinate to the given value. */ void setColor(size_t x, size_t y, unsigned color); /** * Get the color at the given coordinates. */ unsigned getColor(size_t x, size_t y) const; /** * Get the data area. */ unsigned char* getData(); /** * Get the data area. */ const unsigned char* getData() const; /** * Decode the top field. */ void decodeTopField(SPUBufferBitReader& reader, unsigned contrast); /** * Decode the bottom field. */ void decodeBottomField(SPUBufferBitReader& reader, unsigned contrast); /** * Embed the picture into the given one, which should be as large * as the full frame (e.g. 720x576 for PAL). Only the * picture's area will be modified. */ void embedInto(unsigned char* frame, size_t frameWidth, size_t frameHeight) const; /** * Encode the data into the given stream. */ size_t encode(DynamicBufferBitWriter& writer, size_t& tfl) const;private: /** * Read the variable length length + color combo */ unsigned decodeVLC(SPUBufferBitReader& reader) const; /** * Decode a field starting with the given line. */ void decodeField(SPUBufferBitReader& reader, size_t line, unsigned contrast); /** * Invalidate the compressed data. */ void invalidateCompressed(); /** * Compress the data if not compressed. */ void compress(); /** * Compress the data into the given stream. */ size_t compress(DynamicBufferBitWriter& writer, size_t& tfl) const; /** * Compress a field starting with the given line. */ void compressField(DynamicBufferBitWriter& writer, size_t line) const; /** * Compress the given line into the given buffer. */ void compressLine(DynamicBufferBitWriter& writer, size_t line) const; /** * Add the VLC representation of the given length and color to the * given writer. */ void addVLC(DynamicBufferBitWriter& writer, unsigned color, size_t length) const; /** * Add the VLC representation of the given color till the end of the * line. */ void addVLCLineEnd(DynamicBufferBitWriter& writer, unsigned color) const;};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline void Picture::addReference(){ ++referenceCount;}//------------------------------------------------------------------------------inline void Picture::removeReference(){ assert(referenceCount>0); --referenceCount; if (referenceCount==0) { delete this; }}//------------------------------------------------------------------------------inline bool Picture::isValid() const{ return data != 0;}//------------------------------------------------------------------------------inline size_t Picture::getXOffset() const{ return area.getStartX();}//------------------------------------------------------------------------------inline size_t Picture::getWidth() const{ return area.getWidth();}//------------------------------------------------------------------------------inline size_t Picture::getYOffset() const{ return area.getStartY();}//------------------------------------------------------------------------------inline size_t Picture::getHeight() const{ return area.getHeight();}//------------------------------------------------------------------------------inline const Area& Picture::getArea() const{ return area;}//------------------------------------------------------------------------------inline void Picture::getVisibleArea(Area& area) const{ if (visibleStartX<=visibleEndX && visibleStartY<=visibleEndY) { area.set(visibleStartX + getXOffset(), visibleEndX + getXOffset(), visibleStartY + getYOffset(), visibleEndY + getYOffset()); }}//------------------------------------------------------------------------------inline void Picture::setColor(size_t x, size_t y, unsigned color){ assert(data!=0); assert(x<getWidth()); assert(y<getHeight()); assert(color<4); invalidateCompressed(); data[ y * getWidth() + x ] = color;}//------------------------------------------------------------------------------inline unsigned Picture::getColor(size_t x, size_t y) const{ assert(data!=0); assert(x<getWidth()); assert(y<getHeight()); return data[ y * getWidth() + x ];}//------------------------------------------------------------------------------inline void Picture::decodeTopField(SPUBufferBitReader& reader, unsigned contrast){ decodeField(reader, 0, contrast);}//------------------------------------------------------------------------------inline void Picture::decodeBottomField(SPUBufferBitReader& reader, unsigned contrast){ decodeField(reader, 1, contrast);}//------------------------------------------------------------------------------inline unsigned char* Picture::getData(){ invalidateCompressed(); return data;}//------------------------------------------------------------------------------inline const unsigned char* Picture::getData() const{ return data;}//------------------------------------------------------------------------------} /* namespace dvd::spu */ } /* namespace dvd *///------------------------------------------------------------------------------#endif // DXR3PLAYER_DVD_SPU_PICTURE_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -