Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
18 KiB

  1. /*
  2. * CVPixelBuffer.h
  3. * CoreVideo
  4. *
  5. * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
  6. *
  7. */
  8. /*! @header CVPixelBuffer.h
  9. @copyright 2004 Apple Computer, Inc. All rights reserved.
  10. @availability Mac OS X 10.4 or later
  11. @discussion CVPixelBuffers are CVImageBuffers that hold the pixels in main memory
  12. */
  13. #if !defined(__COREVIDEO_CVPIXELBUFFER_H__)
  14. #define __COREVIDEO_CVPIXELBUFFER_H__ 1
  15. #include <TargetConditionals.h>
  16. #if TARGET_OS_MAC
  17. #include <QuartzCore/CVImageBuffer.h>
  18. #include <CoreFoundation/CFArray.h>
  19. #else
  20. #pragma warning (disable: 4068) // ignore unknown pragmas
  21. #include <CVImageBuffer.h>
  22. #include <CFArray.h>
  23. #endif
  24. #if defined(__cplusplus)
  25. extern "C" {
  26. #endif
  27. #pragma mark BufferAttributeKeys
  28. #if TARGET_OS_MAC
  29. CV_EXPORT const CFStringRef kCVPixelBufferPixelFormatTypeKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // A single CFNumber or a CFArray of CFNumbers (OSTypes)
  30. CV_EXPORT const CFStringRef kCVPixelBufferMemoryAllocatorKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFAllocatorRef
  31. CV_EXPORT const CFStringRef kCVPixelBufferWidthKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  32. CV_EXPORT const CFStringRef kCVPixelBufferHeightKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  33. CV_EXPORT const CFStringRef kCVPixelBufferExtendedPixelsLeftKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  34. CV_EXPORT const CFStringRef kCVPixelBufferExtendedPixelsTopKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  35. CV_EXPORT const CFStringRef kCVPixelBufferExtendedPixelsRightKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  36. CV_EXPORT const CFStringRef kCVPixelBufferExtendedPixelsBottomKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  37. CV_EXPORT const CFStringRef kCVPixelBufferBytesPerRowAlignmentKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFNumber
  38. CV_EXPORT const CFStringRef kCVPixelBufferCGBitmapContextCompatibilityKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFBoolean
  39. CV_EXPORT const CFStringRef kCVPixelBufferCGImageCompatibilityKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFBoolean
  40. CV_EXPORT const CFStringRef kCVPixelBufferOpenGLCompatibilityKey AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // CFBoolean
  41. #else
  42. #define kCVPixelBufferPixelFormatTypeKey CFSTR("PixelFormatType")
  43. #define kCVPixelBufferMemoryAllocatorKey CFSTR("MemoryAllocator")
  44. #define kCVPixelBufferWidthKey CFSTR("Width")
  45. #define kCVPixelBufferHeightKey CFSTR("Height")
  46. #define kCVPixelBufferExtendedPixelsLeftKey CFSTR("ExtendedPixelsLeft")
  47. #define kCVPixelBufferExtendedPixelsTopKey CFSTR("ExtendedPixelsTop")
  48. #define kCVPixelBufferExtendedPixelsRightKey CFSTR("ExtendedPixelsRight")
  49. #define kCVPixelBufferExtendedPixelsBottomKey CFSTR("ExtendedPixelsBottom")
  50. #define kCVPixelBufferBytesPerRowAlignmentKey CFSTR("BytesPerRowAlignment")
  51. #define kCVPixelBufferCGBitmapContextCompatibilityKey CFSTR("CGBitmapContextCompatibility")
  52. #define kCVPixelBufferCGImageCompatibilityKey CFSTR("CGImageCompatibility")
  53. #define kCVPixelBufferOpenGLCompatibilityKey CFSTR("OpenGLCompatibility")
  54. #endif
  55. /*!
  56. @typedef CVPixelBufferRef
  57. @abstract Based on the image buffer type. The pixel buffer implements the memory storage for an image buffer.
  58. */
  59. typedef CVImageBufferRef CVPixelBufferRef;
  60. CV_EXPORT CFTypeID CVPixelBufferGetTypeID() AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  61. /*!
  62. @function CVPixelBufferRetain
  63. @abstract Retains a CVPixelBuffer object
  64. @discussion Equivalent to CFRetain, but NULL safe
  65. @param buffer A CVPixelBuffer object that you want to retain.
  66. @result A CVPixelBuffer object that is the same as the passed in buffer.
  67. */
  68. CV_EXPORT CVPixelBufferRef CVPixelBufferRetain( CVPixelBufferRef texture ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  69. /*!
  70. @function CVPixelBufferRelease
  71. @abstract Releases a CVPixelBuffer object
  72. @discussion Equivalent to CFRelease, but NULL safe
  73. @param buffer A CVPixelBuffer object that you want to release.
  74. */
  75. CV_EXPORT void CVPixelBufferRelease( CVPixelBufferRef texture ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  76. /*!
  77. @function CVPixelBufferCreateResolvedAttributesDictionary
  78. @abstract Takes a CFArray of CFDictionary objects describing various pixel buffer attributes and tries to resolve them into a
  79. single dictionary.
  80. @discussion This is useful when you need to resolve multiple requirements between different potential clients of a buffer.
  81. @param attributes CFArray of CFDictionaries containing kCVPixelBuffer key/value pairs.
  82. @param resolvedDictionaryOut The resulting dictionary will be placed here.
  83. @result Return value that may be useful in discovering why resolution failed.
  84. */
  85. CV_EXPORT CVReturn CVPixelBufferCreateResolvedAttributesDictionary(CFAllocatorRef allocator, CFArrayRef attributes, CFDictionaryRef *resolvedDictionaryOut) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  86. /*!
  87. @function CVPixelBufferCreate
  88. @abstract Call to create a single PixelBuffer for a given size and pixelFormatType.
  89. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. It allocates the necessary memory based on the pixel dimensions, pixelFormatType and extended pixels described in the pixelBufferAttributes. Not all parameters of the pixelBufferAttributes will be used here.
  90. @param width Width of the PixelBuffer in pixels.
  91. @param height Height of the PixelBuffer in pixels.
  92. @param pixelFormatType Pixel format indentified by its respective OSType.
  93. @param pixelBufferAttributes A dictionary with additonal attributes for a a pixel buffer. This parameter is optional. See PixelBufferAttributes for more details.
  94. @param pixelBufferOut The new pixel buffer will be returned here
  95. @result returns kCVReturnSuccess on success.
  96. */
  97. CV_EXPORT CVReturn CVPixelBufferCreate(CFAllocatorRef allocator,
  98. size_t width,
  99. size_t height,
  100. OSType pixelFormatType,
  101. CFDictionaryRef pixelBufferAttributes,
  102. CVPixelBufferRef *pixelBufferOut) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  103. typedef void (*CVPixelBufferReleaseBytesCallback)( void *releaseRefCon, const void *baseAddress );
  104. /*!
  105. @function CVPixelBufferCreateWithBytes
  106. @abstract Call to create a single PixelBuffer for a given size and pixelFormatType based on a passed in piece of memory.
  107. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. Not all parameters of the pixelBufferAttributes will be used here. It requires a release callback function that will be called, when the PixelBuffer gets destroyed so that the owner of the pixels can free the memory.
  108. @param width Width of the PixelBuffer in pixels
  109. @param height Height of the PixelBuffer in pixels
  110. @param pixelFormatType Pixel format indentified by its respective OSType.
  111. @param baseAddress Address of the memory storing the pixels.
  112. @param bytesPerRow Row bytes of the pixel storage memory.
  113. @param releaseCallback CVPixelBufferReleaseBytePointerCallback function that gets called when the PixelBuffer gets destroyed.
  114. @param releaseRefCon User data identifying the PixelBuffer for the release callback.
  115. @param pixelBufferAttributes A dictionary with additonal attributes for a a pixel buffer. This parameter is optional. See PixelBufferAttributes for more details.
  116. @param pixelBufferOut The new pixel buffer will be returned here
  117. @result returns kCVReturnSuccess on success.
  118. */
  119. CV_EXPORT CVReturn CVPixelBufferCreateWithBytes(CFAllocatorRef allocator,
  120. size_t width,
  121. size_t height,
  122. OSType pixelFormatType,
  123. void *baseAddress,
  124. size_t bytesPerRow,
  125. CVPixelBufferReleaseBytesCallback releaseCallback,
  126. void *releaseRefCon,
  127. CFDictionaryRef pixelBufferAttributes,
  128. CVPixelBufferRef *pixelBufferOut) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  129. typedef void (*CVPixelBufferReleasePlanarBytesCallback)( void *releaseRefCon, const void *dataPtr, size_t dataSize, size_t numberOfPlanes, const void *planeAddresses[] );
  130. /*!
  131. @function CVPixelBufferCreateWithPlanarBytes
  132. @abstract Call to create a single PixelBuffer in planar format for a given size and pixelFormatType based on a passed in piece of memory.
  133. @discussion Creates a single PixelBuffer for a given size and pixelFormatType. Not all parameters of the pixelBufferAttributes will be used here. It requires a release callback function that will be called, when the PixelBuffer gets destroyed so that the owner of the pixels can free the memory.
  134. @param width Width of the PixelBuffer in pixels
  135. @param height Height of the PixelBuffer in pixels
  136. @param pixelFormatType Pixel format indentified by its respective OSType.
  137. @param dataPtr Pass a pointer to a plane descriptor block, or NULL.
  138. @param dataSize pass size if planes are contiguous, NULL if not.
  139. @param numberOfPlanes Number of planes.
  140. @param planeBaseAddress Array of base addresses for the planes.
  141. @param planeWidth Array of plane widths.
  142. @param planeHeight Array of plane heights.
  143. @param planeBytesPerRow Array of plane bytesPerRow values.
  144. @param releaseCallback CVPixelBufferReleaseBytePointerCallback function that gets called when the PixelBuffer gets destroyed.
  145. @param releaseRefCon User data identifying the PixelBuffer for the release callback.
  146. @param pixelBufferAttributes A dictionary with additonal attributes for a a pixel buffer. This parameter is optional. See PixelBufferAttributes for more details.
  147. @param pixelBufferOut The new pixel buffer will be returned here
  148. @result returns kCVReturnSuccess on success.
  149. */
  150. CV_EXPORT CVReturn CVPixelBufferCreateWithPlanarBytes(CFAllocatorRef allocator,
  151. size_t width,
  152. size_t height,
  153. OSType pixelFormatType,
  154. void *dataPtr, // pass a pointer to a plane descriptor block, or NULL
  155. size_t dataSize, // pass size if planes are contiguous, NULL if not
  156. size_t numberOfPlanes,
  157. void *planeBaseAddress[],
  158. size_t planeWidth[],
  159. size_t planeHeight[],
  160. size_t planeBytesPerRow[],
  161. CVPixelBufferReleasePlanarBytesCallback releaseCallback,
  162. void *releaseRefCon,
  163. CFDictionaryRef pixelBufferAttributes,
  164. CVPixelBufferRef *pixelBufferOut) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  165. /*!
  166. @function CVPixelBufferLockBaseAddress
  167. @abstract Description Locks the BaseAddress of the PixelBuffer to ensure that the is available.
  168. @param pixelBuffer Target PixelBuffer.
  169. @param lockFlags No options currently defined, pass 0.
  170. @result kCVReturnSuccess if the lock succeeded, or error code on failure
  171. */
  172. CV_EXPORT CVReturn CVPixelBufferLockBaseAddress(CVPixelBufferRef pixelBuffer, CVOptionFlags lockFlags) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  173. /*!
  174. @function CVPixelBufferUnlockBaseAddress
  175. @abstract Description Unlocks the BaseAddress of the PixelBuffer.
  176. @param pixelBuffer Target PixelBuffer.
  177. @param unlockFlags No options currently defined, pass 0.
  178. @result kCVReturnSuccess if the unlock succeeded, or error code on failure
  179. */
  180. CV_EXPORT CVReturn CVPixelBufferUnlockBaseAddress(CVPixelBufferRef pixelBuffer, CVOptionFlags unlockFlags) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  181. /*!
  182. @function CVPixelBufferGetWidth
  183. @abstract Returns the width of the PixelBuffer.
  184. @param pixelBuffer Target PixelBuffer.
  185. @result Width in pixels.
  186. */
  187. CV_EXPORT size_t CVPixelBufferGetWidth(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  188. /*!
  189. @function CVPixelBufferGetHeight
  190. @abstract Returns the height of the PixelBuffer.
  191. @param pixelBuffer Target PixelBuffer.
  192. @result Height in pixels.
  193. */
  194. CV_EXPORT size_t CVPixelBufferGetHeight(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  195. /*!
  196. @function CVPixelBufferGetPixelFormatType
  197. @abstract Returns the PixelFormatType of the PixelBuffer.
  198. @param pixelBuffer Target PixelBuffer.
  199. @result OSType identifying the pixel format by its type.
  200. */
  201. CV_EXPORT OSType CVPixelBufferGetPixelFormatType(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  202. /*!
  203. @function CVPixelBufferGetBaseAddress
  204. @abstract Returns the base address of the PixelBuffer.
  205. @discussion Retrieving the base address for a PixelBuffer requires that the buffer base address be locked
  206. via a successful call to CVPixelBufferLockBaseAddress.
  207. @param pixelBuffer Target PixelBuffer.
  208. @result Base address of the pixels.
  209. For chunky buffers, this will return a pointer to the pixel at 0,0 in the buffer
  210. For planar buffers this will return a pointer to a PlanarComponentInfo struct (defined in QuickTime).
  211. */
  212. CV_EXPORT void *CVPixelBufferGetBaseAddress(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  213. /*!
  214. @function CVPixelBufferGetBytesPerRow
  215. @abstract Returns the rowBytes of the PixelBuffer.
  216. @param pixelBuffer Target PixelBuffer.
  217. @result Bytes per row of the image data. For planar buffers this will return a rowBytes value such that bytesPerRow * height
  218. will cover the entire image including all planes.
  219. */
  220. CV_EXPORT size_t CVPixelBufferGetBytesPerRow(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  221. /*!
  222. @function CVPixelBufferGetDataSize
  223. @abstract Returns the data size for contigous planes of the PixelBuffer.
  224. @param pixelBuffer Target PixelBuffer.
  225. @result Data size used in CVPixelBufferCreateWithPlanarBytes.
  226. */
  227. CV_EXPORT size_t CVPixelBufferGetDataSize(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  228. /*!
  229. @function CVPixelBufferIsPlanar
  230. @abstract Returns if the PixelBuffer is planar.
  231. @param pixelBuffer Target PixelBuffer.
  232. @result True if the PixelBuffer was created using CVPixelBufferCreateWithPlanarBytes.
  233. */
  234. CV_EXPORT Boolean CVPixelBufferIsPlanar(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  235. /*!
  236. @function CVPixelBufferGetPlaneCount
  237. @abstract Returns number of planes of the PixelBuffer.
  238. @param pixelBuffer Target PixelBuffer.
  239. @result Number of planes. Returns 0 for non-planar CVPixelBufferRefs.
  240. */
  241. CV_EXPORT size_t CVPixelBufferGetPlaneCount(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  242. /*!
  243. @function CVPixelBufferGetWidthOfPlane
  244. @abstract Returns the width of the plane at planeIndex in the PixelBuffer.
  245. @param pixelBuffer Target PixelBuffer.
  246. @param planeIndex Identifying the plane.
  247. @result Width in pixels, or 0 for non-planar CVPixelBufferRefs.
  248. */
  249. CV_EXPORT size_t CVPixelBufferGetWidthOfPlane(CVPixelBufferRef pixelBuffer, size_t planeIndex) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  250. /*!
  251. @function CVPixelBufferGetHeightOfPlane
  252. @abstract Returns the height of the plane at planeIndex in the PixelBuffer.
  253. @param pixelBuffer Target PixelBuffer.
  254. @param planeIndex Identifying the plane.
  255. @result Height in pixels, or 0 for non-planar CVPixelBufferRefs.
  256. */
  257. CV_EXPORT size_t CVPixelBufferGetHeightOfPlane(CVPixelBufferRef pixelBuffer, size_t planeIndex) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  258. /*!
  259. @function CVPixelBufferGetBaseAddressOfPlane
  260. @abstract Returns the base address of the plane at planeIndex in the PixelBuffer.
  261. @discussion Retrieving the base address for a PixelBuffer requires that the buffer base address be locked
  262. via a successful call to CVPixelBufferLockBaseAddress.
  263. @param pixelBuffer Target PixelBuffer.
  264. @param planeIndex Identifying the plane.
  265. @result Base address of the plane, or NULL for non-planar CVPixelBufferRefs.
  266. */
  267. CV_EXPORT void *CVPixelBufferGetBaseAddressOfPlane(CVPixelBufferRef pixelBuffer, size_t planeIndex) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  268. /*!
  269. @function CVPixelBufferGetBytesPerRowOfPlane
  270. @abstract Returns the row bytes of the plane at planeIndex in the PixelBuffer.
  271. @param pixelBuffer Target PixelBuffer.
  272. @param planeIndex Identifying the plane.
  273. @result Row bytes of the plane, or NULL for non-planar CVPixelBufferRefs.
  274. */
  275. CV_EXPORT size_t CVPixelBufferGetBytesPerRowOfPlane(CVPixelBufferRef pixelBuffer, size_t planeIndex) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  276. /*!
  277. @function CVPixelBufferGetExtendedPixels
  278. @abstract Returns the size of extended pixels of the PixelBuffer.
  279. @param pixelBuffer Target PixelBuffer.
  280. @param extraColumnsOnLeft Returns the pixel row padding to the left. May be NULL.
  281. @param extraRowsOnTop Returns the pixel row padding to the top. May be NULL.
  282. @param extraColumnsOnRight Returns the pixel row padding to the right. May be NULL.
  283. @param extraRowsOnBottom Returns the pixel row padding to the bottom. May be NULL.
  284. */
  285. CV_EXPORT void CVPixelBufferGetExtendedPixels(CVPixelBufferRef pixelBuffer,
  286. size_t *extraColumnsOnLeft,
  287. size_t *extraColumnsOnRight,
  288. size_t *extraRowsOnTop,
  289. size_t *extraRowsOnBottom) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  290. /*!
  291. @function CVPixelBufferFillExtendedPixels
  292. @abstract Fills the extended pixels of the PixelBuffer with Zero. This function replicates edge pixels to fill the entire extended region of the image.
  293. @param pixelBuffer Target PixelBuffer.
  294. */
  295. CV_EXPORT CVReturn CVPixelBufferFillExtendedPixels(CVPixelBufferRef pixelBuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER;
  296. #if defined(__cplusplus)
  297. }
  298. #endif
  299. #endif