1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
31 YUVOutput::YUVOutput(const char *filename
, int w
, int h
, uint32_t d
, int csp
)
38 ofs
.open(filename
, ios::binary
| ios::out
);
39 buf
= new char[width
];
41 for (int i
= 0; i
< x265_cli_csps
[colorSpace
].planes
; i
++)
43 frameSize
+= (uint32_t)((width
>> x265_cli_csps
[colorSpace
].width
[i
]) * (height
>> x265_cli_csps
[colorSpace
].height
[i
]));
47 YUVOutput::~YUVOutput()
53 bool YUVOutput::writePicture(const x265_picture
& pic
)
55 uint64_t fileOffset
= pic
.poc
;
56 fileOffset
*= frameSize
;
58 X265_CHECK(pic
.colorSpace
== colorSpace
, "invalid color space\n");
59 X265_CHECK(pic
.bitDepth
== (int)depth
, "invalid bit depth\n");
64 int shift
= pic
.bitDepth
- 8;
65 ofs
.seekp((std::streamoff
)fileOffset
);
66 for (int i
= 0; i
< x265_cli_csps
[colorSpace
].planes
; i
++)
68 uint16_t *src
= (uint16_t*)pic
.planes
[i
];
69 for (int h
= 0; h
< height
>> x265_cli_csps
[colorSpace
].height
[i
]; h
++)
71 for (int w
= 0; w
< width
>> x265_cli_csps
[colorSpace
].width
[i
]; w
++)
73 buf
[w
] = (char)(src
[w
] >> shift
);
76 ofs
.write(buf
, width
>> x265_cli_csps
[colorSpace
].width
[i
]);
77 src
+= pic
.stride
[i
] / sizeof(*src
);
83 ofs
.seekp((std::streamoff
)(fileOffset
* 2));
84 for (int i
= 0; i
< x265_cli_csps
[colorSpace
].planes
; i
++)
86 uint16_t *src
= (uint16_t*)pic
.planes
[i
];
87 for (int h
= 0; h
< height
>> x265_cli_csps
[colorSpace
].height
[i
]; h
++)
89 ofs
.write((const char*)src
, (width
* 2) >> x265_cli_csps
[colorSpace
].width
[i
]);
90 src
+= pic
.stride
[i
] / sizeof(*src
);
94 #else // if HIGH_BIT_DEPTH
95 ofs
.seekp((std::streamoff
)fileOffset
);
96 for (int i
= 0; i
< x265_cli_csps
[colorSpace
].planes
; i
++)
98 char *src
= (char*)pic
.planes
[i
];
99 for (int h
= 0; h
< height
>> x265_cli_csps
[colorSpace
].height
[i
]; h
++)
101 ofs
.write(src
, width
>> x265_cli_csps
[colorSpace
].width
[i
]);
102 src
+= pic
.stride
[i
] / sizeof(*src
);
106 #endif // if HIGH_BIT_DEPTH