Skip to content

Commit

Permalink
Set some images to transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jan 5, 2025
1 parent 9f47d51 commit 429a284
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 42 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -500,31 +500,23 @@ jobs:
fail-fast: false
matrix:
include:
- { driver: gxm }
- { driver: gles2 }
- { driver: gxm, cmake: "-DSIMPLE_HIGHLIGHT=ON -DUSE_SYSTEM_SDL2=ON" }
- { driver: gles2, cmake: "-DUSE_GXM=ON -DUSE_VITA_SHARK=ON" }

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Build GLES2
if: ${{ matrix.driver == 'gles2' }}
run: |
docker run --rm -v $(pwd):/src/ xfangfang/wiliwili_psv_builder:latest \
"cmake -B build -G Ninja -DPLATFORM_PSV=ON -DUSE_SYSTEM_CURL=ON -DUSE_SYSTEM_SDL2=ON -DCMAKE_BUILD_TYPE=Release && \
cmake --build build"
- name: Build GXM
if: ${{ matrix.driver == 'gxm' }}
- name: Build wiliwili
run: |
docker run --rm -v $(pwd):/src/ xfangfang/wiliwili_psv_builder:latest-gxm \
"cmake -B build -G Ninja -DPLATFORM_PSV=ON -DUSE_SYSTEM_CURL=ON -DUSE_GXM=ON -DUSE_VITA_SHARK=ON -DCMAKE_BUILD_TYPE=Release && \
cmake --build build"
- name: Rename eboot
run: mv build/wiliwili.self build/eboot.bin
"cmake -B build -G Ninja -DPLATFORM_PSV=ON -DUSE_SYSTEM_CURL=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=16 \
-DBRLS_UNITY_BUILD=${{ github.event.inputs.disable_unity_build == 'true' && 'OFF' || 'ON' }} \
-DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake }} && \
cmake --build build && \
mv build/wiliwili.self build/eboot.bin"
- name: Upload vpk
uses: actions/upload-artifact@v4
Expand Down
27 changes: 25 additions & 2 deletions wiliwili/include/utils/image_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#include <unordered_map>
#include <borealis/views/image.hpp>

#ifdef BOREALIS_USE_GXM
#include <borealis/extern/nanovg/nanovg_gxm.h>
#define IMAGE_FLAG_BASE NVG_IMAGE_DXT1
#define IMAGE_FLAG_ALPHA NVG_IMAGE_DXT5
#else
#define IMAGE_FLAG_BASE 0
#define IMAGE_FLAG_ALPHA 0
#endif

/**
* 图片加载请求,每个请求对应一个ImageHelper的实例
*/
Expand Down Expand Up @@ -38,7 +47,8 @@ class ImageHelper {
/**
* 加载网络图片。此函数需要工作在主线程。
*/
void load(std::string url);
void load(const std::string& url);
void load(const std::string& url, int flag);

/**
* 取消请求,并清空图片。此函数需要工作在主线程。
Expand All @@ -50,6 +60,17 @@ class ImageHelper {
/// 图片请求后缀,用来控制图片大小
#ifdef USE_WEBP
#ifdef __PSV__
#ifdef BOREALIS_USE_GXM
inline static std::string h_ext = "@256w_144h_1c.webp";
inline static std::string v_ext = "@190w_256h_1c.webp";
inline static std::string face_ext = "@64w_64h_1c_1s.webp";
inline static std::string face_large_ext = "@128w_128h_1c_1s.webp";
inline static std::string emoji_size1_ext = "@32w_32h.webp";
inline static std::string emoji_size2_ext = "@64w_64h.webp";
inline static std::string note_ext = "@256w_256h_85q_!note-comment-multiple.webp";
inline static std::string note_custom_ext = "@{}w_{}h_85q_!note-comment-multiple.webp";
inline static std::string note_raw_ext = "@256h.webp";
#else
inline static std::string h_ext = "@224w_126h_1c.webp";
inline static std::string v_ext = "@156w_210h_1c.webp";
inline static std::string face_ext = "@48w_48h_1c_1s.webp";
Expand All @@ -58,7 +79,8 @@ class ImageHelper {
inline static std::string emoji_size2_ext = "@36w_36h.webp";
inline static std::string note_ext = "@180w_180h_85q_!note-comment-multiple.webp";
inline static std::string note_custom_ext = "@{}w_{}h_85q_!note-comment-multiple.webp";
inline static std::string note_raw_ext = "@300h.webp";
inline static std::string note_raw_ext = "@256h.webp";
#endif
#else
inline static std::string h_ext = "@672w_378h_1c.webp";
inline static std::string v_ext = "@312w_420h_1c.webp";
Expand Down Expand Up @@ -108,6 +130,7 @@ class ImageHelper {
private:
bool isCancel{};
brls::Image* imageView;
int imageFlag;
std::string imageUrl;
Pool::iterator currentIter;

Expand Down
2 changes: 1 addition & 1 deletion wiliwili/source/activity/gallery_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NetImageGalleryItem : public GalleryItem {
explicit NetImageGalleryItem(const std::string& url) {
this->inflateFromXMLString(ImageGalleryItemXML);
this->image->setImageFromRes("icon/bilibili_video.png");
ImageHelper::with(this->image)->load(url);
ImageHelper::with(this->image)->load(url, IMAGE_FLAG_ALPHA);
}
~NetImageGalleryItem() override { ImageHelper::clear(this->image); }

Expand Down
2 changes: 2 additions & 0 deletions wiliwili/source/activity/setting_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ void SettingActivity::onContentAvailable() {
#endif
#elif defined(BOREALIS_USE_D3D11)
+ " (D3D11)"
#elif defined(BOREALIS_USE_GXM)
+ " (GXM)"
#endif
);
labelOpensource->setText(OPENSOURCE);
Expand Down
4 changes: 2 additions & 2 deletions wiliwili/source/fragment/home_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GridSubAreaCell : public RecyclingGridItem {
if (pic.empty()) {
this->image->setImageFromRes("pictures/22_open.png");
} else {
ImageHelper::with(image)->load(pic + ImageHelper::face_ext);
ImageHelper::with(image)->load(pic + ImageHelper::face_ext, IMAGE_FLAG_ALPHA);
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class GridMainAreaCell : public RecyclingGridItem {
if (pic.empty()) {
this->image->setImageFromRes("pictures/22_open.png");
} else {
ImageHelper::with(image)->load(pic + ImageHelper::face_ext);
ImageHelper::with(image)->load(pic + ImageHelper::face_ext, IMAGE_FLAG_ALPHA);
}
}

Expand Down
45 changes: 28 additions & 17 deletions wiliwili/source/utils/image_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
#endif

#ifdef BOREALIS_USE_GXM
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#define STB_DXT_IMPLEMENTATION
#include <borealis/extern/nanovg/stb_dxt.h>
#include <borealis/extern/nanovg/nanovg_gxm.h>

static inline __attribute__((always_inline)) uint32_t nearest_po2(uint32_t val) {
val--;
Expand Down Expand Up @@ -61,32 +66,34 @@ static inline __attribute__((always_inline)) void extract_block(const uint8_t *s
* @param w source width
* @param h source height
* @param stride source stride
* @param isdxt5 0 for DXT1, others for DXT5
* @param isdxt5 false for DXT1, true for DXT5
*/
static void _dxt_compress(uint8_t *dst, uint8_t *src, uint32_t w, uint32_t h, uint32_t stride, int isdxt5) {
static void dxt_compress_ext(uint8_t *dst, uint8_t *src, uint32_t w, uint32_t h, uint32_t stride, bool isdxt5) {
uint8_t block[64];
uint32_t align_w = nearest_po2(w);
uint32_t align_h = nearest_po2(h);
uint32_t s = align_w > align_h ? align_h : align_w;
uint32_t num_blocks = s * s / 16;
uint32_t align_w = MAX(nearest_po2(w), 64);
uint32_t align_h = MAX(nearest_po2(h), 64);
uint32_t s = MIN(align_w, align_h);
uint32_t num_blocks = s * s / 16;
const uint32_t block_size = isdxt5 ? 16 : 8;
uint64_t d, offs_x, offs_y;

for (d = 0; d < num_blocks; d++, dst += block_size) {
d2xy_morton(d, &offs_x, &offs_y);
if (offs_x * 4 >= h || offs_y * 4 >= w)
if (offs_x * 4 >= h || offs_y * 4 >= w)
continue;
extract_block(src + offs_y * 16 + offs_x * stride * 16, stride, block);
stb_compress_dxt_block(dst, block, isdxt5, STB_DXT_NORMAL);
}
if (align_w > align_h)
return _dxt_compress(dst, src + s * 4, w - s, h, stride, isdxt5);
else if (align_w < align_h)
return _dxt_compress(dst, src + w * s * 4, w, h - s, stride, isdxt5);
if (align_w > align_h) {
return dxt_compress_ext(dst, src + s * 4, w - s, h, stride, isdxt5);
}
else if (align_w < align_h) {
return dxt_compress_ext(dst, src + stride * s * 4, w, h - s, stride, isdxt5);
}
}

void dxt_compress(uint8_t *dst, uint8_t *src, uint32_t w, uint32_t h, int isdxt5) {
_dxt_compress(dst, src, w, h, w, isdxt5);
static void dxt_compress(uint8_t *dst, uint8_t *src, uint32_t w, uint32_t h, bool isdxt5) {
dxt_compress_ext(dst, src, w, h, w, isdxt5);
}
#endif

Expand Down Expand Up @@ -134,8 +141,11 @@ std::shared_ptr<ImageHelper> ImageHelper::with(brls::Image* view) {
return item;
}

void ImageHelper::load(std::string url) {
void ImageHelper::load(const std::string &url) { this->load(url, IMAGE_FLAG_BASE); }

void ImageHelper::load(const std::string &url, int flag) {
this->imageUrl = url;
this->imageFlag = flag;

brls::Logger::verbose("load view: {} {}", (size_t)this->imageView, (size_t)this);

Expand Down Expand Up @@ -211,9 +221,10 @@ void ImageHelper::requestImage() {
NVGcontext* vg = brls::Application::getNVGContext();
if (imageData) {
#ifdef BOREALIS_USE_GXM
tex = nvgCreateImageRGBA(vg, imageW, imageH, NVG_IMAGE_DXT1 | NVG_IMAGE_LPDDR, nullptr);
bool dxt5 = this->imageFlag & NVG_IMAGE_DXT5;
tex = nvgCreateImageRGBA(vg, imageW, imageH, (dxt5 ? NVG_IMAGE_DXT5 : NVG_IMAGE_DXT1) | NVG_IMAGE_LPDDR, nullptr);
NVGXMtexture *gxmTex = nvgxmImageHandle(vg, tex);
dxt_compress(gxmTex->data, imageData, imageW, imageH, 0);
dxt_compress(gxmTex->data, imageData, imageW, imageH, dxt5);
#else
tex = nvgCreateImageRGBA(vg, imageW, imageH, 0, imageData);
#endif
Expand Down
4 changes: 4 additions & 0 deletions wiliwili/source/utils/version_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ std::string APPVersion::getPlatform() {
return "NX";
#endif
#elif defined(__PSV__)
#ifdef BOREALIS_USE_GXM
return "PSVita-GXM";
#else
return "PSVita";
#endif
#else
return "Unknown";
#endif
Expand Down
2 changes: 1 addition & 1 deletion wiliwili/source/view/text_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ RichTextImage::RichTextImage(std::string url, float width, float height, bool au
image->setCornerRadius(4);
image->setScalingType(brls::ImageScalingType::FIT);

if (autoLoad) ImageHelper::with(image)->load(this->url);
if (autoLoad) ImageHelper::with(image)->load(this->url, IMAGE_FLAG_ALPHA);
}

RichTextImage::~RichTextImage() {
Expand Down
6 changes: 3 additions & 3 deletions wiliwili/source/view/video_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void RecyclingGridItemVideoCard::setExtraInfo(const std::string& extra, float wi
this->boxHint->setVisibility(brls::Visibility::GONE);
this->pictureHint->setVisibility(brls::Visibility::VISIBLE);
this->pictureHint->setDimensions(width, height);
ImageHelper::with(this->pictureHint)->load(extra);
ImageHelper::with(this->pictureHint)->load(extra, IMAGE_FLAG_ALPHA);
} else {
this->svgUp->setVisibility(brls::Visibility::GONE);
this->boxHint->setVisibility(brls::Visibility::VISIBLE);
Expand Down Expand Up @@ -248,11 +248,11 @@ void RecyclingGridItemPGCVideoCard::setCard(std::string pic, std::string title,
this->labelDuration->setText(badge_bottom_right);

if (!badge_top.empty()) {
ImageHelper::with(this->badgeTop)->load(badge_top);
ImageHelper::with(this->badgeTop)->load(badge_top, IMAGE_FLAG_ALPHA);
}

if (!badge_bottom_left.empty()) {
ImageHelper::with(this->badgeBottomLeft)->load(badge_bottom_left);
ImageHelper::with(this->badgeBottomLeft)->load(badge_bottom_left, IMAGE_FLAG_ALPHA);
}
}

Expand Down

0 comments on commit 429a284

Please sign in to comment.