mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
fix (plg_image_c): fix issue brought by #731
This commit is contained in:
parent
ceffa180cd
commit
00fc2ee960
8 changed files with 8083 additions and 40 deletions
|
|
@ -1,10 +0,0 @@
|
|||
package plg_image_c
|
||||
|
||||
// #include "image_heif.h"
|
||||
// #cgo LDFLAGS: -lheif
|
||||
import "C"
|
||||
|
||||
func heif(input uintptr, output uintptr, size int) {
|
||||
C.heif_to_jpeg(C.int(input), C.int(output), C.int(size))
|
||||
return
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package plg_image_c
|
||||
|
||||
// #include "image_jpeg.h"
|
||||
// #cgo LDFLAGS: -l:libjpeg.a
|
||||
import "C"
|
||||
|
||||
func jpeg(input uintptr, output uintptr, size int) {
|
||||
C.jpeg_to_jpeg(C.int(input), C.int(output), C.int(size))
|
||||
return
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package plg_image_c
|
||||
|
||||
// #include "image_png.h"
|
||||
// #cgo LDFLAGS: -l:libpng.a -l:libz.a -l:libwebp.a -fopenmp
|
||||
import "C"
|
||||
|
||||
func png(input uintptr, output uintptr, size int) {
|
||||
C.png_to_webp(C.int(input), C.int(output), C.int(size))
|
||||
return
|
||||
}
|
||||
81
server/plugin/plg_image_c/image_psd.c
Normal file
81
server/plugin/plg_image_c/image_psd.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "image_psd_vendor.h"
|
||||
#include <webp/encode.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define BUF_SIZE 1024 * 16
|
||||
#define WEBP_QUALITY 50
|
||||
|
||||
int psd_to_webp(int inputDesc, int outputDesc, int targetSize) {
|
||||
#ifdef HAS_DEBUG
|
||||
clock_t t;
|
||||
t = clock();
|
||||
#endif
|
||||
FILE* input = fdopen(inputDesc, "rb");
|
||||
FILE* output = fdopen(outputDesc, "wb");
|
||||
int status = 0;
|
||||
if (!input || !output) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// STEP1: write input to a file as stb doesn't work out well with our descriptor
|
||||
char fname_in[32] = "/tmp/filestash.XXXXXX";
|
||||
int _mkstemp_in = mkstemp(fname_in);
|
||||
if (!_mkstemp_in) {
|
||||
ERROR("mkstemp_in");
|
||||
return 1;
|
||||
}
|
||||
FILE* f_in = fdopen(_mkstemp_in, "wb");
|
||||
if (!f_in) {
|
||||
ERROR("fdopen");
|
||||
return 1;
|
||||
}
|
||||
char content[BUF_SIZE];
|
||||
int read;
|
||||
while ((read = fread(content, sizeof(char), BUF_SIZE, input))) {
|
||||
fwrite(content, read, sizeof(char), f_in);
|
||||
}
|
||||
fclose(f_in);
|
||||
DEBUG("setup");
|
||||
|
||||
// STEP2: decode psd
|
||||
DEBUG("init");
|
||||
int width, height, channels;
|
||||
unsigned char* imageData = stbi_load(fname_in, &width, &height, &channels, 0);
|
||||
if (!imageData) {
|
||||
ERROR("cannot_load");
|
||||
status = 1;
|
||||
goto CLEANUP_AND_ABORT;
|
||||
}
|
||||
DEBUG("decoded");
|
||||
|
||||
size_t webp_output_size;
|
||||
uint8_t* webp_output_data = NULL;
|
||||
int success = 0;
|
||||
if (channels == 3) {
|
||||
success = WebPEncodeRGB(imageData, width, height, width * channels, WEBP_QUALITY, &webp_output_data);
|
||||
} else if (channels == 4) {
|
||||
success = WebPEncodeRGBA(imageData, width, height, width * channels, WEBP_QUALITY, &webp_output_data);
|
||||
}
|
||||
DEBUG("encoded");
|
||||
|
||||
if (!success) {
|
||||
stbi_image_free(imageData);
|
||||
status = 1;
|
||||
goto CLEANUP_AND_ABORT;
|
||||
}
|
||||
fwrite(webp_output_data, webp_output_size, 1, output);
|
||||
fprintf(stderr, "WRITEN[%d]", webp_output_size);
|
||||
fflush(output);
|
||||
|
||||
WebPFree(webp_output_data);
|
||||
stbi_image_free(imageData);
|
||||
DEBUG("done");
|
||||
|
||||
|
||||
CLEANUP_AND_ABORT:
|
||||
remove(fname_in);
|
||||
return 0;
|
||||
}
|
||||
10
server/plugin/plg_image_c/image_psd.go
Normal file
10
server/plugin/plg_image_c/image_psd.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package plg_image_c
|
||||
|
||||
// #include "image_psd.h"
|
||||
// #cgo LDFLAGS: -l:libwebp.a
|
||||
import "C"
|
||||
|
||||
func psd(input uintptr, output uintptr, size int) {
|
||||
C.psd_to_webp(C.int(input), C.int(output), C.int(size))
|
||||
return
|
||||
}
|
||||
4
server/plugin/plg_image_c/image_psd.h
Normal file
4
server/plugin/plg_image_c/image_psd.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int psd_to_webp(int input, int output, int targetSize);
|
||||
7988
server/plugin/plg_image_c/image_psd_vendor.h
Normal file
7988
server/plugin/plg_image_c/image_psd_vendor.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +0,0 @@
|
|||
package plg_image_c
|
||||
|
||||
// #include "image_raw.h"
|
||||
// #cgo LDFLAGS: -l:libjpeg.a -l:libraw.a -fopenmp -l:libstdc++.a -llcms2 -lm
|
||||
import "C"
|
||||
|
||||
func raw(input uintptr, output uintptr, size int) {
|
||||
C.raw_to_jpeg(C.int(input), C.int(output), C.int(size))
|
||||
return
|
||||
}
|
||||
Loading…
Reference in a new issue