!33 support JPEG file

This commit is contained in:
idea4good 2021-04-02 11:37:13 +08:00
parent 40ab2c5ed8
commit b209383fdb
21 changed files with 136 additions and 76 deletions

View File

@ -123,10 +123,6 @@ typedef struct struct_lattice_font_info
unsigned int count; unsigned int count;
LATTICE* lattice_array; LATTICE* lattice_array;
} LATTICE_FONT_INFO; } LATTICE_FONT_INFO;
typedef struct struct_font_info
{
const void* font; //could be LATTICE_FONT_INFO or TTF
} FONT_INFO;
//Rebuild gui library once you change this file //Rebuild gui library once you change this file
enum FONT_LIST enum FONT_LIST
{ {
@ -140,15 +136,15 @@ enum FONT_LIST
FONT_CUSTOM6, FONT_CUSTOM6,
FONT_MAX FONT_MAX
}; };
enum BITMAP_LIST enum IMAGE_LIST
{ {
BITMAP_CUSTOM1, IMAGE_CUSTOM1,
BITMAP_CUSTOM2, IMAGE_CUSTOM2,
BITMAP_CUSTOM3, IMAGE_CUSTOM3,
BITMAP_CUSTOM4, IMAGE_CUSTOM4,
BITMAP_CUSTOM5, IMAGE_CUSTOM5,
BITMAP_CUSTOM6, IMAGE_CUSTOM6,
BITMAP_MAX IMAGE_MAX
}; };
enum COLOR_LIST enum COLOR_LIST
{ {
@ -175,7 +171,7 @@ public:
ASSERT(false); ASSERT(false);
return -1; return -1;
} }
s_font_map[index].font = font; s_font_map[index] = font;
return 0; return 0;
} }
static const void* get_font(FONT_LIST index) static const void* get_font(FONT_LIST index)
@ -185,27 +181,28 @@ public:
ASSERT(false); ASSERT(false);
return 0; return 0;
} }
return s_font_map[index].font; return s_font_map[index];
} }
static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) static int add_image(IMAGE_LIST index, const void* image_info)
{ {
if (index >= BITMAP_MAX) if (index >= IMAGE_MAX)
{ {
ASSERT(false); ASSERT(false);
return -1; return -1;
} }
s_bmp_map[index] = bmp; s_image_map[index] = image_info;
return 0; return 0;
} }
static const BITMAP_INFO* get_bmp(BITMAP_LIST index) static const void* get_image(IMAGE_LIST index)
{ {
if (index >= BITMAP_MAX) if (index >= IMAGE_MAX)
{ {
ASSERT(false); ASSERT(false);
return 0; return 0;
} }
return s_bmp_map[index]; return s_image_map[index];
} }
static int add_color(COLOR_LIST index, const unsigned int color) static int add_color(COLOR_LIST index, const unsigned int color)
{ {
if (index >= COLOR_MAX) if (index >= COLOR_MAX)
@ -226,8 +223,8 @@ public:
return s_color_map[index]; return s_color_map[index];
} }
private: private:
static FONT_INFO s_font_map[FONT_MAX]; static const void* s_font_map[FONT_MAX];
static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static const void* s_image_map[IMAGE_MAX];
static unsigned int s_color_map[COLOR_MAX]; static unsigned int s_color_map[COLOR_MAX];
}; };
#include <string.h> #include <string.h>
@ -318,7 +315,7 @@ public:
c_rect rect; //framebuffer area c_rect rect; //framebuffer area
}; };
class c_surface { class c_surface {
friend class c_display; friend class c_bitmap; friend class c_display; friend class c_bitmap_operator;
public: public:
c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0)
{ {
@ -1131,12 +1128,19 @@ public:
}; };
#define DEFAULT_MASK_COLOR 0xFF080408 #define DEFAULT_MASK_COLOR 0xFF080408
class c_surface; class c_surface;
class c_bitmap class c_image_operator
{ {
public: public:
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0;
virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0;
};
class c_bitmap_operator : public c_image_operator
{ {
ASSERT(pBitmap); public:
virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
ASSERT(image_info);
BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info;
unsigned short* lower_fb_16 = 0; unsigned short* lower_fb_16 = 0;
unsigned int* lower_fb_32 = 0; unsigned int* lower_fb_32 = 0;
int lower_fb_width = 0; int lower_fb_width = 0;
@ -1172,8 +1176,10 @@ public:
} }
} }
} }
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO* pBitmap, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{ {
ASSERT(image_info);
BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info;
if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height)) if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height))
{ {
return; return;
@ -1213,6 +1219,20 @@ public:
} }
} }
}; };
class c_image
{
public:
static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
image_operator->draw_image(surface, z_order, image_info, x, y, mask_rgb);
}
static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
image_operator->draw_image(surface, z_order, image_info, x, y, src_x, src_y, width, height, mask_rgb);
}
static c_image_operator* image_operator;
};
class c_wnd; class c_wnd;
class c_surface; class c_surface;
typedef enum typedef enum
@ -3384,11 +3404,15 @@ private:
unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map[64];
unsigned char m_frame_len_map_index; unsigned char m_frame_len_map_index;
}; };
#ifdef GUILITE_ON
c_bitmap_operator the_bitmap_op = c_bitmap_operator();
c_image_operator* c_image::image_operator = &the_bitmap_op;
#endif
#ifdef GUILITE_ON #ifdef GUILITE_ON
FONT_INFO c_theme::s_font_map[FONT_MAX]; const void* c_theme::s_font_map[FONT_MAX];
const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; const void* c_theme::s_image_map[IMAGE_MAX];
unsigned int c_theme::s_color_map[COLOR_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX];
#endif #endif

View File

@ -110,7 +110,10 @@ Even a C beginner could master GuiLite quickly. The source code only uses basic
</tr> </tr>
<tr> <tr>
<td align="center"><a href="https://github.com/idea4good/GuiLitePreviewer"><img src="documents/Previewer.gif" width="600px;"/><br /><sub><b>Layout GUI</b></sub></a> <td align="center"><a href="https://github.com/idea4good/GuiLitePreviewer"><img src="documents/Previewer.gif" width="600px;"/><br /><sub><b>Layout GUI</b></sub></a>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloFFmpeg"><img src="documents/HelloFFmpeg.jpg" width="600px;"/><br /><sub><b>Video: GuiLite + FFmpeg</b></sub></a> <td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloJPG"><img src="documents/HelloJPG.gif" width="600px;"/><br /><sub><b>Render JPG file quickly</b></sub></a>
</tr>
<tr>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloFFmpeg"><img src="documents/HelloFFmpeg.jpg" width="600px;"/><br /><sub><b>Play video with FFmpeg</b></sub></a>
</tr> </tr>
</table> </table>

View File

@ -108,7 +108,10 @@
</tr> </tr>
<tr> <tr>
<td align="center"><a href="https://github.com/idea4good/GuiLitePreviewer"><img src="documents/Previewer.gif" width="600px;"/><br /><sub><b>Layout GUI</b></sub></a> <td align="center"><a href="https://github.com/idea4good/GuiLitePreviewer"><img src="documents/Previewer.gif" width="600px;"/><br /><sub><b>Layout GUI</b></sub></a>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloFFmpeg"><img src="documents/HelloFFmpeg.jpg" width="600px;"/><br /><sub><b>Video: GuiLite + FFmpeg</b></sub></a> <td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloJPG"><img src="documents/HelloJPG.gif" width="600px;"/><br /><sub><b>Render JPG file quickly</b></sub></a>
</tr>
<tr>
<td align="center"><a href="https://gitee.com/idea4good/GuiLiteSamples/tree/master/HelloFFmpeg"><img src="documents/HelloFFmpeg.jpg" width="600px;"/><br /><sub><b>Play video with FFmpeg</b></sub></a>
</tr> </tr>
</table> </table>

BIN
documents/HelloJPG.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 KiB

View File

@ -42,5 +42,5 @@ curl --include --request POST --header "Content-Type: application/json" --data-b
\"city\" :\"$city\", \"city\" :\"$city\",
\"org\" :\"$org\", \"org\" :\"$org\",
\"log\" :\"$build_time\", \"log\" :\"$build_time\",
\"version\" :\"v2.1\" \"version\" :\"v2.2\"
}]" $url > /dev/null }]" $url > /dev/null

View File

@ -389,8 +389,8 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="core\adapter\api_win.cpp" /> <ClCompile Include="core\adapter\api_win.cpp" />
<ClCompile Include="core\bitmap.cpp" />
<ClCompile Include="core\display.cpp" /> <ClCompile Include="core\display.cpp" />
<ClCompile Include="core\image.cpp" />
<ClCompile Include="core\theme.cpp" /> <ClCompile Include="core\theme.cpp" />
<ClCompile Include="core\wnd.cpp" /> <ClCompile Include="core\wnd.cpp" />
<ClCompile Include="core\word.cpp" /> <ClCompile Include="core\word.cpp" />

View File

@ -34,9 +34,6 @@
<ClCompile Include="widgets\wave_ctrl.cpp"> <ClCompile Include="widgets\wave_ctrl.cpp">
<Filter>widgets</Filter> <Filter>widgets</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="core\bitmap.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="core\display.cpp"> <ClCompile Include="core\display.cpp">
<Filter>core</Filter> <Filter>core</Filter>
</ClCompile> </ClCompile>
@ -52,6 +49,9 @@
<ClCompile Include="core\adapter\api_win.cpp"> <ClCompile Include="core\adapter\api_win.cpp">
<Filter>core\adapter</Filter> <Filter>core\adapter</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="core\image.cpp">
<Filter>core</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="core"> <Filter Include="core">

View File

@ -1 +0,0 @@
#include "../core_include/bitmap.h"

8
workspace/core/image.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "../core_include/image.h"
#ifdef GUILITE_ON
c_bitmap_operator the_bitmap_op = c_bitmap_operator();
c_image_operator* c_image::image_operator = &the_bitmap_op;
#endif

View File

@ -2,8 +2,8 @@
#ifdef GUILITE_ON #ifdef GUILITE_ON
FONT_INFO c_theme::s_font_map[FONT_MAX]; const void* c_theme::s_font_map[FONT_MAX];
const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; const void* c_theme::s_image_map[IMAGE_MAX];
unsigned int c_theme::s_color_map[COLOR_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX];
#endif #endif

View File

@ -103,7 +103,7 @@ public:
}; };
class c_surface { class c_surface {
friend class c_display; friend class c_bitmap; friend class c_display; friend class c_bitmap_operator;
public: public:
c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0)
{ {

View File

@ -6,12 +6,21 @@
#define DEFAULT_MASK_COLOR 0xFF080408 #define DEFAULT_MASK_COLOR 0xFF080408
class c_surface; class c_surface;
class c_bitmap
class c_image_operator
{ {
public: public:
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0;
virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0;
};
class c_bitmap_operator : public c_image_operator
{ {
ASSERT(pBitmap); public:
virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
ASSERT(image_info);
BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info;
unsigned short* lower_fb_16 = 0; unsigned short* lower_fb_16 = 0;
unsigned int* lower_fb_32 = 0; unsigned int* lower_fb_32 = 0;
int lower_fb_width = 0; int lower_fb_width = 0;
@ -48,8 +57,10 @@ public:
} }
} }
static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO* pBitmap, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{ {
ASSERT(image_info);
BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info;
if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height)) if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height))
{ {
return; return;
@ -89,5 +100,20 @@ public:
} }
} }
} }
};
class c_image
{
public:
static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
image_operator->draw_image(surface, z_order, image_info, x, y, mask_rgb);
}
static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR)
{
image_operator->draw_image(surface, z_order, image_info, x, y, src_x, src_y, width, height, mask_rgb);
}
static c_image_operator* image_operator;
}; };

View File

@ -23,8 +23,3 @@ typedef struct struct_lattice_font_info
unsigned int count; unsigned int count;
LATTICE* lattice_array; LATTICE* lattice_array;
} LATTICE_FONT_INFO; } LATTICE_FONT_INFO;
typedef struct struct_font_info
{
const void* font; //could be LATTICE_FONT_INFO or TTF
} FONT_INFO;

View File

@ -18,16 +18,16 @@ enum FONT_LIST
FONT_MAX FONT_MAX
}; };
enum BITMAP_LIST enum IMAGE_LIST
{ {
BITMAP_CUSTOM1, IMAGE_CUSTOM1,
BITMAP_CUSTOM2, IMAGE_CUSTOM2,
BITMAP_CUSTOM3, IMAGE_CUSTOM3,
BITMAP_CUSTOM4, IMAGE_CUSTOM4,
BITMAP_CUSTOM5, IMAGE_CUSTOM5,
BITMAP_CUSTOM6, IMAGE_CUSTOM6,
BITMAP_MAX IMAGE_MAX
}; };
enum COLOR_LIST enum COLOR_LIST
@ -58,9 +58,10 @@ public:
ASSERT(false); ASSERT(false);
return -1; return -1;
} }
s_font_map[index].font = font; s_font_map[index] = font;
return 0; return 0;
} }
static const void* get_font(FONT_LIST index) static const void* get_font(FONT_LIST index)
{ {
if (index >= FONT_MAX) if (index >= FONT_MAX)
@ -68,27 +69,30 @@ public:
ASSERT(false); ASSERT(false);
return 0; return 0;
} }
return s_font_map[index].font; return s_font_map[index];
} }
static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp)
static int add_image(IMAGE_LIST index, const void* image_info)
{ {
if (index >= BITMAP_MAX) if (index >= IMAGE_MAX)
{ {
ASSERT(false); ASSERT(false);
return -1; return -1;
} }
s_bmp_map[index] = bmp; s_image_map[index] = image_info;
return 0; return 0;
} }
static const BITMAP_INFO* get_bmp(BITMAP_LIST index)
static const void* get_image(IMAGE_LIST index)
{ {
if (index >= BITMAP_MAX) if (index >= IMAGE_MAX)
{ {
ASSERT(false); ASSERT(false);
return 0; return 0;
} }
return s_bmp_map[index]; return s_image_map[index];
} }
static int add_color(COLOR_LIST index, const unsigned int color) static int add_color(COLOR_LIST index, const unsigned int color)
{ {
if (index >= COLOR_MAX) if (index >= COLOR_MAX)
@ -99,6 +103,7 @@ public:
s_color_map[index] = color; s_color_map[index] = color;
return 0; return 0;
} }
static const unsigned int get_color(COLOR_LIST index) static const unsigned int get_color(COLOR_LIST index)
{ {
if (index >= COLOR_MAX) if (index >= COLOR_MAX)
@ -108,8 +113,9 @@ public:
} }
return s_color_map[index]; return s_color_map[index];
} }
private: private:
static FONT_INFO s_font_map[FONT_MAX]; static const void* s_font_map[FONT_MAX];
static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static const void* s_image_map[IMAGE_MAX];
static unsigned int s_color_map[COLOR_MAX]; static unsigned int s_color_map[COLOR_MAX];
}; };

View File

@ -2,7 +2,6 @@
#include "../core_include/api.h" #include "../core_include/api.h"
#include "../core_include/resource.h" #include "../core_include/resource.h"
#include "../core_include/bitmap.h"
#include "../core_include/display.h" #include "../core_include/display.h"
class c_wnd; class c_wnd;

View File

@ -2,7 +2,7 @@ echo "Build header-only library: GuiLite.h"
# build GuiLiteRaw.h # build GuiLiteRaw.h
cd core_include cd core_include
cat api.h resource.h theme.h display.h word.h bitmap.h wnd.h > core.h cat api.h resource.h theme.h display.h word.h image.h wnd.h > core.h
mv core.h ../ mv core.h ../
cd ../widgets_include cd ../widgets_include

View File

@ -66,7 +66,7 @@ set raw_data=[{^
\"city\" :\"%city%\",^ \"city\" :\"%city%\",^
\"org\" :\"%org%\",^ \"org\" :\"%org%\",^
\"log\" :\"%datetime%\",^ \"log\" :\"%datetime%\",^
\"version\" :\"v2.1\"^ \"version\" :\"v2.2\"^
}] }]
curl.exe --include --request POST --header "Content-Type: application/json" --data-binary "%raw_data%" "%url%" curl.exe --include --request POST --header "Content-Type: application/json" --data-binary "%raw_data%" "%url%"

View File

@ -3,7 +3,6 @@
#include "../core_include/api.h" #include "../core_include/api.h"
#include "../core_include/wnd.h" #include "../core_include/wnd.h"
#include "../core_include/resource.h" #include "../core_include/resource.h"
#include "../core_include/bitmap.h"
#include "../core_include/word.h" #include "../core_include/word.h"
#include "../core_include/display.h" #include "../core_include/display.h"
#include "../core_include/theme.h" #include "../core_include/theme.h"

View File

@ -4,7 +4,6 @@
#include "../core_include/wnd.h" #include "../core_include/wnd.h"
#include "../core_include/display.h" #include "../core_include/display.h"
#include "../core_include/resource.h" #include "../core_include/resource.h"
#include "../core_include/bitmap.h"
#include "../core_include/theme.h" #include "../core_include/theme.h"
#include "../core_include/word.h" #include "../core_include/word.h"

View File

@ -4,7 +4,6 @@
#include "../core_include/resource.h" #include "../core_include/resource.h"
#include "../core_include/wnd.h" #include "../core_include/wnd.h"
#include "../core_include/display.h" #include "../core_include/display.h"
#include "../core_include/bitmap.h"
#include "../core_include/word.h" #include "../core_include/word.h"
#include "../core_include/theme.h" #include "../core_include/theme.h"
#include "../widgets_include/button.h" #include "../widgets_include/button.h"