Skip to content

Commit

Permalink
stop using PNGs for mousecape files since they ruin colorspace inform…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
alexzielenski committed Jun 13, 2020
1 parent d414d17 commit c946d78
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Mousecape/Mousecape/Mousecape-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1801</string>
<string>1811</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1801</string>
<string>1811</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 1 addition & 3 deletions Mousecape/Mousecape/src/models/MCCursor.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ - (BOOL)_readFromDictionary:(NSDictionary *)dictionary ofVersion:(CGFloat)versio
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:data];
rep.size = NSMakeSize(self.size.width, self.size.height * self.frameCount);

// PNGCodec ignores colorspace information. As an invariant to our cape files we make sure
// all images are converted to sRGB so we retag it beforehand
[self setRepresentation:rep.retaggedSRGBSpace forScale:cursorScaleForScale(rep.pixelsWide / pointsWide.doubleValue)];
}

Expand All @@ -131,7 +129,7 @@ - (NSDictionary *)dictionaryRepresentation {
NSMutableArray *pngs = [NSMutableArray array];
for (NSString *key in self.representations) {
NSBitmapImageRep *rep = self.representations[key];
pngs[pngs.count] = [rep.ensuredSRGBSpace representationUsingType:NSPNGFileType properties:@{}];
pngs[pngs.count] = [rep.ensuredSRGBSpace TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0];
}

drep[MCCursorDictionaryRepresentationsKey] = pngs;
Expand Down
14 changes: 4 additions & 10 deletions Mousecape/Mousecape/src/views/MMAnimatingImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)newScale from

// Tell OSX that our view can accept images to be dragged in
- (void)registerTypes {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSPasteboardTypePNG, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilenamesPboardType, nil]];
}

- (void)viewDidMoveToWindow {
Expand Down Expand Up @@ -277,21 +277,15 @@ - (void)mouseDown:(NSEvent *)event {
- (void)pasteboard:(NSPasteboard *)sender item:(NSPasteboardItem *)item provideDataForType:(NSString *)type {
if ([type compare: NSPasteboardTypeTIFF] == NSOrderedSame) {
[sender setData:[self.image TIFFRepresentation] forType:NSPasteboardTypeTIFF];
} else if ([type compare: NSPasteboardTypePNG] == NSOrderedSame) {
NSImageRep *rep =self.image.representations.lastObject;
if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
[sender setData:[(NSBitmapImageRep *)rep representationUsingType:NSPNGFileType properties:@{}] forType:NSPasteboardTypePNG];
} else {
// abort();
}
} else if ([type compare:@"public.image"] == NSOrderedSame) {
[sender writeObjects:@[ self.image ]];
} else if ([type compare:(__bridge NSString *)kPasteboardTypeFileURLPromise] == NSOrderedSame && SHOULDCOPY) {
NSURL *url = [[NSURL URLWithString:[item stringForType:@"com.apple.pastelocation"]] URLByAppendingPathComponent:[NSString stringWithFormat:@"Mousecape Image (%f).png", NSDate.date.timeIntervalSince1970]];
NSURL *url = [[NSURL URLWithString:[item stringForType:@"com.apple.pastelocation"]] URLByAppendingPathComponent:[NSString stringWithFormat:@"Mousecape Image (%f).tiff", NSDate.date.timeIntervalSince1970]];
NSImageRep *rep =self.image.representations.firstObject;

if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
[[(NSBitmapImageRep *)rep representationUsingType:NSPNGFileType properties:@{}] writeToFile:url.path atomically:NO];
NSBitmapImageRep* bitmap = (NSBitmapImageRep*)rep;
[[bitmap TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0] writeToFile:url.path atomically:NO];
} else {
abort();
}
Expand Down
2 changes: 1 addition & 1 deletion Mousecape/mousecloak/MCDefs.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void CGImageWriteToFile(CGImageRef image, CFStringRef path) {

NSData *pngDataForImage(id image) {
if ([image isKindOfClass:[NSBitmapImageRep class]]) {
return [(NSBitmapImageRep *)image representationUsingType:NSPNGFileType properties:@{}];
return [(NSBitmapImageRep *)image TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0];
}

// CGImage
Expand Down
4 changes: 2 additions & 2 deletions Mousecape/mousecloak/create.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

NSBitmapImageRep *image = [NSBitmapImageRep imageRepWithData:[NSData dataWithContentsOfFile:repPath]];
if (image) {
NSData *pngData = [image.ensuredSRGBSpace representationUsingType:NSPNGFileType properties:@{}];
NSData *pngData = [image.ensuredSRGBSpace TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0];
[representations addObject:pngData];
}

Expand Down Expand Up @@ -191,7 +191,7 @@
bytesPerRow:bpr.integerValue
bitsPerPixel:bpp.integerValue];

currentCursor[MCCursorDictionaryRepresentationsKey] = @[ [rep.ensuredSRGBSpace representationUsingType:NSPNGFileType properties:@{}] ];
currentCursor[MCCursorDictionaryRepresentationsKey] = @[ [rep.ensuredSRGBSpace TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0] ];
currentCursor[MCCursorDictionaryPointsWideKey] = wide;
currentCursor[MCCursorDictionaryPointsHighKey] = high;
currentCursor[MCCursorDictionaryHotSpotXKey] = hotX;
Expand Down

0 comments on commit c946d78

Please sign in to comment.