summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/output/yuvDumper.cpp
blob: 1962b1515209a24f74ae42d0f867c0f4842724d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
  writes yuv images on HD
  Copyright (C) 2000  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#include "yuvDumper.h"

YUVDumper::YUVDumper() {
  picCnt=1;
  method=_DUMP_YUV_AS_STREAM;
}

YUVDumper::~YUVDumper() {
}


int YUVDumper::openWindow(int w, int h,const char*) {
  
  FILE* formatFile=fopen("stream.yuv.format","w+");
  fprintf(formatFile,"Version 0.1\nw:%dh:%d\n",w,h);
  fclose(formatFile);



  if (method == _DUMP_YUV_AS_STREAM) {
    FILE* outFile=fopen("stream.yuv","w+");
    fclose(outFile);
  }
 return true;
}

void YUVDumper::closeWindow() {
}


void YUVDumper::flushWindow() {
}


int YUVDumper::getMethod() {
  return method;
}


void YUVDumper::setMethod(int method) {
  this->method=method;
}

void YUVDumper::unlockPictureArray(PictureArray* pictureArray) {
  YUVPicture* pic=pictureArray->getYUVPictureCallback();
  if (pic == NULL) {
    return;
  }

  FILE* outFile=NULL;

  if (method == _DUMP_YUV_AS_STREAM) {
    outFile=fopen("stream.yuv","a+");
  }

  if (outFile == NULL) {
      perror("fopen");
      return;
  }

  int lumSize=pic->getLumLength();
  int colorSize=pic->getColorLength();
  fwrite(pic->getLuminancePtr(),1,lumSize,outFile);
  fwrite(pic->getCrPtr(),1,colorSize,outFile);
  fwrite(pic->getCbPtr(),1,colorSize,outFile);
  fclose(outFile);

}