NVIDIA DeepLearning Dataset Synthesizer (NDDS)
 All Classes Namespaces Functions Variables Typedefs Pages
NVImageExporter.h
1 /*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10 
11 #pragma once
12 
13 #include "NVSceneCapturerUtils.h"
14 #include "HAL/Runnable.h"
15 #include "IImageWrapper.h"
16 #include "NVImageExporter.generated.h"
17 
18 USTRUCT()
19 struct NVSCENECAPTURER_API FNVImageExporterData
20 {
21  GENERATED_BODY()
22 
23 public:
24  UPROPERTY()
25  FNVTexturePixelData PixelDataToBeExported;
26 
27  UPROPERTY()
28  FString ExportFilePath;
29 
30  UPROPERTY()
31  ENVImageFormat ExportImageFormat;
32 
33 public:
34  FNVImageExporterData();
35  FNVImageExporterData(const FNVTexturePixelData& InPixelDataToBeExported,
36  const FString InExportFilePath,
37  ENVImageFormat InExportImageFormat = ENVImageFormat::PNG);
38 };
39 
40 struct NVSCENECAPTURER_API FNVImageExporter
41 {
42 public:
43  FNVImageExporter(IImageWrapperModule* InImageWrapperModule);
45 
46  /// Compress a source image data to PNG format
47  /// NOTE: PNG is lossless compression so we can't change the compression quality
48  /// This function always use Z_BEST_SPEED, may be we want to customize the compression level
49  /// result The compressed data in bytes
50  static TArray<uint8> CompressImagePNG(const FNVTexturePixelData& SourcePixelData);
51 
52  /// Compress a source image to a certain image type
53  /// @param ImageWrapperModule Reference to the ImageWrapper module
54  /// @param SourcePixelData The source, raw pixel data
55  /// @param ImageFormat The type of the image to compress to
56  /// @param CompressionQuality The quality of the compression
57  /// result The compressed data in bytes
58  static TArray<uint8> CompressImage(IImageWrapperModule* ImageWrapperModule,
59  const FNVTexturePixelData& SourcePixelData,
60  ENVImageFormat ImageFormat,
61  uint8 CompressionQuality = 100);
62 
63  /// Export an in-memory image to file on disk
64  static bool ExportImage(IImageWrapperModule* ImageWrapperModule, const FNVImageExporterData& ImageExporterData);
65 
66  bool ExportImage(const FNVImageExporterData& ImageExporterData);
67 
68 protected:
69  IImageWrapperModule* ImageWrapperModule;
70 };
71 
72 struct NVSCENECAPTURER_API FNVImageExporter_Thread : public FRunnable
73 {
74 public:
75  FNVImageExporter_Thread(IImageWrapperModule* InImageWrapperModule);
77 
78  bool ExportImage(const FNVTexturePixelData& ExportPixelData,
79  const FString& ExportFilePath,
80  const ENVImageFormat ExportImageFormat = ENVImageFormat::PNG);
81 
82  virtual uint32 Run();
83  virtual void Stop() override;
84 
85  uint32 GetPendingImagesCount() const;
86  bool IsExportingImage() const;
87 
88 protected:
89  FRunnableThread* Thread;
90  bool bIsRunning;
91 
92  TQueue<FNVImageExporterData> QueuedImageData;
93 
94  IImageWrapperModule* ImageWrapperModule;
95 
96  FEvent* HavePendingImageEvent;
97  FThreadSafeCounter PendingImageCounter;
98  TSharedPtr<FThreadSafeCounter, ESPMode::ThreadSafe> ExportingImageCounterPtr;
99 };