mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Merge "introduce a common signature for all image reader function"
This commit is contained in:
commit
eee788e26a
@ -105,19 +105,8 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
if (!ok) goto End;
|
||||
|
||||
if (pic->width == 0 || pic->height == 0) {
|
||||
ok = 0;
|
||||
if (data_size >= 12) {
|
||||
const WebPInputFileFormat format = WebPGuessImageType(data, data_size);
|
||||
if (format == WEBP_PNG_FORMAT) {
|
||||
ok = ReadPNG(data, data_size, pic, keep_alpha, metadata);
|
||||
} else if (format == WEBP_JPEG_FORMAT) {
|
||||
ok = ReadJPEG(data, data_size, pic, metadata);
|
||||
} else if (format == WEBP_TIFF_FORMAT) {
|
||||
ok = ReadTIFF(data, data_size, pic, keep_alpha, metadata);
|
||||
} else if (format == WEBP_WEBP_FORMAT) {
|
||||
ok = ReadWebP(data, data_size, pic, keep_alpha, metadata);
|
||||
}
|
||||
}
|
||||
WebPImageReader reader = WebPGuessImageReader(data, data_size);
|
||||
ok = (reader != NULL) && reader(data, data_size, pic, keep_alpha, metadata);
|
||||
} else {
|
||||
// If image size is specified, infer it as YUV format.
|
||||
ok = ReadYUV(data, data_size, pic);
|
||||
|
@ -33,3 +33,14 @@ WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
size_t data_size) {
|
||||
switch (WebPGuessImageType(data, data_size)) {
|
||||
case WEBP_PNG_FORMAT: return ReadPNG;
|
||||
case WEBP_JPEG_FORMAT: return ReadJPEG;
|
||||
case WEBP_TIFF_FORMAT: return ReadTIFF;
|
||||
case WEBP_WEBP_FORMAT: return ReadWebP;
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
@ -44,6 +44,16 @@ typedef enum {
|
||||
WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||
size_t data_size);
|
||||
|
||||
// Signature for common image-reading functions (ReadPNG, ReadJPEG, ...)
|
||||
typedef int (*WebPImageReader)(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
int keep_alpha, struct Metadata* const metadata);
|
||||
|
||||
// This function is similar to WebPGuessImageType(), but returns a
|
||||
// suitable reader function. Or NULL if the image can't be guessed.
|
||||
WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
size_t data_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
@ -255,7 +255,8 @@ static void ContextSetup(volatile struct jpeg_decompress_struct* const cinfo,
|
||||
}
|
||||
|
||||
int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic, Metadata* const metadata) {
|
||||
WebPPicture* const pic, int keep_alpha,
|
||||
Metadata* const metadata) {
|
||||
volatile int ok = 0;
|
||||
int stride, width, height;
|
||||
volatile struct jpeg_decompress_struct dinfo;
|
||||
@ -264,6 +265,7 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
JSAMPROW buffer[1];
|
||||
JPEGReadContext ctx;
|
||||
|
||||
(void)keep_alpha;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.data = data;
|
||||
ctx.data_size = data_size;
|
||||
@ -333,11 +335,12 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
}
|
||||
#else // !WEBP_HAVE_JPEG
|
||||
int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
struct WebPPicture* const pic, int keep_alpha,
|
||||
struct Metadata* const metadata) {
|
||||
(void)data;
|
||||
(void)data_size;
|
||||
(void)pic;
|
||||
(void)keep_alpha;
|
||||
(void)metadata;
|
||||
fprintf(stderr, "JPEG support not compiled. Please install the libjpeg "
|
||||
"development package before building.\n");
|
||||
|
@ -25,8 +25,11 @@ struct WebPPicture;
|
||||
// Reads a JPEG from 'data', returning the decoded output in 'pic'.
|
||||
// The output is RGB or YUV depending on pic->use_argb value.
|
||||
// Returns true on success.
|
||||
// 'keep_alpha' has no effect, but is kept for coherence with other signatures
|
||||
// for image readers.
|
||||
int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic, struct Metadata* const metadata);
|
||||
struct WebPPicture* const pic, int keep_alpha,
|
||||
struct Metadata* const metadata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
Loading…
Reference in New Issue
Block a user