| 1 |
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. |
| 2 |
* |
| 3 |
* Redistribution and use in source and binary forms, with or without |
| 4 |
* modification, are permitted provided that the following conditions |
| 5 |
* are met: |
| 6 |
* * Redistributions of source code must retain the above copyright |
| 7 |
* notice, this list of conditions and the following disclaimer. |
| 8 |
* * Redistributions in binary form must reproduce the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer in the |
| 10 |
* documentation and/or other materials provided with the distribution. |
| 11 |
* * Neither the name of NVIDIA CORPORATION nor the names of its |
| 12 |
* contributors may be used to endorse or promote products derived |
| 13 |
* from this software without specific prior written permission. |
| 14 |
* |
| 15 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| 16 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 19 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifndef _NVMEDIA_TEST_IMAGE_UTILS_H_ |
| 29 |
#define _NVMEDIA_TEST_IMAGE_UTILS_H_ |
| 30 |
|
| 31 |
#ifdef __cplusplus |
| 32 |
extern "C" { |
| 33 |
#endif |
| 34 |
|
| 35 |
#include "misc_utils.h" |
| 36 |
#include "nvmedia_core.h" |
| 37 |
#include "nvmedia_surface.h" |
| 38 |
#include "nvmedia_image.h" |
| 39 |
#include "cmdline.h" |
| 40 |
|
| 41 |
#if (NV_IS_SAFETY == 1) |
| 42 |
#include "nvmedia_image_internal.h" |
| 43 |
#endif |
| 44 |
|
| 45 |
#define PACK_RGBA(R, G, B, A) (((uint32_t)(A) << 24) | ((uint32_t)(B) << 16) | \ |
| 46 |
((uint32_t)(G) << 8) | (uint32_t)(R)) |
| 47 |
#define DEFAULT_ALPHA 0x80 |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
// ReadImage |
| 53 |
// |
| 54 |
// ReadImage() Read image from file |
| 55 |
// |
| 56 |
// Arguments: |
| 57 |
// |
| 58 |
// filename |
| 59 |
// (in) Input file name |
| 60 |
// |
| 61 |
// frameNum |
| 62 |
// (in) Frame number to read. Use for stream input files. |
| 63 |
// |
| 64 |
// width |
| 65 |
// (in) Surface width |
| 66 |
// |
| 67 |
// height |
| 68 |
// (in) Surface height |
| 69 |
// |
| 70 |
// image |
| 71 |
// (out) Pointer to pre-allocated output surface |
| 72 |
// |
| 73 |
// uvOrderFlag |
| 74 |
// (in) Flag for UV order. If true - UV; If false - VU; |
| 75 |
// |
| 76 |
// bytesPerPixel |
| 77 |
// (in) Bytes per pixel. Nedded for RAW image types handling. |
| 78 |
// RAW8 - 1 byte per pixel |
| 79 |
// RAW10, RAW12, RAW14 - 2 bytes per pixel |
| 80 |
// |
| 81 |
// pixelAlignment |
| 82 |
// (in) Alignment of bits in pixel. |
| 83 |
// 0 - LSB Aligned |
| 84 |
// 1 - MSB Aligned |
| 85 |
|
| 86 |
NvMediaStatus |
| 87 |
ReadImage( |
| 88 |
char *fileName, |
| 89 |
uint32_t frameNum, |
| 90 |
uint32_t width, |
| 91 |
uint32_t height, |
| 92 |
NvMediaImage *image, |
| 93 |
NvMediaBool uvOrderFlag, |
| 94 |
uint32_t bytesPerPixel, |
| 95 |
uint32_t pixelAlignment); |
| 96 |
|
| 97 |
// InitImage |
| 98 |
// |
| 99 |
// InitImage() Init image data to zeros |
| 100 |
// |
| 101 |
// Arguments: |
| 102 |
// |
| 103 |
// image |
| 104 |
// (in) image to initialize |
| 105 |
// |
| 106 |
// width |
| 107 |
// (in) Surface width |
| 108 |
// |
| 109 |
// height |
| 110 |
// (in) Surface height |
| 111 |
|
| 112 |
NvMediaStatus |
| 113 |
InitImage( |
| 114 |
NvMediaImage *image, |
| 115 |
uint32_t width, |
| 116 |
uint32_t height); |
| 117 |
|
| 118 |
NvMediaStatus |
| 119 |
AllocateBufferToWriteImage( |
| 120 |
Blit2DTest *ctx, |
| 121 |
NvMediaImage *image, |
| 122 |
NvMediaBool uvOrderFlag, |
| 123 |
NvMediaBool appendFlag); |
| 124 |
|
| 125 |
// WriteImageToBuffer |
| 126 |
// |
| 127 |
// WriteImageToBuffer() Save RGB or YUV image |
| 128 |
// |
| 129 |
NvMediaStatus |
| 130 |
WriteImageToAllocatedBuffer( |
| 131 |
Blit2DTest *ctx, |
| 132 |
NvMediaImage *image, |
| 133 |
NvMediaBool uvOrderFlag, |
| 134 |
NvMediaBool appendFlag, |
| 135 |
uint32_t bytesPerPixel); |
| 136 |
|
| 137 |
#ifdef __cplusplus |
| 138 |
} |
| 139 |
#endif |
| 140 |
|
| 141 |
#endif /* _NVMEDIA_TEST_IMAGE_UTILS_H_ */ |