UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImageParallelFor.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4ImageParallelFor.h: helper to run ParallelFor on images
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "ImageCore.h"
11#include "Async/ParallelFor.h"
12
29// ImageCore.h in global namespace:
30// ImageParallelForComputeNumJobsForPixels
31// ImageParallelForComputeNumJobsForRows
32
33namespace FImageCore
34{
35 // ImageParallelFor treats the image as being 2d (no slices) but with *NumSlices rows
37 {
38 return (int64)Image.SizeY * Image.NumSlices;
39 }
40
41 // Y indexes across slices and SizeY here :
43 {
45
46 // point at one row of the image :
48 ImageRow.SizeY = 1;
49 ImageRow.NumSlices = 1;
50 ImageRow.RawData = (uint8 *)Image.RawData + Image.GetBytesPerPixel() * Y * Image.SizeX;
51 return ImageRow;
52 }
53
56
57 // Lambda is a functor that works on an FImageView()
58 // it will be called with portions of the image
59 // each portion will be a 2d FImageView (NumSlices == 1)
60 // use like :
61 // FImageCore::ImageParallelFor( TEXT("Texture.AdjustImageColorsFunc.PF"),Image, [&](FImageView & ImagePart) {
62 template <typename Lambda>
63 inline void ImageParallelFor(const TCHAR* DebugName, const FImageView & Image, const Lambda& Func)
64 {
67
68 ParallelFor(DebugName, NumJobs, 1, [=](int64 JobIndex)
69 {
72 Func(Part,StartY);
74 }
75
77 {
80 };
81
91 template <typename Lambda>
92 inline void ProcessLinearPixels(const FImageView & Image, const Lambda& Func, int64 StartY)
93 {
94 if ( Image.Format == ERawImageFormat::RGBA32F )
95 {
96 // Image is already FLinearColor, can work on it in-place
97 TArrayView64<FLinearColor> Colors = Image.AsRGBA32F();
98 FLinearColor * Start = &Colors[0];
99
101 {
103 Func(RowColors,StartY+Y);
104 }
105 }
106 else
107 {
108 // convert to linear, act on linear, then copy back
111
113 {
114 // point at one row of the image :
116
118
120
122 {
123 // Colors were modified, need to blit back
125 }
126 }
127 }
128 }
129
130 // parallel process image as TArrayView64<FLinearColor>
131 // your lambda is called on one row at a time so that the grouping is machine invariant
132 template <typename Lambda>
133 inline void ImageParallelProcessLinearPixels(const TCHAR* DebugName, const FImageView & Image, const Lambda& Func)
134 {
135 ImageParallelFor(DebugName,Image,[Func](const FImageView &Part,int64 StartY) {
136 // call ProcessLinearPixels on each part :
138 } );
139 }
140
141};
#define check(expr)
Definition AssertionMacros.h:314
void ParallelFor(int32 Num, TFunctionRef< void(int32)> Body, bool bForceSingleThread, bool bPumpRenderingThread=false)
Definition ParallelFor.h:481
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
@ RGBA32F
Definition ImageCore.h:63
Definition ImageCore.cpp:1836
FImageView ImageParallelForGetOneRowView(const FImageView &Image, int64 Y)
Definition ImageParallelFor.h:42
ProcessLinearPixelsAction
Definition ImageParallelFor.h:77
IMAGECORE_API int64 ImageParallelForMakePart(FImageView *Part, const FImageView &Whole, int64 JobIndex, int64 RowsPerJob)
Definition ImageParallelFor.cpp:33
int64 ImageParallelForComputeNumRows(const FImageView &Image)
Definition ImageParallelFor.h:36
IMAGECORE_API void CopyImage(const FImageView &SrcImage, const FImageView &DestImage)
Definition ImageCore.cpp:369
IMAGECORE_API int32 ImageParallelForComputeNumJobs(const FImageView &Image, int64 *pRowsPerJob)
Definition ImageParallelFor.cpp:18
void ProcessLinearPixels(const FImageView &Image, const Lambda &Func, int64 StartY)
Definition ImageParallelFor.h:92
void ImageParallelProcessLinearPixels(const TCHAR *DebugName, const FImageView &Image, const Lambda &Func)
Definition ImageParallelFor.h:133
void ImageParallelFor(const TCHAR *DebugName, const FImageView &Image, const Lambda &Func)
Definition ImageParallelFor.h:63
int32 SizeY
Definition ImageCore.h:144
Definition ImageCore.h:264
Definition ImageCore.h:416
Definition Color.h:48