1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | #include <cstdlib> |
---|
35 | |
---|
36 | #include "TLibCommon/TComPicYuv.h" |
---|
37 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
38 | #include "TAppCommon/program_options_lite.h" |
---|
39 | |
---|
40 | using namespace std; |
---|
41 | namespace po = df::program_options_lite; |
---|
42 | |
---|
43 | int main(int argc, const char** argv) |
---|
44 | { |
---|
45 | bool do_help; |
---|
46 | string filename_in, filename_out; |
---|
47 | unsigned int width, height; |
---|
48 | unsigned int bitdepth_in, bitdepth_out; |
---|
49 | unsigned int num_frames; |
---|
50 | unsigned int num_frames_skip; |
---|
51 | |
---|
52 | po::Options opts; |
---|
53 | opts.addOptions() |
---|
54 | ("help", do_help, false, "this help text") |
---|
55 | ("InputFile,i", filename_in, string(""), "input file to convert") |
---|
56 | ("OutputFile,o", filename_out, string(""), "output file") |
---|
57 | ("SourceWidth", width, 0u, "source picture width") |
---|
58 | ("SourceHeight", height, 0u, "source picture height") |
---|
59 | ("InputBitDepth", bitdepth_in, 8u, "bit-depth of input file") |
---|
60 | ("OutputBitDepth", bitdepth_out, 8u, "bit-depth of output file") |
---|
61 | ("NumFrames", num_frames, 0xffffffffu, "number of frames to process") |
---|
62 | ("FrameSkip,-fs", num_frames_skip, 0u, "Number of frames to skip at start of input YUV") |
---|
63 | ; |
---|
64 | |
---|
65 | po::setDefaults(opts); |
---|
66 | po::scanArgv(opts, argc, argv); |
---|
67 | |
---|
68 | if (argc == 1 || do_help) |
---|
69 | { |
---|
70 | /* argc == 1: no options have been specified */ |
---|
71 | po::doHelp(cout, opts); |
---|
72 | return EXIT_FAILURE; |
---|
73 | } |
---|
74 | |
---|
75 | TVideoIOYuv input; |
---|
76 | TVideoIOYuv output; |
---|
77 | |
---|
78 | input.open((char*)filename_in.c_str(), false, bitdepth_in, bitdepth_in, bitdepth_out, bitdepth_out); |
---|
79 | output.open((char*)filename_out.c_str(), true, bitdepth_out, bitdepth_out, bitdepth_out, bitdepth_out); |
---|
80 | |
---|
81 | input.skipFrames(num_frames_skip, width, height); |
---|
82 | |
---|
83 | TComPicYuv frame; |
---|
84 | frame.create( width, height, 1, 1, 0 ); |
---|
85 | |
---|
86 | int pad[2] = {0, 0}; |
---|
87 | |
---|
88 | unsigned int num_frames_processed = 0; |
---|
89 | while (!input.isEof()) |
---|
90 | { |
---|
91 | if (! input.read(&frame, pad)) |
---|
92 | { |
---|
93 | break; |
---|
94 | } |
---|
95 | #if 0 |
---|
96 | Pel* img = frame.getLumaAddr(); |
---|
97 | for (int y = 0; y < height; y++) |
---|
98 | { |
---|
99 | for (int x = 0; x < height; x++) |
---|
100 | img[x] = 0; |
---|
101 | img += frame.getStride(); |
---|
102 | } |
---|
103 | img = frame.getLumaAddr(); |
---|
104 | img[0] = 1; |
---|
105 | #endif |
---|
106 | |
---|
107 | output.write(&frame); |
---|
108 | num_frames_processed++; |
---|
109 | if (num_frames_processed == num_frames) |
---|
110 | break; |
---|
111 | } |
---|
112 | |
---|
113 | input.close(); |
---|
114 | output.close(); |
---|
115 | |
---|
116 | return EXIT_SUCCESS; |
---|
117 | } |
---|