diff options
author | handbrake <[email protected]> | 2006-01-14 12:53:59 +0000 |
---|---|---|
committer | handbrake <[email protected]> | 2006-01-14 12:53:59 +0000 |
commit | a9a84221af31ca7d11d1aa182d8b152270203f9f (patch) | |
tree | da452de9a4d3bb509d59de4a65fe12e9fb8e7825 /macosx/PictureGLView.mm | |
parent | 939b35fc70bb688d38b086afebd8d14d8193d2c9 (diff) |
HandBrake 0.3
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/PictureGLView.mm')
-rw-r--r-- | macosx/PictureGLView.mm | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/macosx/PictureGLView.mm b/macosx/PictureGLView.mm new file mode 100644 index 000000000..72e564141 --- /dev/null +++ b/macosx/PictureGLView.mm @@ -0,0 +1,114 @@ +#include <OpenGL/gl.h> + +#include "PictureGLView.h" + +@implementation PictureGLView + +- (void) SetManager: (HBManager*) manager +{ + fManager = manager; +} + +- (void) SetTitle: (HBTitle*) title +{ + fTitle = title; + + /* This is needed as the view's size may have changed */ + [self clearGLContext]; + [self openGLContext]; +} + +- (void) ShowPicture: (int) index +{ + /* Get the picture */ + uint8_t * tmp = fManager->GetPreview( fTitle, index ); + + /* Make it be upside-down */ + if( fPicture ) free( fPicture ); + fPicture = (uint8_t*) malloc( 4 * ( fTitle->fOutWidthMax + 2 ) * + ( fTitle->fOutHeightMax + 2 ) ); + for( uint32_t i = 0; i < fTitle->fOutHeightMax + 2; i++ ) + { + memcpy( fPicture + 4 * ( fTitle->fOutWidthMax + 2 ) * i, + tmp + 4 * ( fTitle->fOutWidthMax + 2 ) * + ( fTitle->fOutHeightMax + 1 - i ), + 4 * ( fTitle->fOutWidthMax + 2 ) ); + } + free( tmp ); + + /* Grrr - should find a way to give ARGB to OpenGL */ + uint8_t r, g, b, a; + for( uint32_t i = 0; i < fTitle->fOutHeightMax + 2; i++ ) + { + for( uint32_t j = 0; j < fTitle->fOutWidthMax + 2; j++ ) + { + a = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)]; + r = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+1]; + g = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+2]; + b = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+3]; + + fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)] = r; + fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+1] = g; + fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+2] = b; + fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+3] = a; + } + } + + [self setNeedsDisplay: YES]; +} + +/* Override NSView's initWithFrame: to specify our pixel format */ +- (id) initWithFrame: (NSRect) frame +{ + fManager = NULL; + fTitle = NULL; + fPicture = NULL; + + GLuint attribs[] = + { + NSOpenGLPFANoRecovery, + NSOpenGLPFAWindow, + NSOpenGLPFAAccelerated, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAColorSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAStencilSize, 8, + NSOpenGLPFAAccumSize, 0, + 0 + }; + + NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] + initWithAttributes: (NSOpenGLPixelFormatAttribute*) attribs]; + + if( !fmt ) + { + fprintf( stderr, "Sarass\n" ); + } + + return self = [super initWithFrame:frame pixelFormat: + [fmt autorelease]]; +} + +/* Override the view's drawRect: to draw our GL content */ +- (void) drawRect: (NSRect) rect +{ + glViewport( 0, 0, (GLsizei) rect.size.width, + (GLsizei) rect.size.height ); + + /* Black background */ + glClearColor( 0, 0, 0, 0 ); + glClear( GL_COLOR_BUFFER_BIT ); + + /* Show it */ + if( fPicture ) + { + glDrawPixels( fTitle->fOutWidthMax + 2, + fTitle->fOutHeightMax + 2, GL_RGBA, + GL_UNSIGNED_BYTE, fPicture ); + } + + [[self openGLContext] flushBuffer]; +} + +@end |