OSDN Git Service

alpha2
[eliscolors/main.git] / ElisWriterDummyView.m
1 //
2 //  ElisWriterDummyView.m
3 //  Elis Colors
4 //
5 //  Created by 柳 on 09/09/26.
6 //  Copyright 2009 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ElisWriterDummyView.h"
10
11
12 @implementation ElisWriterDummyView
13
14 - (void)awakeFromNib
15 {
16     lock = [[NSRecursiveLock alloc] init];
17     timeOffset = QTZeroTime;
18     layerSet = [[NSMutableArray alloc] init];
19     sortedLayerSet = malloc(sizeof(void*) * TRACK_SIZE);
20     [self prepareOpenGL];
21 }
22
23 - (void)finalize
24 {
25     free(sortedLayerSet);
26     [super finalize];
27 }
28
29 - (void)setMainController:(id)c
30 {
31     _mainController = c;
32 }
33
34 - (void)prepareOpenGL
35 {
36         GLint swapInterval = 1;
37     
38     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);   // black background
39         [[self openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
40     
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]];
46     
47     CGColorSpaceRelease(colorSpace);
48     
49     [self setFrame:*(NSRect*)&ProjectMovieSize];
50 //    [self setHidden:YES];
51 }
52
53 - (void)getFrameForQTTime:(QTTime)time
54 {
55     [layerSet removeAllObjects];
56     _qt = time;
57     [_mainController getFrameForTime:time result:layerSet];
58     [self drawRect:NSZeroRect];
59 }
60
61 - (void)drawRect:(NSRect)rect
62 {
63     [lock lock];
64     
65     [[self openGLContext] makeCurrentContext];
66     glClear(GL_COLOR_BUFFER_BIT);
67     
68     int i, size = [layerSet count];
69     CIImage* ci;
70     NSPoint point;
71     CGRect imageRect;
72     CGPoint cp;
73     
74     // トラック番号順にバケットソート
75     memset(sortedLayerSet, 0, sizeof(void*) * TRACK_SIZE);
76     for(i = 0; i < size; i++)
77         sortedLayerSet[[[layerSet objectAtIndex:i] trackNumber]] = [layerSet objectAtIndex:i];
78     
79     for(i = 0; i < TRACK_SIZE; i++){
80         if(sortedLayerSet[i] == 0) continue;
81         
82         ci = [sortedLayerSet[i] getEffectedImage:nil forTime:_qt];
83         point = [sortedLayerSet[i] getPositionForTime:[sortedLayerSet[i] convertToInnnerTime:_qt]];
84         if(ci == nil) continue; // サウンドレイヤーはスキップ
85         
86         imageRect = [ci extent];
87         if(imageRect.size.width >= 4000){
88             imageRect = CGRectMake(0, 0, 4000, 3000);
89         }
90         
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];
96     }
97     
98     glFlush();
99     
100     // あとかたづけ
101     for(i = 0; i < size; i++)
102         [[layerSet objectAtIndex:i] releaseContext];
103     
104     [layerSet removeAllObjects];
105     
106     [lock unlock];
107 }
108
109 - (void)reshape
110
111         GLfloat minX, minY, maxX, maxY;
112     
113     NSRect sceneBounds = [self bounds];
114         NSRect frame = [self frame];
115         
116     minX = NSMinX(sceneBounds);
117         minY = NSMinY(sceneBounds);
118         maxX = NSMaxX(sceneBounds);
119         maxY = NSMaxY(sceneBounds);
120     
121     //    if(rendering)
122     //        glViewport(0, 0, (GLsizei)ProjectMovieSize.size.width, (GLsizei)ProjectMovieSize.size.height);
123     //    else
124     glViewport(0, 0, (GLsizei)frame.size.width, (GLsizei)frame.size.height);    // set the viewport
125     
126     glMatrixMode(GL_MODELVIEW);    // select the modelview matrix
127     glLoadIdentity();              // reset it
128     
129     glMatrixMode(GL_PROJECTION);   // select the projection matrix
130     glLoadIdentity();              // reset it
131     
132     //    if(rendering)
133     //        gluOrtho2D(minX, minX + ProjectMovieSize.size.width, minY, minY + ProjectMovieSize.size.height);
134     //    else
135     gluOrtho2D(minX, maxX, minY, maxY); // define a 2-D orthographic projection matrix
136     
137     //    float scale;
138     //    if(frame.size.height < frame.size.width)
139     //        scale = frame.size.height/ProjectMovieSize.size.height;
140     //    else 
141     //        scale = frame.size.width/ProjectMovieSize.size.width;
142     
143     //    glScalef(scale, scale, 1.0);
144     
145         glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
146     glEnable(GL_BLEND);
147     
148 }
149
150 - (void)getCurrentPixelData:(NSRect)rect buffer:(void*)buffer
151 {
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);
157     
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);
160     
161     glPopClientAttrib();
162 }
163
164
165 @end