⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icon.cc

📁 Linux下比较早的基于命令行的DVD播放器
💻 CC
字号:
//// 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//------------------------------------------------------------------------------#include "Icon.h"#include "Unichrome.h"#include "MemoryBlock.h"#include "Window.h"#include "util/FileReader.h"#include "util/FileWriter.h"#include "util/Log.h"#include <algorithm>//------------------------------------------------------------------------------using unichrome::Icon;using std::min;//------------------------------------------------------------------------------const char Icon::magic[4] = { 'D', '3', 'P', 'I' };//------------------------------------------------------------------------------Icon::Icon(size_t width, size_t height, bool transparent) :    width(width),    pitch( (width+3) & (~3) ),    height(height),    transparent(transparent),    location(HOST_MEMORY){    buffer = new uint32_t[pitch*height];    for(size_t i = 0; i<pitch*height; ++i) {        //buffer[i] = transparentColor;        buffer[i] = 0x00ffffff;    }}//------------------------------------------------------------------------------Icon::Icon(Unichrome& unichrome, FILE* file,           uint8_t transparentAlpha):    location(BOARD_MEMORY){    init(unichrome, file, transparentAlpha);}//------------------------------------------------------------------------------// FIXME: this is very similar to Font::FontIcon::Icon(Unichrome& unichrome,            const char* name, const char* directory,           uint8_t transparentAlpha) :    location(BOARD_MEMORY){    char fileName[256];    if (directory==0) {         snprintf(fileName, sizeof(fileName), "%s", name);    } else {        snprintf(fileName, sizeof(fileName), "%s/%s", directory, name);    }        FILE* file = fopen(fileName, "rb");    if (file==0) {        Log::fatal("unichrome::Icon::Icon: cannot open icon file %s\n",                   fileName);        abort();    }    init(unichrome, file, transparentAlpha);    fclose(file);}//------------------------------------------------------------------------------Icon::~Icon(){    switch(location) {      case HOST_MEMORY:        delete[] buffer;        break;      case BOARD_MEMORY:        delete memoryBlock;        break;      default:        assert(0);    }}    //------------------------------------------------------------------------------void Icon::setPixel(size_t x, size_t y, uint32_t pixel){    assert(x<width);    assert(y<height);    if ( transparent && (pixel&rgbMask)==transparentColor ) {        pixel = (pixel&alphaMask) | transparentReplacement;    }        getBuffer()[x + y*pitch] = pixel;}//------------------------------------------------------------------------------void Icon::setTransparent(size_t x, size_t y){    assert(x<width);    assert(y<height);    assert(transparent);    getBuffer()[x + y*pitch] = transparentColor;}//------------------------------------------------------------------------------void Icon::write(FILE* f) const{    FileWriter writer(f);    writer.write(magic, sizeof(magic));    writer.write32(currentVersion);    writer.write16(width);    writer.write16(pitch);    writer.write16(height);    writer.write8( transparent ? 1 : 0 );    for(size_t i = 0; i<pitch*height; ++i) {        writer.write32(getBuffer()[i]);    }}//------------------------------------------------------------------------------void Icon::display(Window& window,                    size_t x, size_t y, size_t w, size_t h) const{    assert(location==BOARD_MEMORY);        memoryBlock->setSource(pitch*sizeof(uint32_t));    if (transparent) {        window.setSourceKey(transparentColor);        window.enableSourceKeying();    } else {        window.disableKeying();    }    if (w==0) w = width;    if (h==0) h = height;    window.blit(0, 0, w, h, x, y);    if (transparent) {        memoryBlock->setOffsetSource(pitch*height*sizeof(uint32_t));        window.enableSourceKeying(true);            window.blit(0, 0, width, height, x, y);    }}//------------------------------------------------------------------------------void Icon::repeatHorizontal(Window& window,                            size_t x, size_t y, size_t length) const{    while(length>0) {        size_t w = min(length, width);        display(window, x, y, w, height);        length -= w;        x += w;    }}//------------------------------------------------------------------------------void Icon::repeatVertical(Window& window,                          size_t x, size_t y, size_t length) const{    while(length>0) {        size_t h = min(length, height);        display(window, x, y, width, h);        length -= h;        y += h;    }}//------------------------------------------------------------------------------volatile uint32_t* Icon::getBuffer() const{    switch(location) {      case HOST_MEMORY:        return buffer;        break;      case BOARD_MEMORY:        return memoryBlock->getBuffer32();        break;      default:        assert(0);    }}//------------------------------------------------------------------------------void Icon::copyToBoard(Unichrome& unichrome, uint8_t transparentAlpha){    if (location!=HOST_MEMORY) return;    // FIXME: unify with init()    size_t iconSize = pitch*height;    size_t totalIconSize = (transparent ? 2 : 1) * iconSize;    MemoryBlock* mb = unichrome.allocateMemoryBlock(totalIconSize*sizeof(uint32_t));        for(size_t i = 0; i<iconSize; ++i) {        uint32_t pixel = buffer[i];        mb->getBuffer32()[i] = pixel;        if (transparent) {            if (pixel==transparentColor) {                pixel = transparentAlpha;                pixel <<= 24;            } else {                pixel = (pixel&alphaMask) | transparentColor;            }            mb->getBuffer32()[i + iconSize] = pixel;        }    }    delete[] buffer;    memoryBlock = mb;    location = BOARD_MEMORY;}//------------------------------------------------------------------------------void Icon::init(Unichrome& unichrome, FILE* file, uint8_t transparentAlpha){    FileReader reader(file);    char magicBuffer[sizeof(magic)];    reader.read(magicBuffer, sizeof(magicBuffer));    assert(memcmp(magic, magicBuffer, sizeof(magic))==0);    reader.read32();  // version: unused currently    width = reader.read16();    pitch = reader.read16();    height = reader.read16();    transparent = reader.read8()!=0;        size_t iconSize = pitch*height;    size_t totalIconSize = (transparent ? 2 : 1) * iconSize;    memoryBlock = unichrome.allocateMemoryBlock(totalIconSize*sizeof(uint32_t));     for(size_t i = 0; i<iconSize; ++i) {        uint32_t pixel = reader.read32();        memoryBlock->getBuffer32()[i] = pixel;        if (transparent) {            if (pixel==transparentColor) {                pixel = transparentAlpha;                pixel <<= 24;            } else {                pixel = (pixel&alphaMask) | transparentColor;            }            memoryBlock->getBuffer32()[i + iconSize] = pixel;        }    }}//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -