5 // Created by 柳 on 09/09/17.
6 // Copyright 2009 __MyCompanyName__. All rights reserved.
10 #import "ElisController.h"
12 @implementation ElisWriter
18 imageQuality = [NSNumber numberWithLong:codecMaxQuality];
19 gamma_table = malloc(sizeof(unsigned char) * 256);
29 - (void)setContoller:(id)c
34 - (void)write:(NSString*)path
36 int frame, i, size, totalFrames;
40 unsigned char *buffer, *pixels;
43 NSBitmapImageRep* rep;
45 [self initializeMovie:path];
46 seconds = [_mainController getHipTime];
47 totalFrames = seconds * fps;
48 w = ProjectMovieSize.size.width;
49 h = ProjectMovieSize.size.height;
50 rect = *(NSRect*)&ProjectMovieSize;
52 buffer = malloc(w*h*3*sizeof(unsigned char));
53 pixels = malloc(w*h*3*sizeof(unsigned char));
55 attrs = [NSDictionary dictionaryWithObjectsAndKeys:imageCodec, QTAddImageCodecType,
56 imageQuality, QTAddImageCodecQuality,
59 [self readyGammmaTable];
61 for(frame = 1; frame < 300/*totalFrames*/; frame++){
63 now = QTMakeTime(frame, fps);
64 [_mainView getFrameForQTTime:now];
65 [_mainView getCurrentPixelData:rect buffer:buffer];
67 for(i = 0; i < h; i++) // 富豪的に上下反転。テラ強引
68 memcpy(&pixels[i*w*3], &buffer[(h-1-i)*w*3], w*3*sizeof(unsigned char));
70 [self gammaAdjust:pixels size:w*h*3]; // 色味がシフトする分をガンマ補正。これはひどい。
72 rep = [[NSBitmapImageRep alloc] // RGB RGB RGB ... なバイト列からBitMapImageRepをつくる。
73 initWithBitmapDataPlanes:&pixels
80 colorSpaceName:NSCalibratedRGBColorSpace
81 bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
85 image = [[NSImage alloc] init];
86 [image addRepresentation:rep];
87 [outputMovie addImage:image forDuration:QTMakeTime(1, fps) withAttributes:attrs];
93 [outputMovie updateMovieFile];
96 - (void)initializeMovie:(NSString*)path
98 outputMovie = [[QTMovie alloc] initToWritableFile:path error:nil];
107 - (void)readyGammmaTable
111 for(i = 0; i < 256; i++)
112 gamma_table[i] = (unsigned char)255.0 * pow(i/255.0, 1.0/GAMMA);
115 - (void)gammaAdjust:(unsigned char*)pixels size:(int)s
118 for(i = 0; i < s; i++)
119 pixels[i] = gamma_table[pixels[i]];