Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QuickTimeUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Cinder.h"
26 #include "cinder/Url.h"
27 #include "cinder/Surface.h"
28 #include "cinder/ImageIo.h"
29 
30 #include <string>
31 
32 #if defined( CINDER_MAC )
33  #if ! defined( __LP64__ )
34  #include <QuickTime/QuickTime.h>
35  #else
36  #include <CoreVideo/CoreVideo.h>
37  #endif
38 #else
39  #pragma push_macro( "__STDC_CONSTANT_MACROS" )
40  #pragma push_macro( "_STDINT_H" )
41  #undef __STDC_CONSTANT_MACROS
42  #if _MSC_VER >= 1600 // VC10 or greater
43  #define _STDINT_H
44  #define __FP__
45  #endif
46  #include <QTML.h>
47  #include <Movies.h>
48  #pragma pop_macro( "_STDINT_H" )
49  #pragma pop_macro( "__STDC_CONSTANT_MACROS" )
50 #endif
51 
52 namespace cinder { namespace qtime {
53 
54 #if ! defined( __LP64__ )
55 bool dictionarySetValue( CFMutableDictionaryRef dict, CFStringRef key, SInt32 value );
58 bool dictionarySetPixelBufferSize( const unsigned int width, const unsigned int height, CFMutableDictionaryRef dict );
61 bool dictionarySetPixelBufferOptions( unsigned int width, unsigned int height, bool alpha, CFMutableDictionaryRef *pixelBufferOptions );
63 
64 ::Movie openMovieFromUrl( const Url &url );
65 ::Movie openMovieFromPath( const fs::path &path );
66 ::Movie openMovieFromMemory( const void *data, size_t dataSize, const std::string &fileNameHint, const std::string &mimeTypeHint );
67 
69 
71 static void CVPixelBufferDealloc( void *refcon );
73 Surface8u convertCVPixelBufferToSurface( CVPixelBufferRef pixelBufferRef );
74 
75 #endif // ! defined( __LP64__ )
76 
77 typedef std::shared_ptr<class ImageTargetCvPixelBuffer> ImageTargetCvPixelBufferRef;
78 
80  public:
81  static ImageTargetCvPixelBufferRef createRef( ImageSourceRef imageSource, bool convertToYpCbCr = false );
83 
84  virtual void* getRowPointer( int32_t row );
85  virtual void finalize();
86 
87  ::CVPixelBufferRef getCvPixelBuffer() const { return mPixelBufferRef; }
88 
89  protected:
90  ImageTargetCvPixelBuffer( ImageSourceRef imageSource, bool convertToYpCbCr );
91 
92  void convertDataToYpCbCr();
93  void convertDataToAYpCbCr();
94 
95  ::CVPixelBufferRef mPixelBufferRef;
96  size_t mRowBytes;
97  uint8_t *mData;
99 };
100 
102 CVPixelBufferRef createCvPixelBuffer( ImageSourceRef imageSource, bool convertToYpCbCr = false );
103 
104 #if defined( CINDER_MSW )
105 typedef std::shared_ptr<class ImageTargetGWorld> ImageTargetGWorldRef;
106 
107 class ImageTargetGWorld : public cinder::ImageTarget {
108  public:
109  static ImageTargetGWorldRef createRef( ImageSourceRef imageSource );
110 
111  virtual void* getRowPointer( int32_t row );
112  virtual void finalize();
113 
114  ::GWorldPtr getGWorld() const { return mGWorld; }
115 
116  protected:
117  ImageTargetGWorld( ImageSourceRef imageSource );
118 
119  ::GWorldPtr mGWorld;
120  ::PixMapHandle mPixMap;
121  size_t mRowBytes;
122  uint8_t *mData;
123 };
124 
126 GWorldPtr createGWorld( ImageSourceRef imageSource );
127 #endif // defined( CINDER_MSW )
128 
129 } } // namespace cinder::qtime
Surface8u convertCVPixelBufferToSurface(CVPixelBufferRef pixelBufferRef)
Makes a cinder::Surface form a CVPixelBufferRef, setting a proper deallocation function to free the C...
Definition: QuickTimeUtils.cpp:412
CFMutableDictionaryRef initQTVisualContextOptions(int width, int height, bool alpha)
Definition: QuickTimeUtils.cpp:117
GLsizei const GLchar ** string
Definition: GLee.h:2427
GLenum GLsizei width
Definition: GLee.h:969
void dictionarySetPixelBufferOpenGLCompatibility(CFMutableDictionaryRef dict)
Definition: QuickTimeUtils.cpp:92
size_t mRowBytes
Definition: QuickTimeUtils.h:96
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:1011
Definition: ImageIo.h:151
bool dictionarySetPixelBufferSize(const unsigned int width, const unsigned int height, CFMutableDictionaryRef dict)
Definition: QuickTimeUtils.cpp:75
::CVPixelBufferRef getCvPixelBuffer() const
Definition: QuickTimeUtils.h:87
::Movie openMovieFromMemory(const void *data, size_t dataSize, const string &fileNameHint, const string &mimeTypeHint)
Definition: QuickTimeUtils.cpp:375
void convertDataToYpCbCr()
Definition: QuickTimeUtils.cpp:519
bool dictionarySetValue(CFMutableDictionaryRef dict, CFStringRef key, SInt32 value)
Definition: QuickTimeUtils.cpp:54
GLenum GLenum GLvoid * row
Definition: GLee.h:1089
static ImageTargetCvPixelBufferRef createRef(ImageSourceRef imageSource, bool convertToYpCbCr=false)
Definition: QuickTimeUtils.cpp:438
::CVPixelBufferRef mPixelBufferRef
Definition: QuickTimeUtils.h:95
Definition: QuickTimeUtils.h:79
uint8_t * mData
Definition: QuickTimeUtils.h:97
bool dictionarySetPixelBufferPixelFormatType(bool alpha, CFMutableDictionaryRef dict)
Definition: QuickTimeUtils.cpp:68
std::shared_ptr< class ImageTargetCvPixelBuffer > ImageTargetCvPixelBufferRef
Definition: QuickTimeUtils.h:77
GLenum GLsizei GLsizei height
Definition: GLee.h:1029
GLclampf GLclampf GLclampf alpha
Definition: GLee.h:951
::Movie openMovieFromUrl(const Url &url)
Definition: QuickTimeUtils.cpp:183
void convertDataToAYpCbCr()
Definition: QuickTimeUtils.cpp:538
CVPixelBufferRef createCvPixelBuffer(ImageSourceRef imageSource, bool convertToYpCbCr=false)
Creates a CVPixelBufferRef from an ImageSource. Release the result with CVPixelBufferRelease(). If convertToYpCbCr the resulting CVPixelBuffer will be in either k444YpCbCr8CodecType or k4444YpCbCrA8PixelFormat.
Definition: QuickTimeUtils.cpp:556
ImageTargetCvPixelBuffer(ImageSourceRef imageSource, bool convertToYpCbCr)
Definition: QuickTimeUtils.cpp:443
GLsizei const GLfloat * value
Definition: GLee.h:2487
virtual void finalize()
Definition: QuickTimeUtils.cpp:504
SurfaceT< uint8_t > Surface8u
8-bit image
Definition: Surface.h:493
struct __CFDictionary * CFMutableDictionaryRef
Definition: ImageTargetFileQuartz.h:30
bool mConvertToYpCbCr
Definition: QuickTimeUtils.h:98
bool dictionarySetPixelBufferOptions(unsigned int width, unsigned int height, bool alpha, CFMutableDictionaryRef *pixelBufferOptions)
Definition: QuickTimeUtils.cpp:97
bool dictionarySetPixelBufferBytesPerRowAlignment(CFMutableDictionaryRef dict)
Definition: QuickTimeUtils.cpp:85
~ImageTargetCvPixelBuffer()
Definition: QuickTimeUtils.cpp:491
std::shared_ptr< class ImageSource > ImageSourceRef
Definition: Channel.h:33
virtual void * getRowPointer(int32_t row)
Definition: QuickTimeUtils.cpp:499
::Movie openMovieFromPath(const fs::path &path)
Definition: QuickTimeUtils.cpp:210