Skip to content

Instantly share code, notes, and snippets.

View zhongwuzw's full-sized avatar
👨‍💻
Thinking! Learning!

Wu Zhong zhongwuzw

👨‍💻
Thinking! Learning!
View GitHub Profile
@NSProgrammer
NSProgrammer / Overview.md
Last active March 7, 2023 08:06
Comparing modern vs legacy graphics context rendering on iOS

legacy = UIGraphicsBeginImageContextWithOptions + UIGraphicsEndImageContext

modern = UIGraphicsImageRendererFormat + UIGraphicsImageRenderer

Take aways:

  • "modern" w/ prefersExtendedRange = NO
    • basically the same perf as "legacy"
    • probably a good idea to adopt since optimizations will likely be in "modern" first
  • "modern" w/ prefersExtendedRange = YES
//
// PSPDFFastEnumeration.h
// PSPDFFoundation
//
// PSPDFKit is the leading cross-platform solution for integrating PDFs into your apps: https://pspdfkit.com.
// Try it today using our free PDF Viewer app: https://pdfviewer.io/
//
// This file is MIT licensed.
@protocol PSPDFFastEnumeration <NSFastEnumeration>
@steipete
steipete / PSPDFThreadSafeMutableDictionary.m
Last active December 10, 2022 09:37
Simple implementation of a thread safe mutable dictionary. In most cases, you want NSCache instead, but it can be useful in situations where you want to manually control what is evicted from the cache in low memory situations.**Warning:** I only use this for setting/getting keys. Enumeration is not thread safe here and will still throw exception…
//
// PSPDFThreadSafeMutableDictionary.m
//
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@steipete
steipete / UIImage+PSPDFKitAdditions.m
Created August 13, 2011 20:52
Preload UIImage for super-smooth interaction. especially great if you use JPGs, which otherwise produce a noticeable lag on the main thread.
- (UIImage *)pspdf_preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width*4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);