HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
convert_NtoMbit_YCbCr.cpp
Go to the documentation of this file.
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"
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  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 }
YUV file I/O class.
Definition: TVideoIOYuv.h:54
Bool write(TComPicYuv *pPicYuv, const InputColourSpaceConversion ipCSC, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0, ChromaFormat fileFormat=NUM_CHROMA_FORMAT, const Bool bClipToRec709=false)
write one YUV frame with padding parameter
picture YUV buffer class
Definition: TComPicYuv.h:55
void doHelp(ostream &out, Options &opts, unsigned columns)
Int getStride(const ComponentID id) const
Definition: TComPicYuv.h:121
Void open(const std::string &fileName, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE])
open or create file
Void createWithoutCUInfo(const Int picWidth, const Int picHeight, const ChromaFormat chromaFormatIDC, const Bool bUseMargin=false, const UInt maxCUWidth=0, const UInt maxCUHeight=0)
used for margin only
Definition: TComPicYuv.cpp:81
unsigned int UInt
Definition: TypeDef.h:212
Short Pel
pixel type
Definition: TypeDef.h:249
Bool isEof()
check for end-of-file
list< const char * > scanArgv(Options &opts, unsigned argc, const char *argv[], ErrorReporter &error_reporter)
YUV file I/O class (header)
bool Bool
Definition: TypeDef.h:204
int main(int argc, char *argv[])
Definition: decmain.cpp:50
Void close()
close file
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:292
picture YUV buffer class (header)
Bool read(TComPicYuv *pPicYuv, TComPicYuv *pPicYuvTrueOrg, const InputColourSpaceConversion ipcsc, Int aiPad[2], ChromaFormat fileFormat=NUM_CHROMA_FORMAT, const Bool bClipToRec709=false)
read one frame with padding parameter
Pel * getAddr(const ComponentID ch)
Definition: TComPicYuv.h:139
int Int
Definition: TypeDef.h:211
Void skipFrames(Int numFrames, UInt width, UInt height, ChromaFormat format)
Void destroy()
Definition: TComPicYuv.cpp:168