fixed rendering

This commit is contained in:
Diego Waxemberg
2014-01-18 19:14:57 -05:00
parent 029d3b0a97
commit f97fe7fce2
9 changed files with 89 additions and 72 deletions

View File

@@ -18,19 +18,16 @@
CGColorSpaceRef colorSpace;
CGContextRef bitmapContext;
CGImageRef image;
UIImage *uiImage;
unsigned char* pixelData;
}
static bool firstFrame = true;
-(id)init
{
NSLog(@"init");
return [super init];
}
- (void)awakeFromNib
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"awakeFromNib");
self = [super initWithFrame:frame];
NSLog(@"initWithFrame");
// Initialization code
width = 1280;
height = 720;
@@ -38,21 +35,18 @@
bytesPerRow = (bitsPerComponent / 8) * width * 4;
pixelData = malloc(width * height * 4);
colorSpace = CGColorSpaceCreateDeviceRGB();
bitmapContext = CGBitmapContextCreate(NULL, 1280, 720, 8, 5120, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipLast);
image = CGBitmapContextCreateImage(bitmapContext);
uiImage = [UIImage imageWithCGImage:image];
//VideoRenderer* renderer = [[VideoRenderer alloc]initWithTarget:self];
//NSOperationQueue* opQueue = [[NSOperationQueue alloc]init];
//[opQueue addOperation:renderer];
[self setNeedsDisplay];
//bitmapContext = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGBitmapByteOrderDefault);
//image = CGBitmapContextCreateImage(bitmapContext);
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
NSLog(@"drawRect");
if (!nv_avc_get_rgb_frame(pixelData, width*height*4))
@@ -60,10 +54,31 @@
return;
}
if (firstFrame) {
NSData *data = [[NSData alloc] initWithBytes:pixelData length:(width*height*4)];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"MyFile"];
[data writeToFile:appFile atomically:YES];
NSLog(@"writing data to: %@",documentsDirectory);
firstFrame = false;
}
bitmapContext = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
image = CGBitmapContextCreateImage(bitmapContext);
struct CGContext* context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, 1280, 720), image);
CGContextTranslateCTM(context, 0, rect.size.width);
CGContextScaleCTM(context, (float)width / self.frame.size.width, (float)height / -self.frame.size.height);
CGContextDrawImage(context, rect, image);
CGImageRelease(image);
[super drawRect:rect];
}