mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +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 (!ok) goto End;
|
||||||
|
|
||||||
if (pic->width == 0 || pic->height == 0) {
|
if (pic->width == 0 || pic->height == 0) {
|
||||||
ok = 0;
|
WebPImageReader reader = WebPGuessImageReader(data, data_size);
|
||||||
if (data_size >= 12) {
|
ok = (reader != NULL) && reader(data, data_size, pic, keep_alpha, metadata);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// If image size is specified, infer it as YUV format.
|
// If image size is specified, infer it as YUV format.
|
||||||
ok = ReadYUV(data, data_size, pic);
|
ok = ReadYUV(data, data_size, pic);
|
||||||
|
@ -33,3 +33,14 @@ WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
|||||||
}
|
}
|
||||||
return format;
|
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,
|
WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||||
size_t data_size);
|
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
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#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,
|
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;
|
volatile int ok = 0;
|
||||||
int stride, width, height;
|
int stride, width, height;
|
||||||
volatile struct jpeg_decompress_struct dinfo;
|
volatile struct jpeg_decompress_struct dinfo;
|
||||||
@ -264,6 +265,7 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
|||||||
JSAMPROW buffer[1];
|
JSAMPROW buffer[1];
|
||||||
JPEGReadContext ctx;
|
JPEGReadContext ctx;
|
||||||
|
|
||||||
|
(void)keep_alpha;
|
||||||
memset(&ctx, 0, sizeof(ctx));
|
memset(&ctx, 0, sizeof(ctx));
|
||||||
ctx.data = data;
|
ctx.data = data;
|
||||||
ctx.data_size = data_size;
|
ctx.data_size = data_size;
|
||||||
@ -333,11 +335,12 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
|||||||
}
|
}
|
||||||
#else // !WEBP_HAVE_JPEG
|
#else // !WEBP_HAVE_JPEG
|
||||||
int ReadJPEG(const uint8_t* const data, size_t data_size,
|
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) {
|
struct Metadata* const metadata) {
|
||||||
(void)data;
|
(void)data;
|
||||||
(void)data_size;
|
(void)data_size;
|
||||||
(void)pic;
|
(void)pic;
|
||||||
|
(void)keep_alpha;
|
||||||
(void)metadata;
|
(void)metadata;
|
||||||
fprintf(stderr, "JPEG support not compiled. Please install the libjpeg "
|
fprintf(stderr, "JPEG support not compiled. Please install the libjpeg "
|
||||||
"development package before building.\n");
|
"development package before building.\n");
|
||||||
|
@ -25,8 +25,11 @@ struct WebPPicture;
|
|||||||
// Reads a JPEG from 'data', returning the decoded output in 'pic'.
|
// Reads a JPEG from 'data', returning the decoded output in 'pic'.
|
||||||
// The output is RGB or YUV depending on pic->use_argb value.
|
// The output is RGB or YUV depending on pic->use_argb value.
|
||||||
// Returns true on success.
|
// 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,
|
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
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
Loading…
Reference in New Issue
Block a user