-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxremovereflectionschnbl.cpp
executable file
·64 lines (55 loc) · 2.07 KB
/
cxremovereflectionschnbl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "cxremovereflectionschnbl.h"
#include <ImageData.h>
#include <PicBufAPI.h>
#include <PicBufMacros.h>
CxRemoveReflectionsChnbl::CxRemoveReflectionsChnbl() : CxAbstractPolarChnbl("Remove Reflection")
{
}
CxChainable* CxRemoveReflectionsChnbl::clone(){
return new CxRemoveReflectionsChnbl();
}
bool CxRemoveReflectionsChnbl::queryOutputImageInfo(const SxPicBufInfo &picInfoInput, SxPicBufInfo &picInfoOutput, const CxImageMetadata *pMetadataInput, CxImageMetadata *pMetadataOutput){
// Initialize output with input
picInfoOutput = picInfoInput;
// One 2x2 pattern in the input image becomes one pixel in the output image
picInfoOutput.m_uiWidth /= 2;
picInfoOutput.m_uiHeight /= 2;
picInfoOutput.m_uiStride = XICORE_ALIGN_IMG_STRIDE(picInfoOutput.m_uiWidth*picInfoOutput.bytesPerPixel());
if (pMetadataOutput != nullptr && pMetadataInput != nullptr){
*pMetadataOutput = *pMetadataInput;
}
return true;
}
bool CxRemoveReflectionsChnbl::processBuffers(const SxPicBuf &input, SxPicBuf &output){
switch(input.m_eDataType){
case extypeUInt8:
return convertToMinimumImage<unsigned char>(input,output);
case extypeUInt16:
return convertToMinimumImage<unsigned short>(input,output);
default:
setErrorMessage("Unsupported data type!");
return false;
}
}
template<typename T>
bool CxRemoveReflectionsChnbl::convertToMinimumImage(const SxPicBuf& input, SxPicBuf& output)
{
#pragma omp parallel for
// Loop over input image two rows at a time
for(quint32 row = 0u; row < input.m_uiHeight; row+=2u){
const T* upper = ROW(T, input, row);
const T* lower = ROW(T, input, row+1);
T* dst = ROW(T, output, row/2);
std::size_t column = 0;
while (column < input.m_uiWidth){
T upper_temp = *upper < *(upper+1) ? *upper : *(upper+1);
T lower_temp = *lower < *(lower+1) ? *lower : *(lower+1);
*dst = upper_temp < lower_temp ? upper_temp : lower_temp;
upper += 2;
lower += 2;
dst++;
column += 2;
}
}
return true;
}