Skip to content

Instantly share code, notes, and snippets.

@ravron
Created April 8, 2017 07:01
Show Gist options
  • Save ravron/7fcf1dbaa5f628a402f114a961170fc3 to your computer and use it in GitHub Desktop.
Save ravron/7fcf1dbaa5f628a402f114a961170fc3 to your computer and use it in GitHub Desktop.
kCGImagePropertyRawDictionary
#import <Foundation/Foundation.h>
#import <ImageIO/ImageIO.h>
CGImageSourceRef createSourceFromPath(NSString *path) {
NSFileManager *f = [[NSFileManager alloc] init];
NSString *inImagePath = [NSString pathWithComponents:@[f.currentDirectoryPath, path]];
CGDataProviderRef provider = CGDataProviderCreateWithFilename([inImagePath cStringUsingEncoding:NSUTF8StringEncoding]);
CGImageSourceRef src = CGImageSourceCreateWithDataProvider(provider, NULL);
CGDataProviderRelease(provider);
return src;
}
void showImageStuff(CGImageSourceRef source) {
CFStringRef sourceUTI = CGImageSourceGetType(source);
CFDictionaryRef sourceProps = CGImageSourceCopyProperties(source, NULL);
CFDictionaryRef imgProps = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
CFShow(sourceUTI);
CFShow(sourceProps);
CFShow(imgProps);
CFRelease(sourceProps);
CFRelease(imgProps);
}
CFDictionaryRef CreateInsaneExifDict();
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSFileManager *f = [[NSFileManager alloc] init];
NSString *outImagePath = [NSString pathWithComponents:@[f.currentDirectoryPath, @"out_img.jpg"]];
CGImageSourceRef source = createSourceFromPath(@"img.jpg");
showImageStuff(source);
size_t numImages = CGImageSourceGetCount(source);
CGImageRef image = CGImageSourceCreateImageAtIndex(source, 0, NULL);
CFMutableDataRef outData = CFDataCreateMutable(NULL, 0);
CGImageDestinationRef dest = CGImageDestinationCreateWithData(outData, CGImageSourceGetType(source), numImages, NULL);
CFStringRef keys[3];
CFTypeRef vals[3];
keys[0] = kCGImagePropertyRawDictionary;
vals[0] = CreateInsaneExifDict();
CFDictionaryRef newProps = CFDictionaryCreate(NULL, (const void **)keys, (const void **)vals, 1, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CGImageDestinationAddImage(dest, image, newProps);
CGImageDestinationFinalize(dest);
CFRelease(dest);
NSMutableData *nsData = CFBridgingRelease(outData);
[nsData writeToFile:outImagePath atomically:NO];
CGImageRelease(image);
CFRelease(source);
CGImageSourceRef outSource = createSourceFromPath(@"out_img.jpg");
showImageStuff(outSource);
CFRelease(outSource);
}
return 0;
}
CFDictionaryRef CreateInsaneExifDict() {
CFStringRef keys[] = {
CFSTR("{Raw}"),
CFSTR("{CIFF}"),
CFSTR("{MakerCanon}"),
CFSTR("{MakerNikon}"),
CFSTR("{MakerMinolta}"),
CFSTR("{MakerFuji}"),
CFSTR("{MakerOlympus}"),
CFSTR("{MakerPentax}"),
CFSTR("{8BIM}"),
CFSTR("{DNG}"),
CFSTR("{ExifAux}"),
CFSTR("{MakerApple}"),
CFSTR("{EXR}"),
CFSTR("FileSize"),
CFSTR("DPIHeight"),
CFSTR("DPIWidth"),
CFSTR("PixelHeight"),
CFSTR("PixelWidth"),
CFSTR("Depth"),
CFSTR("SamplesPerPixel"),
CFSTR("BitsPerPixel"),
CFSTR("IsFloat"),
CFSTR("IsIndexed"),
CFSTR("HasAlpha"),
CFSTR("ColorModel"),
CFSTR("ProfileName"),
CFSTR("Gray"),
CFSTR("CMYK"),
CFSTR("DocumentName"),
CFSTR("DateTime"),
CFSTR("Artist"),
CFSTR("HostComputer"),
CFSTR("JFIFVersion"),
CFSTR("XDensity"),
CFSTR("YDensity"),
CFSTR("DensityUnit"),
CFSTR("IsProgressive"),
CFSTR("SensitivityType"),
CFSTR("StandardOutputSensitivity"),
CFSTR("RecommendedExposureIndex"),
CFSTR("ISOSpeed"),
CFSTR("ISOSpeedLatitudeyyy"),
CFSTR("ISOSpeedLatitudezzz"),
CFSTR("CameraOwnerName"),
CFSTR("BodySerialNumber"),
CFSTR("LensSpecification"),
CFSTR("LensMake"),
CFSTR("LensModel"),
CFSTR("WidthAppliedTo"),
CFSTR("HeightAppliedTo"),
CFSTR("RegionList"),
CFSTR("Width"),
CFSTR("Height"),
CFSTR("Name"),
CFSTR("Type"),
CFSTR("Face"),
CFSTR("Focus"),
CFSTR("BarCode"),
CFSTR("Timestamp"),
CFSTR("AngleInfoYaw"),
CFSTR("AngleInfoRoll"),
CFSTR("ConfidenceLevel"),
CFSTR("FaceID"),
CFSTR("Quantization"),
CFSTR("ChromaSubsamplingX"),
CFSTR("ChromaSubsamplingY"),
CFSTR("LoopCount"),
CFSTR("DelayTime"),
CFSTR("ImageColorMap"),
CFSTR("HasGlobalColorMap"),
CFSTR("UnclampedDelayTime"),
CFSTR("InterlaceType"),
CFSTR("XPixelsPerMeter"),
CFSTR("YPixelsPerMeter"),
CFSTR("sRGBIntent"),
CFSTR("Chromaticities"),
CFSTR("Creation Time"),
CFSTR("GPSVersion"),
CFSTR("LatitudeRef"),
CFSTR("Latitude"),
CFSTR("LongitudeRef"),
CFSTR("Longitude"),
CFSTR("AltitudeRef"),
CFSTR("Altitude"),
CFSTR("TimeStamp"),
CFSTR("Satellites"),
CFSTR("Status"),
CFSTR("MeasureMode"),
CFSTR("SpeedRef"),
CFSTR("Speed"),
CFSTR("TrackRef"),
CFSTR("Track"),
CFSTR("ImgDirectionRef"),
CFSTR("ImgDirection"),
CFSTR("MapDatum"),
CFSTR("DestLatitudeRef"),
CFSTR("DestLatitude"),
CFSTR("DestLongitudeRef"),
CFSTR("DestLongitude"),
CFSTR("DestBearingRef"),
CFSTR("DestBearing"),
CFSTR("DestDistanceRef"),
CFSTR("DestDistance"),
CFSTR("ProcessingMethod"),
CFSTR("AreaInformation"),
CFSTR("DateStamp"),
CFSTR("Differential"),
CFSTR("HPositioningError"),
CFSTR("ObjectTypeReference"),
CFSTR("ObjectAttributeReference"),
CFSTR("ObjectName"),
CFSTR("EditStatus"),
CFSTR("EditorialUpdate"),
CFSTR("SubjectReference"),
CFSTR("SupplementalCategory"),
CFSTR("FixtureIdentifier"),
CFSTR("Keywords"),
CFSTR("ContentLocationCode"),
CFSTR("ContentLocationName"),
CFSTR("ReleaseDate"),
CFSTR("ReleaseTime"),
CFSTR("ExpirationDate"),
CFSTR("ExpirationTime"),
CFSTR("SpecialInstructions"),
CFSTR("ActionAdvised"),
CFSTR("ReferenceService"),
CFSTR("ReferenceDate"),
CFSTR("ReferenceNumber"),
CFSTR("TimeCreated"),
CFSTR("DigitalCreationDate"),
CFSTR("DigitalCreationTime"),
CFSTR("OriginatingProgram"),
CFSTR("ProgramVersion"),
CFSTR("ObjectCycle"),
CFSTR("Byline"),
CFSTR("BylineTitle"),
CFSTR("SubLocation"),
CFSTR("Province/State"),
CFSTR("Country/PrimaryLocationCode"),
CFSTR("Country/PrimaryLocationName"),
CFSTR("OriginalTransmissionReference"),
CFSTR("CopyrightNotice"),
CFSTR("Caption/Abstract"),
CFSTR("Writer/Editor"),
CFSTR("ImageType"),
CFSTR("ImageOrientation"),
CFSTR("LanguageIdentifier"),
CFSTR("StarRating"),
CFSTR("CiAdrCity"),
CFSTR("CiAdrCtry"),
CFSTR("CiAdrExtadr"),
CFSTR("CiAdrPcode"),
CFSTR("CiAdrRegion"),
CFSTR("CiEmailWork"),
CFSTR("CiTelWork"),
CFSTR("CiUrlWork"),
CFSTR("LayerNames"),
CFSTR("Version"),
CFSTR("DNGVersion"),
CFSTR("DNGBackwardVersion"),
CFSTR("UniqueCameraModel"),
CFSTR("LocalizedCameraModel"),
CFSTR("CameraSerialNumber"),
CFSTR("BlackLevel"),
CFSTR("WhiteLevel"),
CFSTR("CalibrationIlluminant1"),
CFSTR("CalibrationIlluminant2"),
CFSTR("ColorMatrix1"),
CFSTR("ColorMatrix2"),
CFSTR("CameraCalibration1"),
CFSTR("CameraCalibration2"),
CFSTR("AsShotNeutral"),
CFSTR("AsShotWhiteXY"),
CFSTR("BaselineExposure"),
CFSTR("BaselineNoise"),
CFSTR("BaselineSharpness"),
CFSTR("DNGPrivateData"),
CFSTR("CameraCalibrationSignature"),
CFSTR("ProfileCalibrationSignature"),
CFSTR("NoiseProfile"),
CFSTR("WarpRectilinear"),
CFSTR("WarpFisheye"),
CFSTR("FixVignetteRadial"),
CFSTR("ImageName"),
CFSTR("ImageFileName"),
CFSTR("ReleaseMethod"),
CFSTR("ReleaseTiming"),
CFSTR("RecordID"),
CFSTR("SelfTimingTime"),
CFSTR("ImageSerialNumber"),
CFSTR("ContinuousDrive"),
CFSTR("FocusMode"),
CFSTR("ShootingMode"),
CFSTR("LensMaxMM"),
CFSTR("LensMinMM"),
CFSTR("WhiteBalanceIndex"),
CFSTR("FlashExposureComp"),
CFSTR("MeasuredEV"),
CFSTR("ISOSetting"),
CFSTR("ColorMode"),
CFSTR("Quality"),
CFSTR("WhiteBalanceMode"),
CFSTR("SharpenMode"),
CFSTR("FlashSetting"),
CFSTR("ISOSelection"),
CFSTR("ImageAdjustment"),
CFSTR("LensAdapter"),
CFSTR("LensType"),
CFSTR("FocusDistance"),
CFSTR("DigitalZoom"),
CFSTR("ShutterCount"),
CFSTR("AspectRatioInfo"),
CFSTR("ThumbnailOffset"),
CFSTR("ThumbnailSize"),
CFSTR("ThumbnailWidth"),
CFSTR("ThumbnailHeight"),
CFSTR("AspectRatio"),
};
size_t numEntries = sizeof(keys) / sizeof(keys[0]);
CFStringRef vals[numEntries];
for (NSInteger i = 0; i < numEntries; i++) {
vals[i] = CFSTR("TESTVALUE");
}
return CFDictionaryCreate(NULL, (const void **)keys, (const void **)vals, numEntries, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment