guoyingtao / Mantis

An iOS Image cropping library, which mimics the Photo App written in Swift.
MIT License
900 stars 180 forks source link

Unsupported image causes assertionFailure while cropping #313

Closed trapi closed 1 year ago

trapi commented 1 year ago

Hey,

While trying to crop the attached image I get the following error:

CGBitmapContextCreate: unsupported parameter combination:
    RGB 
    8 bits/component, integer
    4928 bytes/row
    kCGImageAlphaNone
    kCGImageByteOrderDefault
    kCGImagePixelFormatPacked
    Valid parameters for RGB color space model are:
    16  bits per pixel,      5  bits per component,      kCGImageAlphaNoneSkipFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaNoneSkipFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaNoneSkipLast
    32  bits per pixel,      8  bits per component,      kCGImageAlphaPremultipliedFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaPremultipliedLast
    32  bits per pixel,      10 bits per component,      kCGImageAlphaNone|kCGImagePixelFormatRGBCIF10|kCGImageByteOrder16Little
    64  bits per pixel,      16 bits per component,      kCGImageAlphaPremultipliedLast
    64  bits per pixel,      16 bits per component,      kCGImageAlphaNoneSkipLast
    64  bits per pixel,      16 bits per component,      kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little
    64  bits per pixel,      16 bits per component,      kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little
    128 bits per pixel,      32 bits per component,      kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
    128 bits per pixel,      32 bits per component,      kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.
*** Failed to get transfromed image ***
Failed reason: failedToBuildContext(colorSpaceModel: __C.CGColorSpaceModel, bitsPerPixel: 8, bitsPerComponent: 8)
Mantis/CropView.swift:642: Fatal error: croppedImage should not be nil
2023-06-16 16:46:46.331891+0200 TimiiCompanionApp[22355:5438923] Mantis/CropView.swift:642: Fatal error: croppedImage should not be nil

243197060-b84ef5ee-3d84-4494-bd16-48958004631f

guoyingtao commented 1 year ago

@trapi How did you generate this image? Based on the debug information, it is 8 bits per pixel, 8 bits per component, which seems an very unfamiliar image format to me.

guoyingtao commented 1 year ago

Looks like the image is "Indexed Color Image" or "Palette-based Image". I will fix it later but the output image will be RGBA format which is different with original one.

guoyingtao commented 1 year ago

@trapi I released Mantis 2.11.0 which should fix this issue. Can you have a try to see if it works for you?

trapi commented 1 year ago

@guoyingtao It works and fixes the issue. Thanks a lot!