Debian Codegraph @

Samples/2_Concepts_and_Techniques/dct8x8/BmpUtil.h

raw
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 /**
29 **************************************************************************
30 * \file BmpUtil.h
31 * \brief Contains basic image operations declaration.
32 *
33 * This file contains declaration of basic bitmap loading, saving,
34 * conversions to different representations and memory management routines.
35 */
36
37 #pragma once
38
39 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
40 #pragma pack(push)
41 #endif
42
43 #pragma pack(1)
44
45 typedef char int8;
46 typedef short int16;
47 typedef int int32;
48 typedef unsigned char uint8;
49 typedef unsigned short uint16;
50 typedef unsigned int uint32;
51
52 /**
53 * \brief Bitmap file header structure
54 *
55 * Bitmap file header structure
56 */
57 typedef struct {
58 uint16 _bm_signature; //!< File signature, must be "BM"
59 uint32 _bm_file_size; //!< File size
60 uint32 _bm_reserved; //!< Reserved, must be zero
61 uint32 _bm_bitmap_data; //!< Bitmap data
62 } BMPFileHeader;
63
64 /**
65 * \brief Bitmap info header structure
66 *
67 * Bitmap info header structure
68 */
69 typedef struct {
70 uint32 _bm_info_header_size; //!< Info header size, must be 40
71 uint32 _bm_image_width; //!< Image width
72 uint32 _bm_image_height; //!< Image height
73 uint16 _bm_num_of_planes; //!< Amount of image planes, must be 1
74 uint16 _bm_color_depth; //!< Color depth
75 uint32 _bm_compressed; //!< Image compression, must be none
76 uint32 _bm_bitmap_size; //!< Size of bitmap data
77 uint32 _bm_hor_resolution; //!< Horizontal resolution, assumed to be 0
78 uint32 _bm_ver_resolution; //!< Vertical resolution, assumed to be 0
79 uint32 _bm_num_colors_used; //!< Number of colors used, assumed to be 0
80 uint32 _bm_num_important_colors; //!< Number of important colors, assumed to
81 //!be 0
82 } BMPInfoHeader;
83
84 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
85 #pragma pack(pop)
86 #else
87 #pragma pack()
88 #endif
89
90 /**
91 * \brief Simple 2D size / region_of_interest structure
92 *
93 * Simple 2D size / region_of_interest structure
94 */
95 typedef struct {
96 int width; //!< ROI width
97 int height; //!< ROI height
98 } ROI;
99
100 /**
101 * One-byte unsigned integer type
102 */
103 typedef unsigned char byte;
104
105 extern "C" {
106 int clamp_0_255(int x);
107 float round_f(float num);
108 byte *MallocPlaneByte(int width, int height, int *pStepBytes);
109 short *MallocPlaneShort(int width, int height, int *pStepBytes);
110 float *MallocPlaneFloat(int width, int height, int *pStepBytes);
111 void CopyByte2Float(byte *ImgSrc, int StrideB, float *ImgDst, int StrideF,
112 ROI Size);
113 void CopyFloat2Byte(float *ImgSrc, int StrideF, byte *ImgDst, int StrideB,
114 ROI Size);
115 void FreePlane(void *ptr);
116 void AddFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
117 void MulFloatPlane(float Value, float *ImgSrcDst, int StrideF, ROI Size);
118 int PreLoadBmp(char *FileName, int *Width, int *Height);
119 void LoadBmpAsGray(char *FileName, int Stride, ROI ImSize, byte *Img);
120 void DumpBmpAsGray(char *FileName, byte *Img, int Stride, ROI ImSize);
121 void DumpBlockF(float *PlaneF, int StrideF, char *Fname);
122 void DumpBlock(byte *Plane, int Stride, char *Fname);
123 float CalculateMSE(byte *Img1, byte *Img2, int Stride, ROI Size);
124 float CalculatePSNR(byte *Img1, byte *Img2, int Stride, ROI Size);
125 }