新增了原始像素的压缩功能
This commit is contained in:
parent
801ce60031
commit
0a4beef316
@ -9,11 +9,20 @@
|
||||
extern "C" {
|
||||
|
||||
// 将输入的 JPG/PNG 数据转换为 WebP,并返回 WebP 数据
|
||||
unsigned char *convert_image_to_webp(const uint8_t *input_data, size_t input_size, int target_width, int target_height, float quality_factor, size_t *output_size, int preserve_alpha = 0) {
|
||||
unsigned char *convert_image_to_webp(const uint8_t *input_data, size_t input_size,int input_width,int input_height, int target_width, int target_height, float quality_factor, size_t *output_size, int preserve_alpha = 0,int is_original = 0) {
|
||||
int width, height, channels;
|
||||
|
||||
unsigned char *decoded_data = nullptr;
|
||||
if (!is_original) {
|
||||
decoded_data = stbi_load_from_memory(input_data, input_size, &width, &height, &channels, preserve_alpha ? 4 : 3); // 根据是否保留 alpha 通道加载
|
||||
} else {
|
||||
decoded_data = (unsigned char *)input_data;
|
||||
// 当使用原始数据时,需要确保width和height已设置
|
||||
width = input_width;
|
||||
height = input_height;
|
||||
channels = preserve_alpha ? 4 : 3;
|
||||
}
|
||||
// 使用 stb_image 解码输入图像(根据 preserve_alpha 决定加载通道数)
|
||||
unsigned char *decoded_data = stbi_load_from_memory(input_data, input_size, &width, &height, &channels, preserve_alpha ? 4 : 3); // 根据是否保留 alpha 通道加载
|
||||
|
||||
if (!decoded_data) {
|
||||
return nullptr; // 图像解码失败
|
||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in New Issue
Block a user