From e42256c7a8d9f3c3023833160a29d276fc06c0a8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 13 May 2022 12:07:58 +0200 Subject: [PATCH] - added texture class for handling the start. screen --- src/CMakeLists.txt | 1 + .../textures/formats/startscreentexture.cpp | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/gamedata/textures/formats/startscreentexture.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 595b32fdf..bcc7a68b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1083,6 +1083,7 @@ set (PCH_SOURCES common/textures/formats/tgatexture.cpp common/textures/formats/stbtexture.cpp common/textures/formats/anmtexture.cpp + common/textures/formats/startscreentexture.cpp common/textures/hires/hqresize.cpp common/models/models_md3.cpp common/models/models_md2.cpp diff --git a/src/gamedata/textures/formats/startscreentexture.cpp b/src/gamedata/textures/formats/startscreentexture.cpp new file mode 100644 index 000000000..b3305808c --- /dev/null +++ b/src/gamedata/textures/formats/startscreentexture.cpp @@ -0,0 +1,113 @@ +/* +** startscreentexture.cpp +** Texture class to create a texture from the start screen's imagé +** +**--------------------------------------------------------------------------- +** Copyright 2004-2006 Randy Heit +** Copyright 2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "doomtype.h" +#include "files.h" +#include "w_wad.h" +#include "gi.h" +#include "bitmap.h" +#include "textures/textures.h" +#include "imagehelpers.h" +#include "image.h" +#include "st_start.h" + + +//========================================================================== +// +// +// +//========================================================================== + +class FStartScreenTexture : public FImageSource +{ + BitmapInfo *info; // This must remain constant for the lifetime of this texture + +public: + FStartScreenTexture (BitmapInfo *srcdata); + int CopyPixels(FBitmap *bmp, int conversion) override; +}; + +//========================================================================== +// +// +// +//========================================================================== + +FImageSource *CreateStartScreenTexture(BitmapInfo *srcdata) +{ + return new FStartScreenTexture(srcdata); +} + + +//========================================================================== +// +// +// +//========================================================================== + +FStartScreenTexture::FStartScreenTexture (BitmapInfo *srcdata) +: FImageSource(-1) +{ + Width = srcdata->bmiHeader.biWidth; + Height = srcdata->bmiHeader.biHeight; + info = srcdata; + bUseGamePalette = false; + +} + +//========================================================================== +// +// +// +//========================================================================== + +int FStartScreenTexture::CopyPixels(FBitmap *bmp, int conversion) +{ + const RgbQuad *psource = info->bmiColors; + PalEntry paldata[256] = {}; + auto pixels = ST_Util_BitsForBitmap(info); + for (uint32_t i = 0; i < info->bmiHeader.biClrUsed; i++) + { + PalEntry &pe = paldata[i]; + pe.r = psource[i].rgbRed; + pe.g = psource[i].rgbGreen; + pe.b = psource[i].rgbBlue; + pe.a = 255; + } + bmp->CopyPixelData(0, 0, pixels, Width, Height, 1, (Width + 3) & ~3, 0, paldata); + + return 0; +}