📄 icon.h
字号:
//// Copyright (c) 2005 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card, but now handles other// hardware as well. These files contain a (mostly) user-space driver // for the Unichrome board found on Via's EPIA motherboards.//// The information for implementing this driver has been gathered// from the following sources://// - The DirectFB Unichrome driver// Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Andreas Robinson's MPEG-2 decoder for the Unichrome board.// Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Via's Unichrome Framebuffer driver// Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.// Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.// 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_UNICHROME_ICON_H#define DXR3PLAYER_UNICHROME_ICON_H//------------------------------------------------------------------------------#include <cstdio>#include <inttypes.h>//------------------------------------------------------------------------------namespace unichrome {//------------------------------------------------------------------------------class MemoryBlock;class Unichrome;class Window;//------------------------------------------------------------------------------/** * Class representing an icon to be displayed by a Unichrome board. * Such icons contain 32-bit pixels and may be transparent. * * FIXME: perhaps unify with Font::Chunk */class Icon{public: /** * The transparent colour in the icon. */ static const uint32_t transparentColor = 0x00010101;private: /** * The colour to replace the pixels with in an original image * that are equal to the transparent one. */ static const uint32_t transparentReplacement = 0x00000000; /** * The mask for the alpha component of a pixel. */ static const uint32_t alphaMask = 0xff000000; /** * The mask for the RGB component of a pixel. */ static const uint32_t rgbMask = 0x00ffffff; /** * The magic number for icon files. */ static const char magic[4]; /** * The current icon version. */ static const unsigned currentVersion = 1; /** * The width of the icon. */ size_t width; /** * The pitch of the icon. */ size_t pitch; /** * The height of the icon. */ size_t height; /** * Indicate if the icon has transparent pixels. */ bool transparent; /** * The location of this icon. */ enum { HOST_MEMORY, BOARD_MEMORY } location; union { /** * The host-memory buffer for this icon. This is valid, * if location is HOST_MEMORY. */ uint32_t* buffer; /** * The Unichrome memory block. This is valid, if location * is BOARD_MEMORY. */ MemoryBlock* memoryBlock; };public: /** * Construct an icon in the host memory with the given size. */ Icon(size_t width, size_t height, bool transparent); /** * Construct an icon by reading it from the given file and storing * in the board's memory. */ Icon(Unichrome& unichrome, FILE* file, uint8_t transparentAlpha = 0); /** * Construct an icon by reading it from the given file in * the given directory. If the file cannot be opened, it will abort! */ Icon(Unichrome& unichrome, const char* name, const char* directory = 0, uint8_t transparentAlpha = 0); /** * Destroy the icon. */ ~Icon(); /** * Get the width of the icon. */ size_t getWidth() const; /** * Get the pitch of the icon. */ size_t getPitch() const; /** * Get the height of the icon. */ size_t getHeight() const; /** * Set the pixel at the given position. If the pixel's RGB part is * equal to the transparency colour, it will be adjusted to the * transparent replacement. */ void setPixel(size_t x, size_t y, uint32_t pixel); /** * Set the given position to transparent. */ void setTransparent(size_t x, size_t y); /** * Display the icon at the given position. This works only if the * icon is located in the board's memory. It assumes that * destination addresses and other basic parameters are set up * correctly. */ void display(Window& window, size_t x, size_t y, size_t w = 0, size_t h = 0) const; /** * Display the icon repeated horizontally starting at the given * position. This works only if the icon is located in the board's * memory. It assumes that destination addresses and other basic * parameters are set up correctly. */ void repeatHorizontal(Window& window, size_t x, size_t y, size_t length) const; /** * Display the icon repeated vertically starting at the given * position. This works only if the icon is located in the board's * memory. It assumes that destination addresses and other basic * parameters are set up correctly. */ void repeatVertical(Window& window, size_t x, size_t y, size_t length) const; /** * Write the icon to the given file. */ void write(FILE* f) const;protected: /** * Get the buffer address of the icon. It takes into account the * location of the icon. */ volatile uint32_t* getBuffer() const; /** * Copy the icon to the board's memory, if not already there. */ void copyToBoard(Unichrome& unichrome, uint8_t transparentAlpha = 0);private: /** * Initialize the icon by reading it from the given file. */ void init(Unichrome& unichrome, FILE* file, uint8_t transparentAlpha);};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline size_t Icon::getWidth() const{ return width;} //------------------------------------------------------------------------------inline size_t Icon::getPitch() const{ return pitch;} //------------------------------------------------------------------------------inline size_t Icon::getHeight() const{ return height;}//------------------------------------------------------------------------------} /* namespace unichrome *///------------------------------------------------------------------------------#endif // DXR3PLAYER_UNICHROME_ICON_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -