[56] | 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 |
---|
[1313] | 4 | * granted under this license. |
---|
[56] | 5 | * |
---|
[1413] | 6 | * Copyright (c) 2010-2017, ITU/ISO/IEC |
---|
[56] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | #include <cstdlib> |
---|
| 35 | |
---|
| 36 | #include "TLibCommon/TComPicYuv.h" |
---|
| 37 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
[56] | 38 | #include "TAppCommon/program_options_lite.h" |
---|
[2] | 39 | |
---|
| 40 | using namespace std; |
---|
| 41 | namespace po = df::program_options_lite; |
---|
| 42 | |
---|
[1313] | 43 | Int main(Int argc, const char** argv) |
---|
[2] | 44 | { |
---|
[1313] | 45 | Bool do_help; |
---|
[2] | 46 | string filename_in, filename_out; |
---|
[1313] | 47 | UInt width, height; |
---|
| 48 | UInt bitdepth_in, bitdepth_out, chromaFormatRaw; |
---|
| 49 | UInt num_frames; |
---|
| 50 | UInt num_frames_skip; |
---|
[2] | 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") |
---|
[1313] | 61 | ("ChromaFormat", chromaFormatRaw, 420u, "chroma format. 400, 420, 422 or 444 only") |
---|
[2] | 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 | |
---|
[1313] | 69 | |
---|
[2] | 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 | |
---|
[1313] | 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 | |
---|
[2] | 89 | TVideoIOYuv input; |
---|
| 90 | TVideoIOYuv output; |
---|
| 91 | |
---|
[1313] | 92 | Int inputBitDepths [MAX_NUM_CHANNEL_TYPE]; |
---|
| 93 | Int outputBitDepths[MAX_NUM_CHANNEL_TYPE]; |
---|
[2] | 94 | |
---|
[1313] | 95 | for (UInt channelTypeIndex = 0; channelTypeIndex < MAX_NUM_CHANNEL_TYPE; channelTypeIndex++) |
---|
| 96 | { |
---|
| 97 | inputBitDepths [channelTypeIndex] = bitdepth_in; |
---|
| 98 | outputBitDepths[channelTypeIndex] = bitdepth_out; |
---|
| 99 | } |
---|
[2] | 100 | |
---|
[1313] | 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 | |
---|
[2] | 106 | TComPicYuv frame; |
---|
[1386] | 107 | frame.createWithoutCUInfo( width, height, chromaFormatIDC); |
---|
[2] | 108 | |
---|
[1313] | 109 | Int pad[2] = {0, 0}; |
---|
[2] | 110 | |
---|
[1313] | 111 | TComPicYuv cPicYuvTrueOrg; |
---|
[1386] | 112 | cPicYuvTrueOrg.createWithoutCUInfo( width, height, chromaFormatIDC ); |
---|
[1313] | 113 | |
---|
| 114 | UInt num_frames_processed = 0; |
---|
| 115 | while (!input.isEof()) |
---|
[56] | 116 | { |
---|
[1313] | 117 | if (! input.read(&frame, &cPicYuvTrueOrg, IPCOLOURSPACE_UNCHANGED, pad)) |
---|
[56] | 118 | { |
---|
| 119 | break; |
---|
| 120 | } |
---|
[2] | 121 | #if 0 |
---|
[1313] | 122 | Pel* img = frame.getAddr(COMPONENT_Y); |
---|
| 123 | for (Int y = 0; y < height; y++) |
---|
[56] | 124 | { |
---|
[1313] | 125 | for (Int x = 0; x < height; x++) |
---|
| 126 | { |
---|
[2] | 127 | img[x] = 0; |
---|
[1313] | 128 | } |
---|
[2] | 129 | img += frame.getStride(); |
---|
| 130 | } |
---|
[1313] | 131 | img = frame.getAddr(COMPONENT_Y); |
---|
[2] | 132 | img[0] = 1; |
---|
| 133 | #endif |
---|
| 134 | |
---|
[1313] | 135 | output.write(&frame, IPCOLOURSPACE_UNCHANGED); |
---|
[2] | 136 | num_frames_processed++; |
---|
| 137 | if (num_frames_processed == num_frames) |
---|
[1313] | 138 | { |
---|
[2] | 139 | break; |
---|
[1313] | 140 | } |
---|
[2] | 141 | } |
---|
| 142 | |
---|
| 143 | input.close(); |
---|
| 144 | output.close(); |
---|
[1313] | 145 | cPicYuvTrueOrg.destroy(); |
---|
[2] | 146 | |
---|
| 147 | return EXIT_SUCCESS; |
---|
| 148 | } |
---|