{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/comments/60635651","id":60635651,"diff_hunk":"@@ -15,11 +16,867 @@\n //******************************************************************************\n \n #import <ImageIO/CGImageDestination.h>\n+#import <ImageIO/CGImageDestinationInternal.h>\n #import <StubReturn.h>\n+#include <windows.h>\n+#include <string>\n \n+static const wchar_t* TAG = L\"CGImageDestination\"; \n const CFStringRef kCGImageDestinationLossyCompressionQuality = static_cast<CFStringRef>(@\"kCGImageDestinationLossyCompressionQuality\");\n const CFStringRef kCGImageDestinationBackgroundColor = static_cast<CFStringRef>(@\"kCGImageDestinationBackgroundColor\");\n \n+const CFStringRef kUTTypeJPEG = static_cast<const CFStringRef>(@\"public.jpeg\");\n+const CFStringRef kUTTypeTIFF = static_cast<const CFStringRef>(@\"public.tiff\");\n+const CFStringRef kUTTypeGIF = static_cast<const CFStringRef>(@\"com.compuserve.gif\");\n+const CFStringRef kUTTypePNG = static_cast<const CFStringRef>(@\"public.png\");\n+const CFStringRef kUTTypeBMP = static_cast<const CFStringRef>(@\"com.microsoft.bmp\");\n+\n+const unsigned int c_minutesPerDegree = 60;\n+const unsigned int c_secondsPerMinute = 60;\n+\n+enum imageTypes { typeJPEG,\n+                  typeTIFF,\n+                  typeGIF,\n+                  typePNG,\n+                  typeBMP,\n+                  typeUnknown };\n+\n+enum destinationTypes { toData,\n+                        toURL,\n+                        toConsumer };\n+\n+@implementation ImageDestination\n+\n+- (instancetype)initToDestination:(size_t)frames\n+                             type:(CFStringRef)type\n+                             data:(CFMutableDataRef)data\n+                              url:(CFURLRef)url {\n+    if (self = [super init]) {\n+        RETURN_NULL_IF(url && ![(NSURL*)url isFileURL]);\n+        RETURN_NULL_IF(!data && !url);\n+\n+        self.maxCount = frames;\n+\n+        MULTI_QI imageQueryInterface = {0};\n+        static const GUID IID_IWICImagingFactory = {0xec5ec8a9,0xc395,0x4314,0x9c,0x77,0x54,0xd7,0xa9,0x35,0xff,0x70};\n+        imageQueryInterface.pIID = &IID_IWICImagingFactory;\n+        RETURN_NULL_IF_FAILED(\n+            CoCreateInstanceFromApp(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, nullptr, 1, &imageQueryInterface));\n+        \n+        _idFactory = (IWICImagingFactory*)imageQueryInterface.pItf;\n+        RETURN_NULL_IF_FAILED(_idFactory->CreateStream(&_idStream));\n+\n+        if (CFStringCompare(type, kUTTypeJPEG, NULL) == kCFCompareEqualTo) {\n+            _type = typeJPEG;\n+            RETURN_NULL_IF_FAILED(_idFactory->CreateEncoder(GUID_ContainerFormatJpeg, NULL, &_idEncoder));\n+        } else if (CFStringCompare(type, kUTTypeTIFF, NULL) == kCFCompareEqualTo) {\n+            _type = typeTIFF;\n+            RETURN_NULL_IF_FAILED(_idFactory->CreateEncoder(GUID_ContainerFormatTiff, NULL, &_idEncoder));\n+        } else if (CFStringCompare(type, kUTTypeGIF, NULL) == kCFCompareEqualTo) {\n+            _type = typeGIF;\n+            RETURN_NULL_IF_FAILED(_idFactory->CreateEncoder(GUID_ContainerFormatGif, NULL, &_idEncoder));\n+        } else if (CFStringCompare(type, kUTTypePNG, NULL) == kCFCompareEqualTo) {\n+            _type = typePNG;\n+            RETURN_NULL_IF_FAILED(_idFactory->CreateEncoder(GUID_ContainerFormatPng, NULL, &_idEncoder));\n+        } else if (CFStringCompare(type, kUTTypeBMP, NULL) == kCFCompareEqualTo) {\n+            _type = typeBMP;\n+            RETURN_NULL_IF_FAILED(_idFactory->CreateEncoder(GUID_ContainerFormatBmp, NULL, &_idEncoder));\n+        } else {\n+            _type = typeUnknown;\n+            return NULL;\n+        }\n+\n+        if (url && [(NSURL*)url path]) { // Make sure that the url path actually resolves to something to avoid causing an exception\n+            NSString* urlNSString = [[(NSURL*)url path] substringFromIndex:1];\n+            NSData* urlAsData = [urlNSString dataUsingEncoding:NSUnicodeStringEncoding];\n+            std::wstring wideUrl((wchar_t*)[urlAsData bytes], [urlAsData length]/sizeof(wchar_t));\n+            RETURN_NULL_IF_FAILED(_idStream->InitializeFromFilename(wideUrl.c_str(), GENERIC_WRITE));\n+\n+            if (![(NSURL*)url checkResourceIsReachableAndReturnError:NULL]) {\n+                return NULL;\n+            }\n+        } else if (data) {\n+            _outData = data;\n+\n+            IStream* dataStream;\n+            CreateStreamOnHGlobal(NULL, true, &dataStream);","path":"Frameworks/ImageIO/CGImageDestination.mm","position":null,"original_position":94,"commit_id":"60b0a42f180f8eafd0af56b3f0524b15c3499144","original_commit_id":"e5831561c2d52c89fd0fcc09892904f1ba6139ce","user":{"login":"yweijiang","id":16156441,"avatar_url":"https://avatars.githubusercontent.com/u/16156441?v=3","gravatar_id":"","url":"https://api.github.com/users/yweijiang","html_url":"https://github.com/yweijiang","followers_url":"https://api.github.com/users/yweijiang/followers","following_url":"https://api.github.com/users/yweijiang/following{/other_user}","gists_url":"https://api.github.com/users/yweijiang/gists{/gist_id}","starred_url":"https://api.github.com/users/yweijiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yweijiang/subscriptions","organizations_url":"https://api.github.com/users/yweijiang/orgs","repos_url":"https://api.github.com/users/yweijiang/repos","events_url":"https://api.github.com/users/yweijiang/events{/privacy}","received_events_url":"https://api.github.com/users/yweijiang/received_events","type":"User","site_admin":false},"body":"Went ahead and put this in a RETURN_NULL_IF_FAILED.","created_at":"2016-04-21T18:52:08Z","updated_at":"2016-04-21T18:52:08Z","html_url":"https://github.com/Microsoft/WinObjC/pull/445#discussion_r60635651","pull_request_url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/comments/60635651"},"html":{"href":"https://github.com/Microsoft/WinObjC/pull/445#discussion_r60635651"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445","id":66713226,"html_url":"https://github.com/Microsoft/WinObjC/pull/445","diff_url":"https://github.com/Microsoft/WinObjC/pull/445.diff","patch_url":"https://github.com/Microsoft/WinObjC/pull/445.patch","issue_url":"https://api.github.com/repos/Microsoft/WinObjC/issues/445","number":445,"state":"open","locked":false,"title":"ImageIO Destination and Properties","user":{"login":"yweijiang","id":16156441,"avatar_url":"https://avatars.githubusercontent.com/u/16156441?v=3","gravatar_id":"","url":"https://api.github.com/users/yweijiang","html_url":"https://github.com/yweijiang","followers_url":"https://api.github.com/users/yweijiang/followers","following_url":"https://api.github.com/users/yweijiang/following{/other_user}","gists_url":"https://api.github.com/users/yweijiang/gists{/gist_id}","starred_url":"https://api.github.com/users/yweijiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yweijiang/subscriptions","organizations_url":"https://api.github.com/users/yweijiang/orgs","repos_url":"https://api.github.com/users/yweijiang/repos","events_url":"https://api.github.com/users/yweijiang/events{/privacy}","received_events_url":"https://api.github.com/users/yweijiang/received_events","type":"User","site_admin":false},"body":"-Added support for CGImageDestination\r\n-Added support for Image Properties in both CGImageSource and CGImageDestination\r\n-Added unit tests for new APIs","created_at":"2016-04-15T22:24:35Z","updated_at":"2016-04-21T18:52:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4847ba312240d999008a9a5b1ee21af6496f7a0a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445/commits","review_comments_url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445/comments","review_comment_url":"https://api.github.com/repos/Microsoft/WinObjC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/WinObjC/issues/445/comments","statuses_url":"https://api.github.com/repos/Microsoft/WinObjC/statuses/60b0a42f180f8eafd0af56b3f0524b15c3499144","head":{"label":"yweijiang:master","ref":"master","sha":"60b0a42f180f8eafd0af56b3f0524b15c3499144","user":{"login":"yweijiang","id":16156441,"avatar_url":"https://avatars.githubusercontent.com/u/16156441?v=3","gravatar_id":"","url":"https://api.github.com/users/yweijiang","html_url":"https://github.com/yweijiang","followers_url":"https://api.github.com/users/yweijiang/followers","following_url":"https://api.github.com/users/yweijiang/following{/other_user}","gists_url":"https://api.github.com/users/yweijiang/gists{/gist_id}","starred_url":"https://api.github.com/users/yweijiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yweijiang/subscriptions","organizations_url":"https://api.github.com/users/yweijiang/orgs","repos_url":"https://api.github.com/users/yweijiang/repos","events_url":"https://api.github.com/users/yweijiang/events{/privacy}","received_events_url":"https://api.github.com/users/yweijiang/received_events","type":"User","site_admin":false},"repo":{"id":56349624,"name":"WinObjC","full_name":"yweijiang/WinObjC","owner":{"login":"yweijiang","id":16156441,"avatar_url":"https://avatars.githubusercontent.com/u/16156441?v=3","gravatar_id":"","url":"https://api.github.com/users/yweijiang","html_url":"https://github.com/yweijiang","followers_url":"https://api.github.com/users/yweijiang/followers","following_url":"https://api.github.com/users/yweijiang/following{/other_user}","gists_url":"https://api.github.com/users/yweijiang/gists{/gist_id}","starred_url":"https://api.github.com/users/yweijiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yweijiang/subscriptions","organizations_url":"https://api.github.com/users/yweijiang/orgs","repos_url":"https://api.github.com/users/yweijiang/repos","events_url":"https://api.github.com/users/yweijiang/events{/privacy}","received_events_url":"https://api.github.com/users/yweijiang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yweijiang/WinObjC","description":"Objective-C for Windows","fork":true,"url":"https://api.github.com/repos/yweijiang/WinObjC","forks_url":"https://api.github.com/repos/yweijiang/WinObjC/forks","keys_url":"https://api.github.com/repos/yweijiang/WinObjC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yweijiang/WinObjC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yweijiang/WinObjC/teams","hooks_url":"https://api.github.com/repos/yweijiang/WinObjC/hooks","issue_events_url":"https://api.github.com/repos/yweijiang/WinObjC/issues/events{/number}","events_url":"https://api.github.com/repos/yweijiang/WinObjC/events","assignees_url":"https://api.github.com/repos/yweijiang/WinObjC/assignees{/user}","branches_url":"https://api.github.com/repos/yweijiang/WinObjC/branches{/branch}","tags_url":"https://api.github.com/repos/yweijiang/WinObjC/tags","blobs_url":"https://api.github.com/repos/yweijiang/WinObjC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yweijiang/WinObjC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yweijiang/WinObjC/git/refs{/sha}","trees_url":"https://api.github.com/repos/yweijiang/WinObjC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yweijiang/WinObjC/statuses/{sha}","languages_url":"https://api.github.com/repos/yweijiang/WinObjC/languages","stargazers_url":"https://api.github.com/repos/yweijiang/WinObjC/stargazers","contributors_url":"https://api.github.com/repos/yweijiang/WinObjC/contributors","subscribers_url":"https://api.github.com/repos/yweijiang/WinObjC/subscribers","subscription_url":"https://api.github.com/repos/yweijiang/WinObjC/subscription","commits_url":"https://api.github.com/repos/yweijiang/WinObjC/commits{/sha}","git_commits_url":"https://api.github.com/repos/yweijiang/WinObjC/git/commits{/sha}","comments_url":"https://api.github.com/repos/yweijiang/WinObjC/comments{/number}","issue_comment_url":"https://api.github.com/repos/yweijiang/WinObjC/issues/comments{/number}","contents_url":"https://api.github.com/repos/yweijiang/WinObjC/contents/{+path}","compare_url":"https://api.github.com/repos/yweijiang/WinObjC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yweijiang/WinObjC/merges","archive_url":"https://api.github.com/repos/yweijiang/WinObjC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yweijiang/WinObjC/downloads","issues_url":"https://api.github.com/repos/yweijiang/WinObjC/issues{/number}","pulls_url":"https://api.github.com/repos/yweijiang/WinObjC/pulls{/number}","milestones_url":"https://api.github.com/repos/yweijiang/WinObjC/milestones{/number}","notifications_url":"https://api.github.com/repos/yweijiang/WinObjC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yweijiang/WinObjC/labels{/name}","releases_url":"https://api.github.com/repos/yweijiang/WinObjC/releases{/id}","deployments_url":"https://api.github.com/repos/yweijiang/WinObjC/deployments","created_at":"2016-04-15T21:03:31Z","updated_at":"2016-04-15T21:03:44Z","pushed_at":"2016-04-21T02:24:17Z","git_url":"git://github.com/yweijiang/WinObjC.git","ssh_url":"git@github.com:yweijiang/WinObjC.git","clone_url":"https://github.com/yweijiang/WinObjC.git","svn_url":"https://github.com/yweijiang/WinObjC","homepage":null,"size":320132,"stargazers_count":0,"watchers_count":0,"language":"Objective-C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"5ff90ccd2a7160ed8a49818556e3ca41022b99d6","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":37950166,"name":"WinObjC","full_name":"Microsoft/WinObjC","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/WinObjC","description":"Objective-C for Windows","fork":false,"url":"https://api.github.com/repos/Microsoft/WinObjC","forks_url":"https://api.github.com/repos/Microsoft/WinObjC/forks","keys_url":"https://api.github.com/repos/Microsoft/WinObjC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/WinObjC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/WinObjC/teams","hooks_url":"https://api.github.com/repos/Microsoft/WinObjC/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/WinObjC/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/WinObjC/events","assignees_url":"https://api.github.com/repos/Microsoft/WinObjC/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/WinObjC/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/WinObjC/tags","blobs_url":"https://api.github.com/repos/Microsoft/WinObjC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/WinObjC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/WinObjC/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/WinObjC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/WinObjC/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/WinObjC/languages","stargazers_url":"https://api.github.com/repos/Microsoft/WinObjC/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/WinObjC/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/WinObjC/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/WinObjC/subscription","commits_url":"https://api.github.com/repos/Microsoft/WinObjC/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/WinObjC/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/WinObjC/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/WinObjC/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/WinObjC/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/WinObjC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/WinObjC/merges","archive_url":"https://api.github.com/repos/Microsoft/WinObjC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/WinObjC/downloads","issues_url":"https://api.github.com/repos/Microsoft/WinObjC/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/WinObjC/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/WinObjC/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/WinObjC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/WinObjC/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/WinObjC/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/WinObjC/deployments","created_at":"2015-06-23T23:14:58Z","updated_at":"2016-04-21T15:53:08Z","pushed_at":"2016-04-21T02:24:18Z","git_url":"git://github.com/Microsoft/WinObjC.git","ssh_url":"git@github.com:Microsoft/WinObjC.git","clone_url":"https://github.com/Microsoft/WinObjC.git","svn_url":"https://github.com/Microsoft/WinObjC","homepage":null,"size":321779,"stargazers_count":5160,"watchers_count":5160,"language":"Objective-C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":629,"mirror_url":null,"open_issues_count":163,"forks":629,"open_issues":163,"watchers":5160,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445"},"html":{"href":"https://github.com/Microsoft/WinObjC/pull/445"},"issue":{"href":"https://api.github.com/repos/Microsoft/WinObjC/issues/445"},"comments":{"href":"https://api.github.com/repos/Microsoft/WinObjC/issues/445/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/WinObjC/pulls/445/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/WinObjC/statuses/60b0a42f180f8eafd0af56b3f0524b15c3499144"}}}}