2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * charles picasso && blackrain 14/08/08.
28 #import <Cocoa/Cocoa.h>
29 #import <QuartzCore/QuartzCore.h>
34 #define SCIMAGE_DEBUG 0
35 #define SCIMAGE_BACKGROUND_DEBUG 0
36 #define SCIMAGE_FILTER_DEBUG 0
37 #define SCCIIMAGE_MAX_WIDTH 4096
38 #define SCCIIMAGE_MAX_HEIGHT 4096
41 May be we should force the 10.4 version ??
43 #define SCIMAGE_MAC_OS_10_5 0
44 because it does run with no problem on 10.5
45 anyway currently in both platform the 10.4 version should be compiled instead of the 10.5
46 in case of a problem force the 10.4
48 Why 2 different versions ?
49 --------------------------
50 - CIImageAccumulator does not behave the same with 10.4 SDK on 10.5 : seems like use Generator type Filters
51 make it refuse to take the CIImage. This crash the app because of an EXEC_BAD_ACCESS later if drawing.
52 - On 10.4 the CIImageAccumulator is replaced by a plain CIImage : this does not change global behaviour
53 it just disable the possibility to use Dirty Rect wich should be considered as a marginal option for now.
58 #if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
59 typedef unsigned int PixelData
;
61 typedef NSUInteger PixelData
;
64 #define SCIMAGE_MAC_OS_10_4 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
65 //#if defined(MAC_OS_X_VERSION_10_5)
66 //#define SCIMAGE_MAC_OS_10_5 (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
68 #define SCIMAGE_MAC_OS_10_5 0
71 #if (SCIMAGE_DEBUG || SCIMAGE_BACKGROUND_DEBUG)
72 inline double GetTimeOfDay();
77 return (double)tv
.tv_sec
+ 1.0e-6 * (double)tv
.tv_usec
;
82 SCImageUseGraphicsAccelerationWhenPossible
= 0, // SCImage will always use CIImage for drawing - worst performance if user will repeatedly:
83 // 1_ draw inside the image
84 // 2_ use direct pixel data manipulation (get/set)
85 // but definitely better for fast drawing and accelerated image processing techniques (CoreImageFilters)
87 SCImageDoNotUseGraphicsAcceleration
= 1 // SCImage will never use CIImage - better performance if user always update the bitmap representation
88 // using standard Quartz techniques like :
89 // 1_ drawing inside the Image (with lockFocus - unlockFocus)
90 // 2_ or using a lot direct pixel data manipulation (get/set)
92 typedef int SCImageHint
;
94 @interface SCImage
: NSObject
97 #if SC_IMAGE_MAC_OS_10_5
98 CIImageAccumulator
*_ciimageStore
; // accumulator
100 CIImage
*_ciimage
; // in 10.4
103 CIFormat _ciFormat
; // hint for prefered format when processing CoreImages
104 NSBitmapImageRep
*_bitmap
; // ref to data used for pixel manipulation
105 NSLock
*_wLock
; // write on lock for pixel manip
106 NSGraphicsContext
*_prevCtx
; // used for lockFocus - unlockFocus store previous context
107 NSImage
*_nsimage
; // front model when not accelerated
108 NSImageInterpolation _interpolation
;
109 SCImageHint _hints
; // store for all hints - only drawing hint for now - not really used...
110 BOOL _accelerated
; // switch between different reps
113 BOOL _bitmapSynced
; // is bitmap rep in sync
114 BOOL _ciimageSynced
; // is ciimage rep in sync
115 BOOL _savedCtxState
; // flag used for lockFocus - unlockFocus
117 void* _cache
; // used to cache reps : might be a CGLayerRef / NSImage / CGPattern (CGLayerRef are cached to GPU when possible)
119 - (id
)initWithContentsOfURL
:(NSURL
*)url isAccelerated
:(BOOL
)yorn format
:(CIFormat
)fmt
;
120 - (id
)initWithSize
:(NSSize
)size isAccelerated
:(BOOL
)yorn format
:(CIFormat
)fmt
;
121 - (id
)initWithCIImage
:(CIImage
*)image extent
:(CGRect
)extent format
:(CIFormat
)imageFormat
;
122 - (id
)initWithNSImage
:(NSImage
*)image
;
125 //- (void)rebuildAccumulatorFromCIImage:(CIImage*)newCIImage; // rebuild everything for inplace operation if extent if different
127 - (NSBitmapImageRep
*)bitmapRepresentation
;
128 - (unsigned char*)bitmapData
;
129 - (void)rebuildBitmapRepFromCIImage
;
130 - (void)rebuildNSImageFromBitmapRep
;
131 - (void)rebuildCIImageFromBitmapRep
;
132 - (void)setDrawingHint
:(SCImageHint
)hint
;
133 - (void)setPixel
:(PixelData
*)pixel atX
:(int)x y
:(int)y
;
134 - (void)setColor
:(NSColor
*)color atX
:(unsigned int)x y
:(unsigned int)y
;
135 - (void)getPixel
:(PixelData
*)pixel atX
:(int)x y
:(int)y
;
136 - (NSColor
*)colorAtX
:(unsigned int)x y
:(unsigned int)y
;
137 - (void)setScalesWhenResized
:(BOOL
)yorn
;
138 - (BOOL
)scalesWhenResized
;
139 - (BOOL
)isAccelerated
;
140 - (void)setAccelerated
:(BOOL
)yorn
;
141 - (NSImageInterpolation
)imageInterpolation
;
142 - (void)setImageInterpolation
:(NSImageInterpolation
)interp
;
145 - (void)setSize
:(NSSize
)s
;
153 - (void)setShouldSyncBitmap
:(BOOL
)yorn
;
154 - (void)setShouldSyncCIImage
:(BOOL
)yorn
;
160 #if SCIMAGE_MAC_OS_10_5
161 - (CIImageAccumulator
*)accumulator
;
163 - (void)syncRepresentations
; // synchronize representations
164 - (void)drawAtPoint
:(NSPoint
)point fromRect
:(NSRect
)srcRect operation
:(NSCompositingOperation
)op fraction
:(float)delta
;
165 - (void)drawInRect
:(NSRect
)dstRect fromRect
:(NSRect
)srcRect operation
:(NSCompositingOperation
)op fraction
:(float)delta
;
166 - (void)drawInSCRect
:(NSRect
)dstRect fromRect
:(NSRect
)srcRect operation
:(NSCompositingOperation
)op fraction
:(float)delta
;
167 - (void)tileInSCRect
:(NSRect
)dstRect fromRect
:(NSRect
)srcRect operation
:(NSCompositingOperation
)op fraction
:(float)delta
;
168 - (void)applyFilter
:(CIFilter
*)filter
;
169 -(SCImage
*)imageFilteredWith
:(CIFilter
*)filter
;