facebookincubator/spectrum

Can not compress the picture properly, there is purple phenomenon

chenzhibo opened this issue · 6 comments

Hello,
when i encode one jpeg 64*48, i Can not compress the picture properly, there is purple phenomenon。
574582621 587397
574582625 446061
574582626 228842

        [[PHImageManager defaultManager] requestImageDataForAsset:asset options:requestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
            
            FSPEncodeRequirement *encodeRequirement =
            [FSPEncodeRequirement encodeRequirementWithFormat:FSPEncodedImageFormat.jpeg];
            FSPEncodeOptions *options =
            [FSPEncodeOptions encodeOptionsWithEncodeRequirement:encodeRequirement];
            
            FSPResult *data = [[FSPSpectrum sharedInstance] encodeImage:imageData toFileAtURL:[NSURL fileURLWithPath:path]  options:options error:&error];

Hi @chenzhibo , thanks for opening the issue. Can you share the image that you as input for requestImageDataForAsset? That will help us reproducing the issue :)

PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = YES;
targetSize = CGSizeMake(64, 64);
requestOptions.networkAccessAllowed = YES;
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:targetSize contentMode:contentMode options:requestOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {

FSPEncodeRequirement *encodeRequirement =
[FSPEncodeRequirement encodeRequirementWithFormat:FSPEncodedImageFormat.jpeg];
FSPEncodeOptions *options =
[FSPEncodeOptions encodeOptionsWithEncodeRequirement:encodeRequirement];

        FSPResult *data = [[FSPSpectrum sharedInstance] encodeImage:imageData toFileAtURL:[NSURL fileURLWithPath:path]  options:options error:&error];
cuva commented

Hi @chenzhibo

Could you confirm on which platform this happens? Was it on a device or simulator? If a device, which one?

Many thanks!

Hi @chenzhibo,

I debugged this problem and found that these small images are encoded with kCGImagePixelFormatRGB555.

Unfortunately, Spectrum doesn't support this kind of format for now. I made some changes in 15fb5fd to detect this case and make sure we return an error.

Feel free to open a new issue to add support for kCGImagePixelFormatRGB555.