123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /*
- * pixiv_down - CLI-based downloading tool for https://www.pixiv.net.
- * Copyright (C) 2024 Mio
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- module pd.image_reader.osx;
- version(OSX):
- import std.string;
- public class ImageReader
- {
- this(string filename)
- {
- CFStringRef cfFilename = CFStringCreateWithCString(kCFAllocatorDefault, toStringz(filename), kCFStringEncodingUTF8);
- CFURLRef path = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfFilename, kCFURLPOSIXPathStyle, false);
- scope(exit) {
- CFRelease(cfFilename);
- CFRelease(path);
- }
- systemRef = CGImageSourceCreateWithURL(path, null);
- if (null is systemRef) {
- // TODO: Check errno and see if we can use strerror.
- throw new Exception("Unable to create image source.");
- }
- }
- void dispose()
- {
- if (this.disposed) {
- return;
- }
- if (null !is systemRef) {
- CFRelease(systemRef);
- }
- this.disposed = true;
- }
- CGImageSourceRef getSystemRef() {
- return this.systemRef;
- }
- private:
- CGImageSourceRef systemRef;
- bool disposed = false;
- }
- private:
- nothrow:
- extern(C):
- @nogc:
- alias CFTypeRef = void*;
- alias CFAllocatorRef = CFTypeRef;
- alias CFDictionaryRef = CFTypeRef;
- alias CFStringRef = CFTypeRef;
- alias CFURLRef = CFTypeRef;
- alias CFStringEncoding = int;
- alias CFURLPathStyle = int;
- alias CGImageSourceRef = CFTypeRef;
- enum kCFAllocatorDefault = null;
- enum : CFStringEncoding
- {
- kCFStringEncodingUTF8 = 0x08000100,
- }
- enum : CFURLPathStyle
- {
- kCFURLPOSIXPathStyle = 0,
- }
- extern __gshared CFStringRef kCGImagePropertyGIFDictionary;
- extern __gshared CFStringRef kCGImagePropertyGIFLoopCount;
- void CFRelease(void*);
- CFStringRef CFStringCreateWithCString(CFAllocatorRef allocator, const char *cStr, CFStringEncoding encoding);
- CFURLRef CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStringRef filePath, CFURLPathStyle pathStyle, bool isDirectory);
- CGImageSourceRef CGImageSourceCreateWithURL(CFURLRef url, CFDictionaryRef options);
|