1 /* ***** BEGIN LICENSE BLOCK *****
7 * Copyright (c) 2008 BBC Research
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * ***** END LICENSE BLOCK ***** */
30 #include "rawIO16P4.h"
32 RawFrame
& RawReader16P4::read(RawFrame
& f
)
34 assert(f
.chroma
== RawFrame::Cr444
);
35 const int line_len
= f
.luma
.width() * 2;
36 unsigned char* in_line
= new unsigned char[line_len
];
40 for (int y
= 0; y
< f
.luma
.height(); y
++) {
41 if (fread(in_line
, line_len
, 1, file
) < 1)
44 for (int x
= 0; x
< f
.luma
.width(); x
++, ptr
+=2)
45 f
.luma
[y
][x
] = ((ptr
[0] << 8) | ptr
[1]);
49 const int chroma_line_len
= line_len
;
50 for (int y
= 0; y
< f
.cb
.height(); y
++) {
51 if (fread(in_line
, chroma_line_len
, 1, file
) < 1)
54 for (int x
= 0; x
< f
.cb
.width(); x
++, ptr
+=2)
55 f
.cb
[y
][x
] = ((ptr
[0] << 8) | ptr
[1]);
59 for (int y
= 0; y
< f
.cr
.height(); y
++) {
60 if (fread(in_line
, chroma_line_len
, 1, file
) < 1)
63 for (int x
= 0; x
< f
.cr
.width(); x
++, ptr
+=2)
64 f
.cr
[y
][x
] = ((ptr
[0] << 8) | ptr
[1]);
71 RawFrame
& RawReader16P4::read()
76 void RawWriter16P4::write(const RawFrame
& f
) const
78 assert(f
.chroma
== RawFrame::Cr444
);
79 const int line_len
= f
.luma
.width() * 2;
80 unsigned char* out_line
= new unsigned char[line_len
];
83 /* write luma plane */
84 for (int y
= 0; y
< f
.luma
.height(); y
++) {
86 for (int x
= 0; x
< f
.luma
.width(); x
++, ptr
+=2) {
91 fwrite(out_line
, line_len
, 1, file
);
95 const int chroma_line_len
= line_len
;
96 for (int y
= 0; y
< f
.cb
.height(); y
++) {
98 for (int x
= 0; x
< f
.cb
.width(); x
++, ptr
+=2) {
103 fwrite(out_line
, chroma_line_len
, 1, file
);
107 for (int y
= 0; y
< f
.cr
.height(); y
++) {
109 for (int x
= 0; x
< f
.cr
.width(); x
++, ptr
+=2) {
114 fwrite(out_line
, chroma_line_len
, 1, file
);