include/cinder/qtime/QuickTimeUtils.h
Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2010, The Barbarian Group
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00006  the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and
00009     the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00011     the following disclaimer in the documentation and/or other materials provided with the distribution.
00012 
00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00014  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00015  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00016  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00017  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00018  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00019  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00020  POSSIBILITY OF SUCH DAMAGE.
00021 */
00022 
00023 #pragma once
00024 
00025 #include "cinder/Cinder.h"
00026 #include "cinder/Url.h"
00027 #include "cinder/Surface.h"
00028 #include "cinder/ImageIo.h"
00029 
00030 #include <string>
00031 
00032 #if defined( CINDER_MAC )
00033     #if ! defined( __LP64__ )
00034         #include <QuickTime/QuickTime.h>
00035     #else
00036         #include <CoreVideo/CoreVideo.h>
00037     #endif
00038 #else
00039     #pragma push_macro( "__STDC_CONSTANT_MACROS" )
00040     #pragma push_macro( "_STDINT_H" )
00041         #undef __STDC_CONSTANT_MACROS
00042         #if _MSC_VER >= 1600 // VC10 or greater
00043             #define _STDINT_H
00044         #endif
00045         #include <QTML.h>
00046         #include <Movies.h>
00047     #pragma pop_macro( "_STDINT_H" )
00048     #pragma pop_macro( "__STDC_CONSTANT_MACROS" )
00049 #endif
00050 
00051 namespace cinder { namespace qtime {
00052 
00053 #if ! defined( __LP64__ )
00054 
00055 bool dictionarySetValue( CFMutableDictionaryRef dict, CFStringRef key, SInt32 value );
00056 bool dictionarySetPixelBufferPixelFormatType( bool alpha, CFMutableDictionaryRef dict );
00057 bool dictionarySetPixelBufferSize( const unsigned int width, const unsigned int height, CFMutableDictionaryRef dict );
00058 bool dictionarySetPixelBufferBytesPerRowAlignment( CFMutableDictionaryRef dict );
00059 void dictionarySetPixelBufferOpenGLCompatibility( CFMutableDictionaryRef dict );
00060 bool dictionarySetPixelBufferOptions( unsigned int width, unsigned int height, bool alpha, CFMutableDictionaryRef *pixelBufferOptions );
00061 CFMutableDictionaryRef initQTVisualContextOptions( int width, int height, bool alpha );
00062 
00063 ::Movie openMovieFromUrl( const Url &url );
00064 ::Movie openMovieFromPath( const fs::path &path );
00065 ::Movie openMovieFromMemory( const void *data, size_t dataSize, const std::string &fileNameHint, const std::string &mimeTypeHint );
00066 
00068 
00070 static void CVPixelBufferDealloc( void *refcon );
00072 Surface8u convertCVPixelBufferToSurface( CVPixelBufferRef pixelBufferRef );
00073 
00074 #endif // ! defined( __LP64__ )
00075 
00076 typedef std::shared_ptr<class ImageTargetCvPixelBuffer> ImageTargetCvPixelBufferRef;
00077 
00078 class ImageTargetCvPixelBuffer : public ci::ImageTarget {
00079   public:
00080     static ImageTargetCvPixelBufferRef createRef( ImageSourceRef imageSource, bool convertToYpCbCr = false );
00081     ~ImageTargetCvPixelBuffer();
00082 
00083     virtual void*       getRowPointer( int32_t row );
00084     virtual void        finalize();
00085 
00086     ::CVPixelBufferRef  getCvPixelBuffer() const { return mPixelBufferRef; }
00087 
00088   protected:
00089     ImageTargetCvPixelBuffer( ImageSourceRef imageSource, bool convertToYpCbCr );
00090     
00091     void        convertDataToYpCbCr();
00092     void        convertDataToAYpCbCr();
00093 
00094     ::CVPixelBufferRef  mPixelBufferRef;
00095     size_t              mRowBytes;
00096     uint8_t             *mData;
00097     bool                mConvertToYpCbCr;
00098 };
00099 
00101 CVPixelBufferRef createCvPixelBuffer( ImageSourceRef imageSource, bool convertToYpCbCr = false );
00102 
00103 #if defined( CINDER_MSW )
00104 typedef std::shared_ptr<class ImageTargetGWorld> ImageTargetGWorldRef;
00105 
00106 class ImageTargetGWorld : public ci::ImageTarget {
00107   public:
00108     static ImageTargetGWorldRef createRef( ImageSourceRef imageSource );
00109 
00110     virtual void*       getRowPointer( int32_t row );
00111     virtual void        finalize();
00112 
00113     ::GWorldPtr         getGWorld() const { return mGWorld; }
00114 
00115   protected:
00116     ImageTargetGWorld( ImageSourceRef imageSource );
00117     
00118     ::GWorldPtr         mGWorld;
00119     ::PixMapHandle      mPixMap;
00120     size_t              mRowBytes;
00121     uint8_t             *mData;
00122 };
00123 
00125 GWorldPtr createGWorld( ImageSourceRef imageSource );
00126 #endif // defined( CINDER_MSW )
00127 
00128 } } // namespace cinder::qtime