imageio_util: s/ExUtil/ImgIoUtil/

ExUtil(SetBinaryMode|ReadFile|ReadFromStdin|WriteFile|CopyPlane) ->
ImgIoUtil(SetBinaryMode|ReadFile|ReadFromStdin|WriteFile|CopyPlane)

Change-Id: I5497f8fe514347efeb83b8b8866ef334390fc18e
This commit is contained in:
James Zern 2016-07-21 15:36:29 -07:00
parent bdda5bd4bf
commit da573cf490
12 changed files with 49 additions and 49 deletions

View File

@ -688,7 +688,7 @@ int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
WebPDataInit(&webp_data); WebPDataInit(&webp_data);
memset(image, 0, sizeof(*image)); memset(image, 0, sizeof(*image));
if (!ExUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) { if (!ImgIoUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) {
fprintf(stderr, "Error reading file: %s\n", filename); fprintf(stderr, "Error reading file: %s\n", filename);
return 0; return 0;
} }

View File

@ -60,12 +60,12 @@ static int ReadYUV(const uint8_t* const data, size_t data_size,
pic->use_argb = 0; pic->use_argb = 0;
if (!WebPPictureAlloc(pic)) return 0; if (!WebPPictureAlloc(pic)) return 0;
ExUtilCopyPlane(data, pic->width, pic->y, pic->y_stride, ImgIoUtilCopyPlane(data, pic->width, pic->y, pic->y_stride,
pic->width, pic->height); pic->width, pic->height);
ExUtilCopyPlane(data + y_plane_size, uv_width, ImgIoUtilCopyPlane(data + y_plane_size, uv_width,
pic->u, pic->uv_stride, uv_width, uv_height); pic->u, pic->uv_stride, uv_width, uv_height);
ExUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width, ImgIoUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width,
pic->v, pic->uv_stride, uv_width, uv_height); pic->v, pic->uv_stride, uv_width, uv_height);
return use_argb ? WebPPictureYUVAToARGB(pic) : 1; return use_argb ? WebPPictureYUVAToARGB(pic) : 1;
} }
@ -77,13 +77,13 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t data_size = 0; size_t data_size = 0;
if (pic->width != 0 && pic->height != 0) { if (pic->width != 0 && pic->height != 0) {
ok = ExUtilReadFile(filename, &data, &data_size); ok = ImgIoUtilReadFile(filename, &data, &data_size);
ok = ok && ReadYUV(data, data_size, pic); ok = ok && ReadYUV(data, data_size, pic);
} else { } else {
// If no size specified, try to decode it using WIC. // If no size specified, try to decode it using WIC.
ok = ReadPictureWithWIC(filename, pic, keep_alpha, metadata); ok = ReadPictureWithWIC(filename, pic, keep_alpha, metadata);
if (!ok) { if (!ok) {
ok = ExUtilReadFile(filename, &data, &data_size); ok = ImgIoUtilReadFile(filename, &data, &data_size);
ok = ok && ReadWebP(data, data_size, pic, keep_alpha, metadata); ok = ok && ReadWebP(data, data_size, pic, keep_alpha, metadata);
} }
} }
@ -102,7 +102,7 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
size_t data_size = 0; size_t data_size = 0;
int ok = 0; int ok = 0;
ok = ExUtilReadFile(filename, &data, &data_size); ok = ImgIoUtilReadFile(filename, &data, &data_size);
if (!ok) goto End; if (!ok) goto End;
if (pic->width == 0 || pic->height == 0) { if (pic->width == 0 || pic->height == 0) {
@ -958,7 +958,7 @@ int main(int argc, const char *argv[]) {
// Open the output // Open the output
if (out_file != NULL) { if (out_file != NULL) {
const int use_stdout = !strcmp(out_file, "-"); const int use_stdout = !strcmp(out_file, "-");
out = use_stdout ? ExUtilSetBinaryMode(stdout) : fopen(out_file, "wb"); out = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
if (out == NULL) { if (out == NULL) {
fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file); fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file);
goto Error; goto Error;

View File

@ -505,7 +505,7 @@ static int SaveOutput(const WebPDecBuffer* const buffer,
#endif #endif
if (needs_open_file) { if (needs_open_file) {
fout = use_stdout ? ExUtilSetBinaryMode(stdout) : fopen(out_file, "wb"); fout = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
if (fout == NULL) { if (fout == NULL) {
fprintf(stderr, "Error opening output file %s\n", out_file); fprintf(stderr, "Error opening output file %s\n", out_file);
return 0; return 0;

View File

@ -500,7 +500,7 @@ int main(int argc, const char *argv[]) {
} }
if (out_file != NULL) { if (out_file != NULL) {
if (!ExUtilWriteFile(out_file, webp_data.bytes, webp_data.size)) { if (!ImgIoUtilWriteFile(out_file, webp_data.bytes, webp_data.size)) {
fprintf(stderr, "Error writing output file: %s\n", out_file); fprintf(stderr, "Error writing output file: %s\n", out_file);
goto End; goto End;
} }

View File

@ -469,8 +469,8 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
if (!ExUtilReadFile(kParams.file_name, if (!ImgIoUtilReadFile(kParams.file_name,
&kParams.data.bytes, &kParams.data.size)) { &kParams.data.bytes, &kParams.data.size)) {
goto Error; goto Error;
} }

View File

@ -369,7 +369,7 @@ static int ReadFileToWebPData(const char* const filename,
WebPData* const webp_data) { WebPData* const webp_data) {
const uint8_t* data; const uint8_t* data;
size_t size; size_t size;
if (!ExUtilReadFile(filename, &data, &size)) return 0; if (!ImgIoUtilReadFile(filename, &data, &size)) return 0;
webp_data->bytes = data; webp_data->bytes = data;
webp_data->size = size; webp_data->size = size;
return 1; return 1;
@ -389,7 +389,7 @@ static int CreateMux(const char* const filename, WebPMux** mux) {
static int WriteData(const char* filename, const WebPData* const webpdata) { static int WriteData(const char* filename, const WebPData* const webpdata) {
int ok = 0; int ok = 0;
FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb") FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb")
: ExUtilSetBinaryMode(stdout); : ImgIoUtilSetBinaryMode(stdout);
if (fout == NULL) { if (fout == NULL) {
fprintf(stderr, "Error opening output WebP file %s!\n", filename); fprintf(stderr, "Error opening output WebP file %s!\n", filename);
return 0; return 0;

View File

@ -31,7 +31,7 @@ static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t data_size = 0; size_t data_size = 0;
WebPImageReader reader = NULL; WebPImageReader reader = NULL;
int ok = ExUtilReadFile(filename, &data, &data_size); int ok = ImgIoUtilReadFile(filename, &data, &data_size);
if (!ok) goto Error; if (!ok) goto Error;
pic->use_argb = 1; // force ARGB pic->use_argb = 1; // force ARGB

View File

@ -29,7 +29,7 @@ int main(int argc, const char *argv[]) {
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t data_size = 0; size_t data_size = 0;
int q; int q;
const int ok = ExUtilReadFile(filename, &data, &data_size); const int ok = ImgIoUtilReadFile(filename, &data, &data_size);
if (!ok) continue; if (!ok) continue;
q = VP8EstimateQuality(data, data_size); q = VP8EstimateQuality(data, data_size);
if (!quiet) printf("[%s] ", filename); if (!quiet) printf("[%s] ", filename);

View File

@ -22,7 +22,7 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// File I/O // File I/O
FILE* ExUtilSetBinaryMode(FILE* file) { FILE* ImgIoUtilSetBinaryMode(FILE* file) {
#if defined(_WIN32) #if defined(_WIN32)
if (_setmode(_fileno(file), _O_BINARY) == -1) { if (_setmode(_fileno(file), _O_BINARY) == -1) {
fprintf(stderr, "Failed to reopen file in O_BINARY mode.\n"); fprintf(stderr, "Failed to reopen file in O_BINARY mode.\n");
@ -32,7 +32,7 @@ FILE* ExUtilSetBinaryMode(FILE* file) {
return file; return file;
} }
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size) { int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size) {
static const size_t kBlockSize = 16384; // default initial size static const size_t kBlockSize = 16384; // default initial size
size_t max_size = 0; size_t max_size = 0;
size_t size = 0; size_t size = 0;
@ -42,7 +42,7 @@ int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size) {
*data = NULL; *data = NULL;
*data_size = 0; *data_size = 0;
if (!ExUtilSetBinaryMode(stdin)) return 0; if (!ImgIoUtilSetBinaryMode(stdin)) return 0;
while (!feof(stdin)) { while (!feof(stdin)) {
// We double the buffer size each time and read as much as possible. // We double the buffer size each time and read as much as possible.
@ -65,15 +65,15 @@ int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size) {
return 0; return 0;
} }
int ExUtilReadFile(const char* const file_name, int ImgIoUtilReadFile(const char* const file_name,
const uint8_t** data, size_t* data_size) { const uint8_t** data, size_t* data_size) {
int ok; int ok;
void* file_data; void* file_data;
size_t file_size; size_t file_size;
FILE* in; FILE* in;
const int from_stdin = (file_name == NULL) || !strcmp(file_name, "-"); const int from_stdin = (file_name == NULL) || !strcmp(file_name, "-");
if (from_stdin) return ExUtilReadFromStdin(data, data_size); if (from_stdin) return ImgIoUtilReadFromStdin(data, data_size);
if (data == NULL || data_size == NULL) return 0; if (data == NULL || data_size == NULL) return 0;
*data = NULL; *data = NULL;
@ -103,8 +103,8 @@ int ExUtilReadFile(const char* const file_name,
return 1; return 1;
} }
int ExUtilWriteFile(const char* const file_name, int ImgIoUtilWriteFile(const char* const file_name,
const uint8_t* data, size_t data_size) { const uint8_t* data, size_t data_size) {
int ok; int ok;
FILE* out; FILE* out;
const int to_stdout = (file_name == NULL) || !strcmp(file_name, "-"); const int to_stdout = (file_name == NULL) || !strcmp(file_name, "-");
@ -124,8 +124,8 @@ int ExUtilWriteFile(const char* const file_name,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ExUtilCopyPlane(const uint8_t* src, int src_stride, void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
uint8_t* dst, int dst_stride, int width, int height) { uint8_t* dst, int dst_stride, int width, int height) {
while (height-- > 0) { while (height-- > 0) {
memcpy(dst, src, width * sizeof(*dst)); memcpy(dst, src, width * sizeof(*dst));
src += src_stride; src += src_stride;

View File

@ -25,29 +25,29 @@ extern "C" {
// Reopen file in binary (O_BINARY) mode. // Reopen file in binary (O_BINARY) mode.
// Returns 'file' on success, NULL otherwise. // Returns 'file' on success, NULL otherwise.
FILE* ExUtilSetBinaryMode(FILE* file); FILE* ImgIoUtilSetBinaryMode(FILE* file);
// Allocates storage for entire file 'file_name' and returns contents and size // Allocates storage for entire file 'file_name' and returns contents and size
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should // in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
// be deleted using free(). // be deleted using free().
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling // If 'file_name' is NULL or equal to "-", input is read from stdin by calling
// the function ExUtilReadFromStdin(). // the function ImgIoUtilReadFromStdin().
int ExUtilReadFile(const char* const file_name, int ImgIoUtilReadFile(const char* const file_name,
const uint8_t** data, size_t* data_size); const uint8_t** data, size_t* data_size);
// Same as ExUtilReadFile(), but reads until EOF from stdin instead. // Same as ImgIoUtilReadFile(), but reads until EOF from stdin instead.
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size); int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size);
// Write a data segment into a file named 'file_name'. Returns true if ok. // Write a data segment into a file named 'file_name'. Returns true if ok.
// If 'file_name' is NULL or equal to "-", output is written to stdout. // If 'file_name' is NULL or equal to "-", output is written to stdout.
int ExUtilWriteFile(const char* const file_name, int ImgIoUtilWriteFile(const char* const file_name,
const uint8_t* data, size_t data_size); const uint8_t* data, size_t data_size);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copy width x height pixels from 'src' to 'dst' honoring the strides. // Copy width x height pixels from 'src' to 'dst' honoring the strides.
void ExUtilCopyPlane(const uint8_t* src, int src_stride, void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
uint8_t* dst, int dst_stride, int width, int height); uint8_t* dst, int dst_stride, int width, int height);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View File

@ -51,7 +51,7 @@ int ExUtilLoadWebP(const char* const in_file,
WebPBitstreamFeatures* bitstream) { WebPBitstreamFeatures* bitstream) {
VP8StatusCode status; VP8StatusCode status;
WebPBitstreamFeatures local_features; WebPBitstreamFeatures local_features;
if (!ExUtilReadFile(in_file, data, data_size)) return 0; if (!ImgIoUtilReadFile(in_file, data, data_size)) return 0;
if (bitstream == NULL) { if (bitstream == NULL) {
bitstream = &local_features; bitstream = &local_features;
@ -184,15 +184,15 @@ int ReadWebP(const uint8_t* const data, size_t data_size,
const WebPYUVABuffer* const yuva = &output_buffer->u.YUVA; const WebPYUVABuffer* const yuva = &output_buffer->u.YUVA;
const int uv_width = (pic->width + 1) >> 1; const int uv_width = (pic->width + 1) >> 1;
const int uv_height = (pic->height + 1) >> 1; const int uv_height = (pic->height + 1) >> 1;
ExUtilCopyPlane(yuva->y, yuva->y_stride, ImgIoUtilCopyPlane(yuva->y, yuva->y_stride,
pic->y, pic->y_stride, pic->width, pic->height); pic->y, pic->y_stride, pic->width, pic->height);
ExUtilCopyPlane(yuva->u, yuva->u_stride, ImgIoUtilCopyPlane(yuva->u, yuva->u_stride,
pic->u, pic->uv_stride, uv_width, uv_height); pic->u, pic->uv_stride, uv_width, uv_height);
ExUtilCopyPlane(yuva->v, yuva->v_stride, ImgIoUtilCopyPlane(yuva->v, yuva->v_stride,
pic->v, pic->uv_stride, uv_width, uv_height); pic->v, pic->uv_stride, uv_width, uv_height);
if (has_alpha) { if (has_alpha) {
ExUtilCopyPlane(yuva->a, yuva->a_stride, ImgIoUtilCopyPlane(yuva->a, yuva->a_stride,
pic->a, pic->a_stride, pic->width, pic->height); pic->a, pic->a_stride, pic->width, pic->height);
} }
} }
} }

View File

@ -88,7 +88,7 @@ static HRESULT OpenInputStream(const char* filename, IStream** stream) {
if (!strcmp(filename, "-")) { if (!strcmp(filename, "-")) {
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t data_size = 0; size_t data_size = 0;
const int ok = ExUtilReadFile(filename, &data, &data_size); const int ok = ImgIoUtilReadFile(filename, &data, &data_size);
if (ok) { if (ok) {
HGLOBAL image = GlobalAlloc(GMEM_MOVEABLE, data_size); HGLOBAL image = GlobalAlloc(GMEM_MOVEABLE, data_size);
if (image != NULL) { if (image != NULL) {