Move the image to data conversion to MP42Image

This commit is contained in:
Damiano Galassi committed 2024-07-18 11:26:52 +02:00
1 parent d2d3365d92
commit a83c7e8e79
2 files changed
+20 -24

No files matched your search

+14 -2
View File
@@ -32,9 +32,11 @@ MP42_OBJC_DIRECT_MEMBERS
- (instancetype)initWithImage:(NSImage *)image
{
if (self = [super init])
if (self = [super init]) {
_image = [image copy];
_type = MP42_ART_PNG;
}
return self;
}
@@ -92,6 +94,11 @@ MP42_OBJC_DIRECT_MEMBERS
} else if (_url) {
NSError *outError = nil;
_data = [NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError];
} else if (_image) {
NSArray<NSImageRep *> *representations = _image.representations;
if (representations.count) {
_data = [NSBitmapImageRep representationOfImageRepsInArray:representations usingType:NSBitmapImageFileTypePNG properties:@{}];
}
}
}
@@ -111,6 +118,11 @@ MP42_OBJC_DIRECT_MEMBERS
return _image;
}
- (NSString *)debugDescription
{
return [NSString stringWithFormat:@"<%@: %p> type: %d", [self class], self, _type];
}
+ (BOOL)supportsSecureCoding
{
return YES;
+6 -22
View File
@@ -1102,36 +1102,20 @@
NSArray<MP42MetadataItem *> *artworks = [self metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt];
for (uint32_t i = 0; i < artworks.count; i++) {
MP42Image *artwork;
MP4TagArtwork newArtwork;
artwork = (MP42Image *)artworks[i].value;
MP42Image *artwork = (MP42Image *)artworks[i].value;
if (artwork.data && artwork.data.length < UINT32_MAX) {
MP4TagArtwork newArtwork;
newArtwork.data = (void *)artwork.data.bytes;
newArtwork.size = (uint32_t)artwork.data.length;
newArtwork.type = (MP4TagArtworkType)artwork.type;
}
else {
NSArray<NSImageRep *> *representations = artwork.image.representations;
if (representations.count) {
NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:representations
usingType:NSBitmapImageFileTypePNG properties:@{}];
if (bitmapData && bitmapData.length < UINT32_MAX) {
newArtwork.data = (void *)bitmapData.bytes;
newArtwork.size = (uint32_t)bitmapData.length;
newArtwork.type = MP4_ART_PNG;
}
if (tags->artworkCount > i) {
MP4TagsSetArtwork(tags, i, &newArtwork);
} else {
MP4TagsAddArtwork(tags, &newArtwork);
}
}
if (tags->artworkCount > i) {
MP4TagsSetArtwork(tags, i, &newArtwork);
} else {
MP4TagsAddArtwork(tags, &newArtwork);
}
}
}