source: 3DVCSoftware/trunk/source/App/utils/convert_NtoMbit_YCbCr.cpp @ 1417

Last change on this file since 1417 was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
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-2017, 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
40using namespace std;
41namespace po = df::program_options_lite;
42
43Int main(Int argc, const char** argv)
44{
45  Bool do_help;
46  string filename_in, filename_out;
47  UInt width, height;
48  UInt bitdepth_in, bitdepth_out, chromaFormatRaw;
49  UInt num_frames;
50  UInt 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  ("ChromaFormat", chromaFormatRaw, 420u, "chroma format. 400, 420, 422 or 444 only")
62  ("NumFrames", num_frames, 0xffffffffu, "number of frames to process")
63  ("FrameSkip,-fs", num_frames_skip, 0u, "Number of frames to skip at start of input YUV")
64  ;
65
66  po::setDefaults(opts);
67  po::scanArgv(opts, argc, argv);
68
69
70  if (argc == 1 || do_help)
71  {
72    /* argc == 1: no options have been specified */
73    po::doHelp(cout, opts);
74    return EXIT_FAILURE;
75  }
76
77  ChromaFormat chromaFormatIDC=CHROMA_420;
78  switch (chromaFormatRaw)
79  {
80    case 400: chromaFormatIDC=CHROMA_400; break;
81    case 420: chromaFormatIDC=CHROMA_420; break;
82    case 422: chromaFormatIDC=CHROMA_422; break;
83    case 444: chromaFormatIDC=CHROMA_444; break;
84    default:
85      fprintf(stderr, "Bad chroma format string\n");
86      return EXIT_FAILURE;
87  }
88
89  TVideoIOYuv input;
90  TVideoIOYuv output;
91
92  Int inputBitDepths [MAX_NUM_CHANNEL_TYPE];
93  Int outputBitDepths[MAX_NUM_CHANNEL_TYPE];
94
95  for (UInt channelTypeIndex = 0; channelTypeIndex < MAX_NUM_CHANNEL_TYPE; channelTypeIndex++)
96  {
97    inputBitDepths [channelTypeIndex] = bitdepth_in;
98    outputBitDepths[channelTypeIndex] = bitdepth_out;
99  }
100
101  input.open((char*)filename_in.c_str(), false, inputBitDepths, inputBitDepths, outputBitDepths);
102  output.open((char*)filename_out.c_str(), true, outputBitDepths, outputBitDepths, outputBitDepths);
103
104  input.skipFrames(num_frames_skip, width, height, chromaFormatIDC);
105
106  TComPicYuv frame;
107  frame.createWithoutCUInfo( width, height, chromaFormatIDC);
108
109  Int pad[2] = {0, 0};
110
111  TComPicYuv cPicYuvTrueOrg;
112  cPicYuvTrueOrg.createWithoutCUInfo( width, height, chromaFormatIDC );
113
114  UInt num_frames_processed = 0;
115  while (!input.isEof())
116  {
117    if (! input.read(&frame, &cPicYuvTrueOrg, IPCOLOURSPACE_UNCHANGED, pad))
118    {
119      break;
120    }
121#if 0
122    Pel* img = frame.getAddr(COMPONENT_Y);
123    for (Int y = 0; y < height; y++)
124    {
125      for (Int x = 0; x < height; x++)
126      {
127        img[x] = 0;
128      }
129      img += frame.getStride();
130    }
131    img = frame.getAddr(COMPONENT_Y);
132    img[0] = 1;
133#endif
134
135    output.write(&frame, IPCOLOURSPACE_UNCHANGED);
136    num_frames_processed++;
137    if (num_frames_processed == num_frames)
138    {
139      break;
140    }
141  }
142
143  input.close();
144  output.close();
145  cPicYuvTrueOrg.destroy();
146
147  return EXIT_SUCCESS;
148}
Note: See TracBrowser for help on using the repository browser.