mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-10-07 01:23:26 +00:00
JPEG is not encoding the DPI
This commit is contained in:
parent
27272bc58e
commit
7306d272b8
@ -595,13 +595,19 @@ NSString* NSImageCompressionFactor = @"NSImageCompressionFactor";
|
||||
return nil;
|
||||
}
|
||||
|
||||
int dpi = 72;
|
||||
if (_size.width > 0) {
|
||||
dpi = ceilf(72 * _pixelsWide / _size.width);
|
||||
}
|
||||
NSMutableData *result=[NSMutableData data];
|
||||
// Convert the NS options to CG options - just NSImageCompressionFactor for now
|
||||
NSDictionary *CGProperties = nil;
|
||||
NSDictionary *CGProperties = [NSMutableDictionary dictionary];
|
||||
|
||||
[CGProperties setValue: [NSNumber numberWithInt: dpi] forKey: (id)kCGImageDestinationDPI];
|
||||
|
||||
if ([properties count]) {
|
||||
id compressionFactor = [properties valueForKey:NSImageCompressionFactor];
|
||||
if (compressionFactor) {
|
||||
CGProperties = [NSMutableDictionary dictionary];
|
||||
[CGProperties setValue:compressionFactor forKey:(id)kCGImageDestinationLossyCompressionQuality];
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ typedef struct O2ImageDestination *CGImageDestinationRef;
|
||||
|
||||
COREGRAPHICS_EXPORT const CFStringRef kCGImageDestinationLossyCompressionQuality;
|
||||
COREGRAPHICS_EXPORT const CFStringRef kCGImageDestinationBackgroundColor;
|
||||
COREGRAPHICS_EXPORT const CFStringRef kCGImageDestinationDPI;
|
||||
|
||||
COREGRAPHICS_EXPORT CFTypeID CGImageDestinationGetTypeID(void);
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
const CFStringRef kCGImageDestinationLossyCompressionQuality=(CFStringRef)@"kCGImageDestinationLossyCompressionQuality";
|
||||
const CFStringRef kCGImageDestinationBackgroundColor=(CFStringRef)@"kCGImageDestinationBackgroundColor";
|
||||
const CFStringRef kCGImageDestinationDPI=(CFStringRef)@"kCGImageDestinationDPI";
|
||||
|
||||
CFTypeID CGImageDestinationGetTypeID(void) {
|
||||
return O2ImageDestinationGetTypeID();
|
||||
|
@ -48,6 +48,15 @@ void O2JPGEncoderWriteImage(O2JPGEncoderRef self,O2ImageRef image,CFDictionaryRe
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
NSNumber *dpi = [properties objectForKey:(NSString *)kO2ImageDestinationDPI];
|
||||
if (dpi) {
|
||||
int dpiValue = [dpi intValue];
|
||||
cinfo.density_unit = 1; /* DPI */
|
||||
cinfo.X_density = dpiValue; /* Horizontal pixel density */
|
||||
cinfo.Y_density = dpiValue; /* Vertical pixel density */
|
||||
}
|
||||
|
||||
NSNumber *compression = [properties objectForKey:(NSString *)kO2ImageDestinationLossyCompressionQuality];
|
||||
if (compression) {
|
||||
jpeg_set_quality(&cinfo, 100*[compression floatValue], TRUE);
|
||||
|
@ -11,6 +11,7 @@ typedef O2ImageDestination *O2ImageDestinationRef;
|
||||
|
||||
extern const CFStringRef kO2ImageDestinationLossyCompressionQuality;
|
||||
extern const CFStringRef kO2ImageDestinationBackgroundColor;
|
||||
extern const CFStringRef kO2ImageDestinationDPI;
|
||||
|
||||
@interface O2ImageDestination : NSObject {
|
||||
@public
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
// Using the same value as CoreGraphics - that's removing the needs for conversion
|
||||
const CFStringRef kO2ImageDestinationLossyCompressionQuality = (const CFStringRef)@"kCGImageDestinationLossyCompressionQuality";
|
||||
const CFStringRef kO2ImageDestinationBackgroundColor = (const CFStringRef)@"kO2ImageDestinationBackgroundColor";
|
||||
const CFStringRef kO2ImageDestinationBackgroundColor = (const CFStringRef)@"kCGImageDestinationBackgroundColor";
|
||||
const CFStringRef kO2ImageDestinationDPI = (const CFStringRef)@"kCGImageDestinationDPI";
|
||||
|
||||
@interface _O2ImageDestination : O2ImageDestination
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user