2020-02-25 21:19:39 +01:00
|
|
|
/*
|
|
|
|
This class will replace EG_IMAGE structure and methods
|
|
|
|
*/
|
|
|
|
|
2020-02-28 21:28:33 +01:00
|
|
|
#if !defined(__XIMAGE_H__)
|
|
|
|
#define __XIMAGE_H__
|
2020-02-28 15:08:40 +01:00
|
|
|
|
2020-03-02 16:43:54 +01:00
|
|
|
extern "C" {
|
|
|
|
#include <Protocol/GraphicsOutput.h>
|
|
|
|
}
|
|
|
|
#include "../cpp_foundation/XArray.h"
|
2020-04-23 15:20:48 +02:00
|
|
|
#include "../cpp_foundation/XString.h"
|
2020-03-02 16:43:54 +01:00
|
|
|
#include "../libeg/libeg.h"
|
2020-02-28 21:28:33 +01:00
|
|
|
//#include "lodepng.h"
|
|
|
|
//
|
|
|
|
//#include "nanosvg.h"
|
|
|
|
//#include "FloatLib.h"
|
|
|
|
|
2020-02-25 14:55:39 +01:00
|
|
|
|
2020-02-26 07:05:14 +01:00
|
|
|
#if 0 //ndef EFI_GRAPHICS_OUTPUT_BLT_PIXEL
|
2020-02-25 14:55:39 +01:00
|
|
|
typedef struct {
|
|
|
|
UINT8 Blue;
|
|
|
|
UINT8 Green;
|
|
|
|
UINT8 Red;
|
|
|
|
UINT8 Reserved; //this is Alpha. 0 means full transparent, 0xFF means opaque
|
|
|
|
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;
|
2020-02-26 14:59:10 +01:00
|
|
|
|
|
|
|
|
2020-02-25 14:55:39 +01:00
|
|
|
typedef union {
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Pixel;
|
|
|
|
UINT32 Raw;
|
|
|
|
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION;
|
2020-02-26 14:59:10 +01:00
|
|
|
#endif
|
2020-03-20 18:48:19 +01:00
|
|
|
/*
|
2020-02-25 14:55:39 +01:00
|
|
|
typedef struct {
|
2020-02-25 21:19:39 +01:00
|
|
|
UINTN Xpos;
|
|
|
|
UINTN Ypos;
|
|
|
|
UINTN Width;
|
|
|
|
UINTN Height;
|
2020-02-25 14:55:39 +01:00
|
|
|
} EgRect;
|
2020-03-20 18:48:19 +01:00
|
|
|
*/
|
2020-02-25 21:19:39 +01:00
|
|
|
class XImage
|
|
|
|
{
|
|
|
|
protected:
|
2020-04-04 04:59:17 +02:00
|
|
|
size_t Width; //may be better to use INTN - signed integer as it always compared with expressions
|
2020-03-29 12:35:09 +02:00
|
|
|
size_t Height;
|
2020-02-25 22:28:36 +01:00
|
|
|
XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL> PixelData;
|
2020-02-26 14:59:10 +01:00
|
|
|
|
2020-02-25 21:19:39 +01:00
|
|
|
public:
|
2020-08-11 14:43:53 +02:00
|
|
|
XImage() : Width(0), Height(0), PixelData() {};
|
2020-02-26 14:59:10 +01:00
|
|
|
XImage(UINTN W, UINTN H);
|
2020-04-03 22:00:42 +02:00
|
|
|
XImage(const XImage& Image, float scale = 0.f); //the constructor can accept 0 scale as 1.f
|
2020-04-14 18:52:13 +02:00
|
|
|
virtual ~XImage();
|
2020-02-25 21:19:39 +01:00
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
XImage& operator= (const XImage& other);
|
|
|
|
|
|
|
|
UINTN GetSizeInBytes() const; //in bytes
|
|
|
|
void setSizeInPixels(UINTN W, UINTN H);
|
|
|
|
|
2020-02-25 22:28:36 +01:00
|
|
|
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& GetData() const;
|
|
|
|
|
2020-04-04 04:59:17 +02:00
|
|
|
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(INTN x, INTN y) const;
|
|
|
|
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(INTN x, INTN y) const ;
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(INTN x, INTN y);
|
|
|
|
INTN GetWidth() const { return (INTN)Width; }
|
|
|
|
INTN GetHeight() const { return (INTN)Height; }
|
2020-02-25 21:19:39 +01:00
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
void setZero() { SetMem( (void*)GetPixelPtr(0, 0), GetSizeInBytes(), 0); }
|
|
|
|
|
2020-03-04 21:39:48 +01:00
|
|
|
void setEmpty() { Width=0; Height=0; PixelData.setEmpty(); }
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEmpty() const { return PixelData.size() == 0; }
|
2020-03-06 22:08:04 +01:00
|
|
|
|
2020-03-02 16:43:54 +01:00
|
|
|
|
2020-02-26 14:59:10 +01:00
|
|
|
void Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color = { 0, 0, 0, 0 });
|
2020-03-23 20:10:16 +01:00
|
|
|
void Fill(const EG_PIXEL* Color);
|
2020-03-24 16:17:12 +01:00
|
|
|
void FillArea(const EG_PIXEL* Color, EG_RECT& Rect);
|
2020-03-20 18:48:19 +01:00
|
|
|
void FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect);
|
2021-02-06 18:16:46 +01:00
|
|
|
UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, float dx, float dy, float scale);
|
2020-04-06 11:15:36 +02:00
|
|
|
void Copy(XImage* Image);
|
2020-04-19 13:23:23 +02:00
|
|
|
void CopyScaled(const XImage& Image, float scale = 0.f);
|
2020-03-24 16:17:12 +01:00
|
|
|
void CopyRect(const XImage& Image, INTN X, INTN Y);
|
2020-04-03 22:00:42 +02:00
|
|
|
void CopyRect(const XImage& Image, const EG_RECT& OwnPlace, const EG_RECT& InputRect);
|
2021-09-28 15:54:31 +02:00
|
|
|
void Compose(const EG_RECT& OwnPlace, const EG_RECT& InputRect, const XImage& TopImage, XBool Lowest, float TopScale = 0.f);
|
|
|
|
void Compose(INTN PosX, INTN PosY, const XImage& TopImage, XBool Lowest, float topScale = 0); //instead of compose we often can Back.Draw(...) + Top.Draw(...)
|
2020-04-02 08:50:44 +02:00
|
|
|
void FlipRB();
|
2020-03-19 19:35:58 +01:00
|
|
|
EFI_STATUS FromPNG(const UINT8 * Data, UINTN Lenght);
|
|
|
|
EFI_STATUS ToPNG(UINT8** Data, UINTN& OutSize);
|
|
|
|
EFI_STATUS FromSVG(const CHAR8 *SVGData, float scale);
|
2020-04-16 13:42:14 +02:00
|
|
|
EFI_STATUS FromICNS(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize);
|
2024-06-07 22:02:19 +02:00
|
|
|
EFI_STATUS FromBMP(UINT8 * Data, UINTN Length);
|
|
|
|
EFI_STATUS ToBMP(UINT8** FileDataReturn, UINTN& FileDataLengthReturn);
|
2020-04-17 14:21:15 +02:00
|
|
|
|
2020-03-02 13:00:24 +01:00
|
|
|
void GetArea(const EG_RECT& Rect);
|
|
|
|
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
2023-11-07 17:40:28 +01:00
|
|
|
void Draw(INTN x, INTN y, float scale, XBool Opaque) const;
|
|
|
|
void Draw(INTN x, INTN y, float scale) const; //can accept 0 scale as 1.f
|
|
|
|
void Draw(INTN x, INTN y) const;
|
|
|
|
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0) const;
|
|
|
|
void DrawOnBack(INTN x, INTN y, const XImage& Plate) const;
|
2020-03-19 07:56:31 +01:00
|
|
|
//I changed the name because LoadImage is too widely used
|
|
|
|
// will be used instead of old egLoadImage
|
2024-01-08 11:27:38 +01:00
|
|
|
EFI_STATUS LoadXImage(const EFI_FILE *Dir, const XString8& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
2020-10-03 19:02:31 +02:00
|
|
|
EFI_STATUS LoadXImage(const EFI_FILE *Dir, const wchar_t* LIconName);
|
|
|
|
EFI_STATUS LoadXImage(const EFI_FILE *Dir, const char* IconName);
|
|
|
|
EFI_STATUS LoadIcns(const EFI_FILE *Dir, IN CONST CHAR16 *FileName, IN UINTN PixelSize);
|
2020-03-19 05:15:08 +01:00
|
|
|
void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color);
|
2020-04-01 14:57:32 +02:00
|
|
|
void EnsureImageSize(IN UINTN NewWidth, IN UINTN NewHeight);
|
2020-03-23 15:51:20 +01:00
|
|
|
void DummyImage(IN UINTN PixelSize);
|
2020-04-01 14:57:32 +02:00
|
|
|
protected:
|
2021-02-06 18:16:46 +01:00
|
|
|
|
2020-02-25 21:19:39 +01:00
|
|
|
};
|
|
|
|
|
2021-03-19 21:32:42 +01:00
|
|
|
extern XImage NullXImage;
|
|
|
|
|
2020-04-14 18:52:13 +02:00
|
|
|
class IndexedImage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
protected:
|
2020-04-14 21:37:44 +02:00
|
|
|
INTN Id;
|
2020-04-14 18:52:13 +02:00
|
|
|
|
|
|
|
XImage Image;
|
|
|
|
public:
|
2020-04-14 21:37:44 +02:00
|
|
|
INTN getIndex() const { return Id; }
|
2020-04-14 18:52:13 +02:00
|
|
|
void setIndex(INTN Index) { Id = Index; }
|
|
|
|
const XImage& getImage() const { return Image; }
|
|
|
|
void setImage(const XImage& Sample) { Image = Sample; }
|
|
|
|
|
|
|
|
IndexedImage() : Id(0), Image() {}
|
|
|
|
IndexedImage(INTN ID) : Id(ID), Image() {}
|
|
|
|
~IndexedImage() {}
|
|
|
|
};
|
|
|
|
|
2020-02-25 21:19:39 +01:00
|
|
|
#endif //__XSTRINGW_H__
|