Refactoring

parent 7c9e932f
......@@ -228,39 +228,12 @@ static void extract_jpeg_params(const unsigned char *data, size_t data_length,
#define IMAX(a,b) ((a) > (b) ? (a) : (b))
/*Parse a picture SPECIFICATION as given on the command-line.
spec: The specification.
error_message: Returns an error message on error.
seen_file_icons: Bit flags used to track if any pictures of type 1 or type 2
have already been added, to ensure only one is allowed.
Return: A Base64-encoded string suitable for use in a METADATA_BLOCK_PICTURE
tag.*/
char *_ope_parse_picture_specification(const char *filename, int picture_type, const char *description,
int *error, int *seen_file_icons){
static unsigned char *_ope_read_picture_file(const char *filename, const char *description, int *error, size_t *size, size_t *offset) {
FILE *picture_file;
opus_uint32 width;
opus_uint32 height;
opus_uint32 depth;
opus_uint32 colors;
unsigned char *buf;
const char *mime_type;
char *out;
size_t cbuf;
size_t nbuf;
size_t data_offset;
size_t data_length;
size_t b64_length;
*error = OPE_OK;
if (picture_type < 0) picture_type=3;
if (picture_type > 20) {
*error=OPE_INVALID_PICTURE;
return NULL;
}
if(picture_type>=1&&picture_type<=2&&(*seen_file_icons&picture_type)){
*error=OPE_INVALID_PICTURE;
return NULL;
}
unsigned char *buf;
if (description == NULL) description = "";
picture_file=_ope_fopen(filename,"rb");
/*Buffer size: 8 static 4-byte fields plus 2 dynamic fields, plus the
......@@ -269,8 +242,6 @@ char *_ope_parse_picture_specification(const char *filename, int picture_type, c
extract it from the file.*/
data_offset=32+strlen(description)+10;
buf=NULL;
{
int has_palette;
/*Complicated case: we have a real file.
Read it in, attempt to parse the media type and image dimensions if
necessary, and validate what the user passed in.*/
......@@ -314,6 +285,44 @@ char *_ope_parse_picture_specification(const char *filename, int picture_type, c
else if(cbuf>0x7FFFFFFFU)cbuf=0xFFFFFFFFU;
else cbuf=cbuf<<1|1;
}
*size = nbuf;
*offset = data_offset;
return buf;
}
/*Parse a picture SPECIFICATION as given on the command-line.
spec: The specification.
error_message: Returns an error message on error.
seen_file_icons: Bit flags used to track if any pictures of type 1 or type 2
have already been added, to ensure only one is allowed.
Return: A Base64-encoded string suitable for use in a METADATA_BLOCK_PICTURE
tag.*/
char *_ope_parse_picture_specification(const char *filename, int picture_type, const char *description,
int *error, int *seen_file_icons){
opus_uint32 width;
opus_uint32 height;
opus_uint32 depth;
opus_uint32 colors;
unsigned char *buf;
const char *mime_type;
char *out;
size_t nbuf;
size_t data_offset;
size_t data_length;
size_t b64_length;
int has_palette;
*error = OPE_OK;
if (picture_type < 0) picture_type=3;
if (picture_type > 20) {
*error=OPE_INVALID_PICTURE;
return NULL;
}
if(picture_type>=1&&picture_type<=2&&(*seen_file_icons&picture_type)){
*error=OPE_INVALID_PICTURE;
return NULL;
}
buf = _ope_read_picture_file(filename, description, error, &nbuf, &data_offset);
if (buf == NULL) return NULL;
data_length=nbuf-data_offset;
/*Try to extract the image dimensions/color information from the file.*/
width=height=depth=colors=0;
......@@ -340,7 +349,6 @@ char *_ope_parse_picture_specification(const char *filename, int picture_type, c
return NULL;
}
}
}
/*These fields MUST be set correctly OR all set to zero.
So if any of them (except colors, for which 0 is a valid value) are still
zero, clear the rest to zero.*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment