Commit 74ed2947 authored by Josh Coalson's avatar Josh Coalson

add number-of-colors field to PICTURE metadata block

parent e343ab2b
......@@ -837,6 +837,7 @@ namespace FLAC {
FLAC__uint32 get_width() const;
FLAC__uint32 get_height() const;
FLAC__uint32 get_depth() const;
FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
FLAC__uint32 get_data_length() const;
const FLAC__byte *get_data() const;
......@@ -851,6 +852,7 @@ namespace FLAC {
void set_width(FLAC__uint32 value) const;
void set_height(FLAC__uint32 value) const;
void set_depth(FLAC__uint32 value) const;
void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
//! See FLAC__metadata_object_picture_set_data()
bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
......@@ -937,8 +939,8 @@ namespace FLAC {
FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); //! See FLAC__metadata_get_cuesheet().
FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); //! See FLAC__metadata_get_cuesheet().
FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth); //! See FLAC__metadata_get_picture().
FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth); //! See FLAC__metadata_get_picture().
FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors); //! See FLAC__metadata_get_picture().
FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors); //! See FLAC__metadata_get_picture().
/* \} */
......
......@@ -767,6 +767,11 @@ typedef struct {
FLAC__uint32 depth;
/**< Picture's color depth in bits-per-pixel. */
FLAC__uint32 colors;
/**< For indexed palettes (like GIF), picture's number of colors (the
* number of palette entries), or \c 0 for non-indexed (i.e. 2^depth).
*/
FLAC__uint32 data_length;
/**< Length of binary picture data in bytes. */
......@@ -781,6 +786,7 @@ extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
......
......@@ -216,6 +216,8 @@ FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__Stre
* \c (unsigned)(-1) to mean "any height".
* \param max_depth The maximum color depth in bits-per-pixel desired.
* Use \c (unsigned)(-1) to mean "any depth".
* \param max_colors The maximum number of colors desired. Use
* \c (unsigned)(-1) to mean "any number of colors".
* \assert
* \code filename != NULL \endcode
* \code picture != NULL \endcode
......@@ -226,7 +228,7 @@ FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__Stre
* error, a file decoder error, or the file contained no PICTURE
* block, and \a *picture will be set to \c NULL.
*/
FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth);
FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors);
/* \} */
......
......@@ -1067,6 +1067,12 @@ namespace FLAC {
return object_->data.picture.depth;
}
FLAC__uint32 Picture::get_colors() const
{
FLAC__ASSERT(is_valid());
return object_->data.picture.colors;
}
FLAC__uint32 Picture::get_data_length() const
{
FLAC__ASSERT(is_valid());
......@@ -1117,6 +1123,12 @@ namespace FLAC {
object_->data.picture.depth = value;
}
void Picture::set_colors(FLAC__uint32 value) const
{
FLAC__ASSERT(is_valid());
object_->data.picture.colors = value;
}
bool Picture::set_data(const FLAC__byte *data, FLAC__uint32 data_length)
{
FLAC__ASSERT(is_valid());
......@@ -1235,7 +1247,7 @@ namespace FLAC {
return false;
}
FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth)
FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
{
FLAC__ASSERT(0 != filename);
......@@ -1243,7 +1255,7 @@ namespace FLAC {
picture = 0;
if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth)) {
if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth, max_colors)) {
picture = new Picture(object, /*copy=*/false);
return true;
}
......@@ -1251,13 +1263,13 @@ namespace FLAC {
return false;
}
FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth)
FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
{
FLAC__ASSERT(0 != filename);
::FLAC__StreamMetadata *object;
if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth)) {
if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth, max_colors)) {
picture.assign(object, /*copy=*/false);
return true;
}
......
......@@ -110,6 +110,7 @@ FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 3
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
......
......@@ -276,7 +276,7 @@ void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErro
cd->got_error = true;
}
FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth)
FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
{
FLAC__Metadata_SimpleIterator *it;
FLAC__uint64 max_area_seen = 0;
......@@ -306,6 +306,7 @@ FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__Strea
obj->data.picture.width <= max_width &&
obj->data.picture.height <= max_height &&
obj->data.picture.depth <= max_depth &&
obj->data.picture.colors <= max_colors &&
(area > max_area_seen || (area == max_area_seen && obj->data.picture.depth > max_depth_seen))
) {
if(*picture)
......@@ -2210,6 +2211,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__I
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_TYPE_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN / 8;
......@@ -2241,6 +2243,12 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__I
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->depth = unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_COLORS_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->colors = unpack_uint32_(buffer, len);
/* for convenience we use read_metadata_block_data_picture_cstring_cb_() even though it adds an extra terminating NUL we don't use */
if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->data), &(block->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK)
return status;
......@@ -2547,6 +2555,7 @@ FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IO
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_COLORS_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN%8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8);
......@@ -2554,6 +2563,7 @@ FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IO
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8);
len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8;
......@@ -2592,6 +2602,11 @@ FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IO
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8;
pack_uint32_(block->colors, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8;
pack_uint32_(block->data_length, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
......
......@@ -481,6 +481,7 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN +
0 /* no data */
) / 8;
......@@ -491,6 +492,7 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type
object->data.picture.width = 0;
object->data.picture.height = 0;
object->data.picture.depth = 0;
object->data.picture.colors = 0;
object->data.picture.data_length = 0;
object->data.picture.data = 0;
*/
......@@ -598,6 +600,7 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMet
to->data.picture.width = object->data.picture.width;
to->data.picture.height = object->data.picture.height;
to->data.picture.depth = object->data.picture.depth;
to->data.picture.colors = object->data.picture.colors;
to->data.picture.data_length = object->data.picture.data_length;
if(!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) {
FLAC__metadata_object_delete(to);
......@@ -834,6 +837,8 @@ static FLAC__bool compare_block_data_picture_(const FLAC__StreamMetadata_Picture
return false;
if(block1->depth != block2->depth)
return false;
if(block1->colors != block2->colors)
return false;
if(block1->data_length != block2->data_length)
return false;
if(block1->data != block2->data && (0 == block1->data || 0 == block2->data || memcmp(block1->data, block2->data, block1->data_length)))
......
......@@ -1677,6 +1677,10 @@ FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN, read_callback_, decoder))
return false; /* read_callback_ sets the state for us */
/* read colors */
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN, read_callback_, decoder))
return false; /* read_callback_ sets the state for us */
/* read data */
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN, read_callback_, decoder))
return false; /* read_callback_ sets the state for us */
......
......@@ -198,6 +198,8 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
return false;
if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
return false;
if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
return false;
if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
return false;
if(!FLAC__bitbuffer_write_byte_block(bb, metadata->data.picture.data, metadata->data.picture.data_length))
......
......@@ -653,6 +653,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
PPR; printf(" width: %u\n", (unsigned)block->data.picture.width);
PPR; printf(" height: %u\n", (unsigned)block->data.picture.height);
PPR; printf(" depth: %u\n", (unsigned)block->data.picture.depth);
PPR; printf(" colors: %u%s\n", (unsigned)block->data.picture.colors, block->data.picture.colors? "" : " (unindexed)");
PPR; printf(" data length: %u\n", (unsigned)block->data.picture.data_length);
PPR; printf(" data:\n");
if(0 != block->data.picture.data)
......
......@@ -545,6 +545,7 @@ static bool generate_file_(FLAC__bool include_extras)
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
) / 8
;
......@@ -556,6 +557,7 @@ static bool generate_file_(FLAC__bool include_extras)
picture.data.picture.width = 300;
picture.data.picture.height = 300;
picture.data.picture.depth = 24;
picture.data.picture.colors = 0;
picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
picture.data.picture.data_length = strlen((const char *)picture.data.picture.data);
picture.length += picture.data.picture.data_length;
......@@ -751,7 +753,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture *picture = 0;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -768,7 +770,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture picture;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......
......@@ -207,6 +207,7 @@ static void init_metadata_blocks_()
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
) / 8
;
......@@ -218,6 +219,7 @@ static void init_metadata_blocks_()
picture_.data.picture.width = 300;
picture_.data.picture.height = 300;
picture_.data.picture.depth = 24;
picture_.data.picture.colors = 0;
picture_.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
picture_.data.picture.data_length = strlen((const char *)picture_.data.picture.data);
picture_.length += picture_.data.picture.data_length;
......@@ -1814,6 +1816,7 @@ bool test_metadata_object_picture()
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
) / 8;
if(block.get_length() != expected_length) {
......@@ -2009,6 +2012,18 @@ bool test_metadata_object_picture()
return die_("value mismatch, expected 16");
printf("OK\n");
printf("testing Picture::get_colors()... ");
if(block.get_colors() != 0)
return die_("value mismatch, expected 0");
printf("OK\n");
printf("testing Picture::set_colors()... +\n");
printf(" Picture::get_colors()... ");
block.set_colors(1u>16);
if(block.get_colors() != 1u>16)
return die_("value mismatch, expected 2^16");
printf("OK\n");
printf("testing Picture::get_data_length()... ");
if(block.get_data_length() != 0)
return die_("value mismatch, expected 0");
......
......@@ -556,6 +556,7 @@ static FLAC__bool generate_file_(FLAC__bool include_extras)
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
) / 8
;
......@@ -567,6 +568,7 @@ static FLAC__bool generate_file_(FLAC__bool include_extras)
picture.data.picture.width = 300;
picture.data.picture.height = 300;
picture.data.picture.depth = 24;
picture.data.picture.colors = 0;
picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
picture.data.picture.data_length = strlen((const char *)picture.data.picture.data);
picture.length += picture.data.picture.data_length;
......@@ -724,7 +726,7 @@ static FLAC__bool test_level_0_()
printf("testing FLAC__metadata_get_picture()... ");
if(!FLAC__metadata_get_picture(flacfile_, &picture, /*type=*/(FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1)))
if(!FLAC__metadata_get_picture(flacfile_, &picture, /*type=*/(FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC__metadata_get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......
......@@ -2044,6 +2044,7 @@ FLAC__bool test_metadata_object()
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
) / 8;
if(block->length != expected_length) {
......
......@@ -328,6 +328,10 @@ FLAC__bool mutils__compare_block_data_picture(const FLAC__StreamMetadata_Picture
printf("FAILED, depth mismatch, expected %u, got %u\n", block->depth, blockcopy->depth);
return false;
}
if(blockcopy->colors != block->colors) {
printf("FAILED, colors mismatch, expected %u, got %u\n", block->colors, blockcopy->colors);
return false;
}
if(blockcopy->data_length != block->data_length) {
printf("FAILED, data_length mismatch, expected %u, got %u\n", block->data_length, blockcopy->data_length);
return false;
......@@ -577,6 +581,7 @@ void mutils__init_metadata_blocks(
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
) / 8
;
......@@ -588,6 +593,7 @@ void mutils__init_metadata_blocks(
picture->data.picture.width = 300;
picture->data.picture.height = 300;
picture->data.picture.depth = 24;
picture->data.picture.colors = 0;
picture->data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
picture->data.picture.data_length = strlen((const char *)picture->data.picture.data);
picture->length += picture->data.picture.data_length;
......
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