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
|
|
|
//#include <Platform.h>
|
2020-02-28 21:28:33 +01:00
|
|
|
//
|
2020-03-02 16:43:54 +01:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <Protocol/GraphicsOutput.h>
|
|
|
|
}
|
|
|
|
#include "../cpp_foundation/XToolsCommon.h"
|
|
|
|
#include "../cpp_foundation/XArray.h"
|
2020-03-18 07:39:11 +01:00
|
|
|
#include "../cpp_foundation/XStringW.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:
|
|
|
|
XImage();
|
2020-02-26 14:59:10 +01:00
|
|
|
XImage(UINTN W, UINTN H);
|
2020-03-02 13:00:24 +01:00
|
|
|
XImage(EG_IMAGE* egImage);
|
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-02-25 21:19:39 +01:00
|
|
|
~XImage();
|
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
XImage& operator= (const XImage& other);
|
|
|
|
|
2020-02-25 21:19:39 +01:00
|
|
|
protected:
|
2020-03-09 02:12:24 +01:00
|
|
|
UINTN GetSizeInBytes() const; //in bytes
|
2020-02-25 21:19:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
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(); }
|
2020-03-02 16:43:54 +01:00
|
|
|
bool 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);
|
2020-03-02 13:00:24 +01:00
|
|
|
void CopyScaled(const XImage& Image, float scale);
|
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);
|
2020-03-17 20:43:58 +01:00
|
|
|
void Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest); //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-03-23 15:51:20 +01:00
|
|
|
EFI_STATUS FromEGImage(const EG_IMAGE* egImage);
|
2020-03-24 16:17:12 +01:00
|
|
|
EG_IMAGE* ToEGImage();
|
2020-03-02 13:00:24 +01:00
|
|
|
void GetArea(const EG_RECT& Rect);
|
|
|
|
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
2020-03-25 18:49:01 +01:00
|
|
|
void Draw(INTN x, INTN y, float scale, bool Opaque);
|
2020-03-24 16:17:12 +01:00
|
|
|
void Draw(INTN x, INTN y, float scale); //can accept 0 scale as 1.f
|
|
|
|
void Draw(INTN x, INTN y);
|
2020-03-09 09:14:05 +01:00
|
|
|
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0);
|
2020-04-04 19:02:30 +02:00
|
|
|
void DrawOnBack(INTN x, INTN y, const XImage& Plate);
|
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
|
|
|
|
EFI_STATUS LoadXImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
2020-03-30 17:31:52 +02:00
|
|
|
EFI_STATUS LoadXImage(EFI_FILE *Dir, const wchar_t* LIconName);
|
2020-03-25 18:49:01 +01:00
|
|
|
EFI_STATUS LoadXImage(EFI_FILE *Dir, const char* IconName);
|
2020-03-27 17:50:17 +01:00
|
|
|
EFI_STATUS LoadIcns(IN 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:
|
|
|
|
UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, int dx, int dy, float scale);
|
2020-02-25 21:19:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__XSTRINGW_H__
|