Move the image to data conversion to MP42Image
This commit is contained in:
2 files changed
+19
-23
No files matched your search
+13
-1
@@ -32,8 +32,10 @@ MP42_OBJC_DIRECT_MEMBERS
|
|||||||
|
|
||||||
- (instancetype)initWithImage:(NSImage *)image
|
- (instancetype)initWithImage:(NSImage *)image
|
||||||
{
|
{
|
||||||
if (self = [super init])
|
if (self = [super init]) {
|
||||||
_image = [image copy];
|
_image = [image copy];
|
||||||
|
_type = MP42_ART_PNG;
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -92,6 +94,11 @@ MP42_OBJC_DIRECT_MEMBERS
|
|||||||
} else if (_url) {
|
} else if (_url) {
|
||||||
NSError *outError = nil;
|
NSError *outError = nil;
|
||||||
_data = [NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&outError];
|
_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;
|
return _image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)debugDescription
|
||||||
|
{
|
||||||
|
return [NSString stringWithFormat:@"<%@: %p> type: %d", [self class], self, _type];
|
||||||
|
}
|
||||||
|
|
||||||
+ (BOOL)supportsSecureCoding
|
+ (BOOL)supportsSecureCoding
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
+6
-22
@@ -1102,36 +1102,20 @@
|
|||||||
|
|
||||||
NSArray<MP42MetadataItem *> *artworks = [self metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt];
|
NSArray<MP42MetadataItem *> *artworks = [self metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt];
|
||||||
for (uint32_t i = 0; i < artworks.count; i++) {
|
for (uint32_t i = 0; i < artworks.count; i++) {
|
||||||
MP42Image *artwork;
|
MP42Image *artwork = (MP42Image *)artworks[i].value;
|
||||||
MP4TagArtwork newArtwork;
|
|
||||||
|
|
||||||
artwork = (MP42Image *)artworks[i].value;
|
|
||||||
|
|
||||||
if (artwork.data && artwork.data.length < UINT32_MAX) {
|
if (artwork.data && artwork.data.length < UINT32_MAX) {
|
||||||
|
MP4TagArtwork newArtwork;
|
||||||
newArtwork.data = (void *)artwork.data.bytes;
|
newArtwork.data = (void *)artwork.data.bytes;
|
||||||
newArtwork.size = (uint32_t)artwork.data.length;
|
newArtwork.size = (uint32_t)artwork.data.length;
|
||||||
newArtwork.type = (MP4TagArtworkType)artwork.type;
|
newArtwork.type = (MP4TagArtworkType)artwork.type;
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSArray<NSImageRep *> *representations = artwork.image.representations;
|
|
||||||
|
|
||||||
if (representations.count) {
|
if (tags->artworkCount > i) {
|
||||||
NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:representations
|
MP4TagsSetArtwork(tags, i, &newArtwork);
|
||||||
usingType:NSBitmapImageFileTypePNG properties:@{}];
|
} else {
|
||||||
|
MP4TagsAddArtwork(tags, &newArtwork);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user