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;
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);
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().
/* \} */
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. */
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) */
* \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
* 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);
/* \} */
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());
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());
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);
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;
}
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;
}
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 */
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;
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)
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;
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;
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);
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;
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)
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;
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;
*/
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);
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)))
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 */
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))
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)
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
;
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;
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_()) */
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_()) */
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
;
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;
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) {
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");
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
;
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;
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_()) */
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) {
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;
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
;
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;