CARLA
 
载入中...
搜索中...
未找到
ImageUtil.cpp
浏览该文件的文档.
1// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8#include "Runtime/RHI/Public/RHISurfaceDataConversion.h"
9#include "Carla/Carla.h"
10
11
12
13namespace ImageUtil
14{
16 void* PixelData,
17 int32 SourcePitch,
18 FIntPoint SourceExtent,
19 FIntPoint DestinationExtent,
20 EPixelFormat Format,
21 FReadSurfaceDataFlags Flags,
22 TArrayView<FLinearColor> Out)
23 {
24 SourcePitch *= GPixelFormats[Format].BlockBytes;
25 auto OutPixelCount = DestinationExtent.X * DestinationExtent.Y;
26 switch (Format)
27 {
28 case PF_G16:
29 case PF_R16_UINT:
30 case PF_R16_SINT:
31 // Shadow maps
32 ConvertRawR16DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
33 break;
34 case PF_R8G8B8A8:
35 ConvertRawR8G8B8A8DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
36 break;
37 case PF_B8G8R8A8:
38 ConvertRawB8G8R8A8DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
39 break;
40 case PF_A2B10G10R10:
41 ConvertRawA2B10G10R10DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
42 break;
43 case PF_FloatRGBA:
44 case PF_R16G16B16A16_UNORM:
45 case PF_R16G16B16A16_SNORM:
46 ConvertRawR16G16B16A16FDataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
47 break;
48 case PF_FloatR11G11B10:
49 ConvertRawRR11G11B10DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
50 break;
51 case PF_A32B32G32R32F:
52 ConvertRawR32G32B32A32DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
53 break;
54 case PF_A16B16G16R16:
55 ConvertRawR16G16B16A16DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
56 break;
57 case PF_G16R16:
58 ConvertRawR16G16DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
59 break;
60 case PF_DepthStencil: // Depth / Stencil
61 ConvertRawD32S8DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
62 break;
63 case PF_X24_G8: // Depth Stencil
64 ConvertRawR24G8DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
65 break;
66 case PF_R32_FLOAT: // Depth Stencil
67 ConvertRawR32DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
68 break;
69 case PF_R16G16B16A16_UINT:
70 case PF_R16G16B16A16_SINT:
71 ConvertRawR16G16B16A16DataToFLinearColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
72 break;
73 default:
74 UE_LOG(LogCarla, Warning, TEXT("Unsupported format %llu"), (unsigned long long)Format);
75 check(false);
76 break;
77 }
78 }
79
81 void* PixelData,
82 int32 SourcePitch,
83 FIntPoint SourceExtent,
84 FIntPoint DestinationExtent,
85 EPixelFormat Format,
86 FReadSurfaceDataFlags Flags,
87 TArrayView<FColor> Out)
88 {
89 SourcePitch *= GPixelFormats[Format].BlockBytes;
90 auto OutPixelCount = DestinationExtent.X * DestinationExtent.Y;
91 switch (Format)
92 {
93 case PF_G16:
94 case PF_R16_UINT:
95 case PF_R16_SINT:
96 // Shadow maps
97 ConvertRawR16DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
98 break;
99 case PF_R8G8B8A8:
100 ConvertRawR8G8B8A8DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
101 break;
102 case PF_B8G8R8A8:
103 ConvertRawB8G8R8A8DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
104 break;
105 case PF_A2B10G10R10:
106 ConvertRawR10G10B10A2DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
107 break;
108 case PF_FloatRGBA:
109 case PF_R16G16B16A16_UNORM:
110 case PF_R16G16B16A16_SNORM:
111 ConvertRawR16G16B16A16FDataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), false);
112 break;
113 case PF_FloatR11G11B10:
114 ConvertRawR11G11B10DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), false);
115 break;
116 case PF_A32B32G32R32F:
117 ConvertRawR32G32B32A32DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), false);
118 break;
119 case PF_A16B16G16R16:
120 ConvertRawR16G16B16A16DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
121 break;
122 case PF_G16R16:
123 ConvertRawR16G16DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
124 break;
125 case PF_DepthStencil: // Depth / Stencil
126 ConvertRawD32S8DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
127 break;
128 case PF_X24_G8: // Depth / Stencil
129 ConvertRawR24G8DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
130 break;
131 case PF_R32_FLOAT: // Depth
132 ConvertRawR32DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData(), Flags);
133 break;
134 case PF_R16G16B16A16_UINT:
135 case PF_R16G16B16A16_SINT:
136 ConvertRawR16G16B16A16DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
137 break;
138 case PF_G8:
139 ConvertRawR8DataToFColor(DestinationExtent.X, DestinationExtent.Y, (uint8*)PixelData, SourcePitch, Out.GetData());
140 break;
141 default:
142 UE_LOG(LogCarla, Warning, TEXT("Unsupported format %llu"), (unsigned long long)Format);
143 check(false);
144 break;
145 }
146 }
147}
void DecodePixelsByFormat(void *PixelData, int32 SourcePitch, FIntPoint SourceExtent, FIntPoint DestinationExtent, EPixelFormat Format, FReadSurfaceDataFlags Flags, TArrayView< FLinearColor > Out)
Definition ImageUtil.cpp:15