2 // ElisWriterDummyView.m
5 // Created by 柳 on 09/09/26.
6 // Copyright 2009 __MyCompanyName__. All rights reserved.
9 #import "ElisWriterDummyView.h"
12 @implementation ElisWriterDummyView
16 lock = [[NSRecursiveLock alloc] init];
17 timeOffset = QTZeroTime;
18 layerSet = [[NSMutableArray alloc] init];
19 sortedLayerSet = malloc(sizeof(void*) * TRACK_SIZE);
29 - (void)setMainController:(id)c
36 GLint swapInterval = 1;
38 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // black background
39 [[self openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
41 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
42 ciContext = [CIContext contextWithCGLContext:[[self openGLContext] CGLContextObj]
43 pixelFormat:[[self pixelFormat] CGLPixelFormatObj]
44 options:[NSDictionary dictionaryWithObjectsAndKeys:(id)colorSpace, kCIContextOutputColorSpace,
45 (id)colorSpace, kCIContextWorkingColorSpace, nil]];
47 CGColorSpaceRelease(colorSpace);
49 [self setFrame:*(NSRect*)&ProjectMovieSize];
50 // [self setHidden:YES];
53 - (void)getFrameForQTTime:(QTTime)time
55 [layerSet removeAllObjects];
57 [_mainController getFrameForTime:time result:layerSet];
58 [self drawRect:NSZeroRect];
61 - (void)drawRect:(NSRect)rect
65 [[self openGLContext] makeCurrentContext];
66 glClear(GL_COLOR_BUFFER_BIT);
68 int i, size = [layerSet count];
75 memset(sortedLayerSet, 0, sizeof(void*) * TRACK_SIZE);
76 for(i = 0; i < size; i++)
77 sortedLayerSet[[[layerSet objectAtIndex:i] trackNumber]] = [layerSet objectAtIndex:i];
79 for(i = 0; i < TRACK_SIZE; i++){
80 if(sortedLayerSet[i] == 0) continue;
82 ci = [sortedLayerSet[i] getEffectedImage:nil forTime:_qt];
83 point = [sortedLayerSet[i] getPositionForTime:[sortedLayerSet[i] convertToInnnerTime:_qt]];
84 if(ci == nil) continue; // サウンドレイヤーはスキップ
86 imageRect = [ci extent];
87 if(imageRect.size.width >= 4000){
88 imageRect = CGRectMake(0, 0, 4000, 3000);
91 cp = *(CGPoint*)&point;
92 // [ciContext drawImage:ci inRect:imageRect fromRect:CGRectMake(point.x, point.y, ProjectMovieSize.size.width, ProjectMovieSize.size.height)];
93 [ciContext drawImage:ci atPoint:cp fromRect:imageRect];
94 // [ciContext drawImage:ci inRect:CGRectMake(point.x, point.y, imageRect.size.width, imageRect.size.height)
95 // fromRect:imageRect];
101 for(i = 0; i < size; i++)
102 [[layerSet objectAtIndex:i] releaseContext];
104 [layerSet removeAllObjects];
111 GLfloat minX, minY, maxX, maxY;
113 NSRect sceneBounds = [self bounds];
114 NSRect frame = [self frame];
116 minX = NSMinX(sceneBounds);
117 minY = NSMinY(sceneBounds);
118 maxX = NSMaxX(sceneBounds);
119 maxY = NSMaxY(sceneBounds);
122 // glViewport(0, 0, (GLsizei)ProjectMovieSize.size.width, (GLsizei)ProjectMovieSize.size.height);
124 glViewport(0, 0, (GLsizei)frame.size.width, (GLsizei)frame.size.height); // set the viewport
126 glMatrixMode(GL_MODELVIEW); // select the modelview matrix
127 glLoadIdentity(); // reset it
129 glMatrixMode(GL_PROJECTION); // select the projection matrix
130 glLoadIdentity(); // reset it
133 // gluOrtho2D(minX, minX + ProjectMovieSize.size.width, minY, minY + ProjectMovieSize.size.height);
135 gluOrtho2D(minX, maxX, minY, maxY); // define a 2-D orthographic projection matrix
138 // if(frame.size.height < frame.size.width)
139 // scale = frame.size.height/ProjectMovieSize.size.height;
141 // scale = frame.size.width/ProjectMovieSize.size.width;
143 // glScalef(scale, scale, 1.0);
145 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
150 - (void)getCurrentPixelData:(NSRect)rect buffer:(void*)buffer
152 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
153 glPixelStorei(GL_PACK_ALIGNMENT, 4);
154 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
155 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
156 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
158 // glReadBuffer(GL_FRONT); // フロントバッファ(って何だろう?)からピクセルを読みに行く。
159 glReadPixels(0, 0, rect.size.width, rect.size.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer);