Commit 8c372a36 authored by 宋柯's avatar 宋柯

眉毛

parent fe06bd86
...@@ -45,8 +45,8 @@ link_directories(/usr/local/lib) ...@@ -45,8 +45,8 @@ link_directories(/usr/local/lib)
#target_link_libraries(main ${OpenCV_LIBS} ${Poco_LIBRARIES}) #target_link_libraries(main ${OpenCV_LIBS} ${Poco_LIBRARIES})
#add_executable(gender gender.cpp ${SRCS}) #add_executable(gender gender.cpp ${SRCS})
#target_link_libraries(gender ${OpenCV_LIBS} ${Poco_LIBRARIES}) #target_link_libraries(gender ${OpenCV_LIBS} ${Poco_LIBRARIES})
add_executable(beautyIris f_BeautyIris.cpp ${SRCS}) add_executable(eyeBrow f_EyeBrow.cpp ${SRCS})
target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} PocoFoundation PocoNet PocoUtil ${dlib_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY}) target_link_libraries(eyeBrow ${OpenCV_LIBS} ${Poco_LIBRARIES} PocoFoundation PocoNet PocoUtil ${dlib_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
#target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} libdlib.a X11 pthread) #target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} libdlib.a X11 pthread)
#target_link_libraries(helloworld #target_link_libraries(helloworld
......
#include"TRGB2HSV.h"
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
void RGB2HSV(unsigned char R, unsigned char G, unsigned char B, float* h, float* s, float * v)
{
float min, max;
float r = R / 255.0;
float g = G / 255.0;
float b = B / 255.0;
min = MIN2(r,MIN2(g,b));
max = MAX2(r,MAX2(g,b));
if (max == min)
*h = 0;
else if (max == r && g >= b)
*h = 60.0 * (g - b) / (max - min);
else if (max == r && g < b)
*h = 60.0 * (g - b) / (max - min) + 360.0;
else if (max == g)
*h = 60.0 * (b - r) / (max - min) + 120.0;
else if (max == b)
*h = 60.0 * (r - g) / (max - min) + 240.0;
*h = CLIP3(*h, 0, 360);
if (max == 0)
*s = 0;
else
*s = (max - min) / max;
*v = max;
};
void HSV2RGB(float h, float s, float v, unsigned char* R, unsigned char *G, unsigned char *B)
{
float q = 0, p = 0, t = 0, f = 0, r = 0, g = 0, b = 0;
int hN = 0;
if(h == 360)
h = 0;
if (h < 0)
h = 360 + h;
hN = (int)((int)h / 60);
f = h / 60.0f - hN;
p = v * (1.0 - s);
q = v * (1.0 - f * s);
t = v * (1.0 - (1.0 - f) * s);
switch (hN)
{
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;
b = q;
break;
default:
break;
}
*R = (unsigned char)CLIP3((r * 255.0),0,255);
*G = (unsigned char)CLIP3((g * 255.0),0,255);
*B = (unsigned char)CLIP3((b * 255.0),0,255);
};
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: RGB2HSV
*************************************************************************/
#ifndef __RGB2HSI__
#define __RGB2HSI__
void RGB2HSV(unsigned char R, unsigned char G, unsigned char B, float *H, float *S, float *V);
void HSV2RGB(float H, float S, float V, unsigned char * R, unsigned char * G, unsigned char *B);
#endif
\ No newline at end of file
#include"TRGB2YCbCr.h"
#include <stdlib.h>
#include <stdio.h>
#include "math.h"
#include <string.h>
const float YCbCrYRF = 0.299F; // RGB转YCbCr的系数(浮点类型)
const float YCbCrYGF = 0.587F;
const float YCbCrYBF = 0.114F;
const float YCbCrCbRF = -0.168736F;
const float YCbCrCbGF = -0.331264F;
const float YCbCrCbBF = 0.500000F;
const float YCbCrCrRF = 0.500000F;
const float YCbCrCrGF = -0.418688F;
const float YCbCrCrBF = -0.081312F;
const float RGBRYF = 1.00000F; // YCbCr转RGB的系数(浮点类型)
const float RGBRCbF = 0.0000F;
const float RGBRCrF = 1.40200F;
const float RGBGYF = 1.00000F;
const float RGBGCbF = -0.34414F;
const float RGBGCrF = -0.71414F;
const float RGBBYF = 1.00000F;
const float RGBBCbF = 1.77200F;
const float RGBBCrF = 0.00000F;
const int Shift = 20;
const int HalfShiftValue = 1 << (Shift - 1);
const int YCbCrYRI = (int)(YCbCrYRF * (1 << Shift) + 0.5); // RGB转YCbCr的系数(整数类型)
const int YCbCrYGI = (int)(YCbCrYGF * (1 << Shift) + 0.5);
const int YCbCrYBI = (int)(YCbCrYBF * (1 << Shift) + 0.5);
const int YCbCrCbRI = (int)(YCbCrCbRF * (1 << Shift) + 0.5);
const int YCbCrCbGI = (int)(YCbCrCbGF * (1 << Shift) + 0.5);
const int YCbCrCbBI = (int)(YCbCrCbBF * (1 << Shift) + 0.5);
const int YCbCrCrRI = (int)(YCbCrCrRF * (1 << Shift) + 0.5);
const int YCbCrCrGI = (int)(YCbCrCrGF * (1 << Shift) + 0.5);
const int YCbCrCrBI = (int)(YCbCrCrBF * (1 << Shift) + 0.5);
const int RGBRYI = (int)(RGBRYF * (1 << Shift) + 0.5); // YCbCr转RGB的系数(整数类型)
const int RGBRCbI = (int)(RGBRCbF * (1 << Shift) + 0.5);
const int RGBRCrI = (int)(RGBRCrF * (1 << Shift) + 0.5);
const int RGBGYI = (int)(RGBGYF * (1 << Shift) + 0.5);
const int RGBGCbI = (int)(RGBGCbF * (1 << Shift) + 0.5);
const int RGBGCrI = (int)(RGBGCrF * (1 << Shift) + 0.5);
const int RGBBYI = (int)(RGBBYF * (1 << Shift) + 0.5);
const int RGBBCbI = (int)(RGBBCbF * (1 << Shift) + 0.5);
const int RGBBCrI = (int)(RGBBCrF * (1 << Shift) + 0.5);
void RGBToYCbCr(int R, int G, int B, int*Y,int*Cb, int* Cr)
{
*Y = ((YCbCrYRI * R + YCbCrYGI * G + YCbCrYBI * B + HalfShiftValue) >> Shift);
*Cb = (128 + ((YCbCrCbRI * R + YCbCrCbGI * G + YCbCrCbBI * B + HalfShiftValue) >> Shift));
*Cr = (128 + ((YCbCrCrRI * R + YCbCrCrGI * G + YCbCrCrBI * B + HalfShiftValue) >> Shift));
}
void YCbCrToRGB(int Y, int Cb, int Cr, int*R,int*G, int* B)
{
Cb = Cb - 128; Cr = Cr - 128;
*R = Y + ((RGBRCrI * Cr + HalfShiftValue) >> Shift);
*G = Y + ((RGBGCbI * Cb + RGBGCrI * Cr + HalfShiftValue) >> Shift);
*B = Y + ((RGBBCbI * Cb + HalfShiftValue) >> Shift);
if (*R > 255) *R = 255; else if (*R < 0) *R = 0;
if (*G > 255) *G = 255; else if (*G < 0) *G = 0;
if (*B > 255) *B = 255; else if (*B < 0) *B = 0;
}
\ No newline at end of file
/*************************************************
Copyright: Copyright HZ.
Author: Hu Yaowu
Date: 2015-04-21
Mail: dongtingyueh@163.com
Description:RGB to YCbCr.
**************************************************/
#ifndef TRGB2YCbCr
#define TRGB2YCbCr
#include<string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void RGBToYCbCr(int R, int G, int B, int*Y,int*Cb, int* Cr);
void YCbCrToRGB(int Y, int Cb, int Cr, int*R,int*G, int* B);
#endif
\ No newline at end of file
#include"TRGB2YUV.h"
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
void RGB2YUV(unsigned char R, unsigned char G, unsigned char B, int *Y, int* U, int*V)
{
*Y = (299 * R + 587 * G + 114 * B) / 1000;
*U = (-147 * R - 289 * G + 436 * B) / 1000;
*V = (615 * R - 515 * G - 100 * B) / 1000;
};
void YUV2RGB(int Y, int U, int V, unsigned char * R, unsigned char * G, unsigned char *B)
{
*R = CLIP3((100 * Y + 114 * V) / 100, 0, 255);
*G = CLIP3((1000 * Y - 395 * U - 581 * V) / 1000, 0, 255);
*B = CLIP3((1000 * Y + 2032 * U) / 1000, 0, 255);
};
\ No newline at end of file
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: RGB2YUV
*************************************************************************/
#ifndef __RGB2YUV__
#define __RGB2YUV__
void RGB2YUV(unsigned char R, unsigned char G, unsigned char B, int *Y, int* U, int*V);
void YUV2RGB(int Y, int U, int V, unsigned char * R, unsigned char * G, unsigned char *B);
#endif
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9F6555E5-E791-44C8-B90B-4FFB3AD7C52D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>TestDemo_C</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\TestDemo\bin\Debug</OutDir>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\TestDemo\bin\Release</OutDir>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTDEMO_C_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TESTDEMO_C_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Commen.h" />
<ClInclude Include="f_BeautyCamera.h" />
<ClInclude Include="f_Commen_MixLayer.h" />
<ClInclude Include="f_GaussFilter.h" />
<ClInclude Include="f_LaplaceSharpen.h" />
<ClInclude Include="f_LUTFilter.h" />
<ClInclude Include="f_SkinDetect.h" />
<ClInclude Include="f_SkinPDF.h" />
<ClInclude Include="f_SkinColor.h" />
<ClInclude Include="f_SmartBlur.h" />
<ClInclude Include="f_SoftSkin.h" />
<ClInclude Include="f_SoftSkin_ChannelMethod.h" />
<ClInclude Include="f_SoftSkin_DetailsAddingMethod.h" />
<ClInclude Include="f_SoftSkin_HPMethod.h" />
<ClInclude Include="f_SoftSkin_MixMethod.h" />
<ClInclude Include="f_SurfaceBlur.h" />
<ClInclude Include="TRGB2HSV.h" />
<ClInclude Include="TRGB2YCbCr.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="f_BeautyCamera.cpp" />
<ClCompile Include="f_Commen_MixLayer.cpp" />
<ClCompile Include="f_GaussFilter.cpp" />
<ClCompile Include="f_LaplaceSharpen.cpp" />
<ClCompile Include="f_LUTFilter.cpp" />
<ClCompile Include="f_SkinDetect.cpp" />
<ClCompile Include="f_SkinPDF.cpp" />
<ClCompile Include="f_SkinColor.cpp" />
<ClCompile Include="f_SmartBlur.cpp" />
<ClCompile Include="f_SoftSkin.cpp" />
<ClCompile Include="f_SoftSkin_ChannelMethod.cpp" />
<ClCompile Include="f_SoftSkin_DetailsAddingMethod.cpp" />
<ClCompile Include="f_SoftSkin_HPMethod.cpp" />
<ClCompile Include="f_SoftSkin_MixMethod.cpp" />
<ClCompile Include="f_SurfaceBlur.cpp" />
<ClCompile Include="TRGB2HSV.cpp" />
<ClCompile Include="TRGB2YCbCr.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="TRGB2YCbCr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SkinPDF.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Commen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_GaussFilter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SoftSkin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SmartBlur.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SkinDetect.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TRGB2HSV.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_LUTFilter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SkinColor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SoftSkin_ChannelMethod.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SoftSkin_HPMethod.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SurfaceBlur.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SoftSkin_MixMethod.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_Commen_MixLayer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_SoftSkin_DetailsAddingMethod.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_LaplaceSharpen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="f_BeautyCamera.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="TRGB2YCbCr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SkinPDF.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_GaussFilter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SoftSkin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SmartBlur.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SkinDetect.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TRGB2HSV.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_LUTFilter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SkinColor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SoftSkin_ChannelMethod.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SoftSkin_HPMethod.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SurfaceBlur.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SoftSkin_MixMethod.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_Commen_MixLayer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_SoftSkin_DetailsAddingMethod.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_LaplaceSharpen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="f_BeautyCamera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
\ No newline at end of file
//
// Created by EDZ on 2021/4/16.
//
#include "ZBase64.h"
string ZBase64::Encode(const unsigned char* Data,int DataByte,string& strEncode)
{
//编码表
const char EncodeTable[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//返回值
unsigned char Tmp[4]={0};
int LineLength=0;
for(int i=0;i<(int)(DataByte / 3);i++)
{
Tmp[1] = *Data++;
Tmp[2] = *Data++;
Tmp[3] = *Data++;
strEncode+= EncodeTable[Tmp[1] >> 2];
strEncode+= EncodeTable[((Tmp[1] << 4) | (Tmp[2] >> 4)) & 0x3F];
strEncode+= EncodeTable[((Tmp[2] << 2) | (Tmp[3] >> 6)) & 0x3F];
strEncode+= EncodeTable[Tmp[3] & 0x3F];
if(LineLength+=4,LineLength==76) {strEncode+="\r\n";LineLength=0;}
}
//对剩余数据进行编码
int Mod=DataByte % 3;
if(Mod==1)
{
Tmp[1] = *Data++;
strEncode+= EncodeTable[(Tmp[1] & 0xFC) >> 2];
strEncode+= EncodeTable[((Tmp[1] & 0x03) << 4)];
strEncode+= "==";
}
else if(Mod==2)
{
Tmp[1] = *Data++;
Tmp[2] = *Data++;
strEncode+= EncodeTable[(Tmp[1] & 0xFC) >> 2];
strEncode+= EncodeTable[((Tmp[1] & 0x03) << 4) | ((Tmp[2] & 0xF0) >> 4)];
strEncode+= EncodeTable[((Tmp[2] & 0x0F) << 2)];
strEncode+= "=";
}
return strEncode;
}
//
// Created by EDZ on 2021/4/16.
//
#ifndef HELLOWORLD_ZBASE64_H
#define HELLOWORLD_ZBASE64_H
#include <string>
using namespace std;
class ZBase64
{
public:
/*编码
DataByte
[in]输入的数据长度,以字节为单位
*/
string Encode(const unsigned char* Data,int DataByte,string& strEncode);
};
#endif //HELLOWORLD_ZBASE64_H
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"Commen.h"
#include"f_AffineTransfrom.h"
/*************************************************************************
*Function: Affinetransfrom matrix compute
*Params:
*x: x of input points
*y: y of input points
*tx: x of output points
*ty: y of output points
*hMatrix: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*Return: NULL
**************************************************************************/
void f_AffinetransformMetrixCompute(float x1, float y1, float x2, float y2, float x3, float y3, float tx1, float ty1, float tx2, float ty2, float tx3, float ty3, float hMatrix[6])
{
//???????|A|
float detA;
detA = tx1 * ty2 + tx2 * ty3 + tx3 * ty1 - tx3 * ty2 - tx1 * ty3 - tx2 * ty1;
// ????????A*
float A11, A12, A13, A21, A22, A23, A31, A32, A33;
A11 = ty2 - ty3;
A21 = -(ty1 - ty3);
A31 = ty1 - ty2;
A12 = -(tx2 - tx3);
A22 = tx1 - tx3;
A32 = -(tx1 - tx2);
A13 = tx2 * ty3 - tx3 * ty2;
A23 = -(tx1 * ty3 - tx3 * ty1);
A33 = tx1 * ty2 - tx2 * ty1;
//???????H=A*/|A|
//float texMatrix[6]={0};
hMatrix[0] = (x1 * A11 + x2 * A21 + x3 * A31) / detA;
hMatrix[1] = (x1 * A12 + x2 * A22 + x3 * A32) / detA;
hMatrix[2] = (x1 * A13 + x2 * A23 + x3 * A33) / detA;
hMatrix[3] = (y1 * A11 + y2 * A21 + y3 * A31) / detA;
hMatrix[4] = (y1 * A12 + y2 * A22 + y3 * A32) / detA;
hMatrix[5] = (y1 * A13 + y2 * A23 + y3 * A33) / detA;
};
/*************************************************************************
*Function: getWHFromHMatrix
*Params:
*width: source image width
*height: source image height
*H: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*wh: the size of image outputs, wh[0]=dWidth, wh[1] = dHeight
*Return: NULL
**************************************************************************/
void getWHFromHMatrix(int width, int height, float H[6], int wh[2])
{
int x0 = (H[0] * 0 + H[1] * 0 + H[2] + 0.5);
int y0 = (H[3] * 0 + H[4] * 0 + H[5] + 0.5);
int x1 = (H[0] * (float)(width - 1) + H[1] * (float)(height - 1) + H[2] + 0.5);
int y1 = (H[3] * (float)(width - 1) + H[4] * (float)(height - 1) + H[5] + 0.5);
int x2 = (H[0] * (float)(width - 1) + H[1] * 0 + H[2] + 0.5);
int y2 = (H[3] * (float)(width - 1) + H[4] * 0 + H[5] + 0.5);
int x3 = (H[0] * 0 + H[1] * (float)(height - 1) + H[2] + 0.5);
int y3 = (H[3] * 0 + H[4] * (float)(height - 1) + H[5] + 0.5);
wh[0] = MAX2(x0, MAX2(x1, MAX2(x2, x3))) - MIN2(x0, MIN2(x1, MIN2(x2, x3)));
wh[1] = MAX2(y0, MAX2(y1, MAX2(y2, y3))) - MIN2(y0, MIN2(y1, MIN2(y2, y3)));
};
/*************************************************************************
*Function: Affinetransfrom
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*H: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*dstData: output image buffer with format bgra32
*dWidth: width of image outputs
*dHeight: height of image outputs
*dStride: Stride of image outputs
*Return: 0-OK,other failed
**************************************************************************/
int f_AffineTransform(unsigned char* srcData, int width, int height, int stride, float H[6], unsigned char* dstData, int dWidth, int dHeight, int dStride)
{
int ret = 0;
unsigned char* pSrc = dstData;
int tx, ty, pos;
int offset[2];
offset[0] = ((dWidth/2.0) - (H[0]*(width/2.0) + H[1]*(height/2.0) + H[2]) + 0.5);
offset[1] = ((dHeight/2.0) - (H[3]*(width/2.0) + H[4]*(height/2.0) + H[5]) + 0.5);
H[2] += offset[0];
H[5] += offset[1];
pSrc = srcData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
tx = CLIP3(((H[0] * (float)(i) + H[1] * (float)(j) + H[2])), 0, dWidth - 1);
ty = CLIP3(((H[3] * (float)(i) + H[4] * (float)(j) + H[5])), 0, dHeight - 1);
pos = (tx << 2) + ty * dStride;
dstData[pos] = pSrc[0];
dstData[pos + 1] = pSrc[1];
dstData[pos + 2] = pSrc[2];
dstData[pos + 3] = 255;
pSrc += 4;
}
}
return ret;
};
\ No newline at end of file
...@@ -4,10 +4,10 @@ Copyright: HZ. ...@@ -4,10 +4,10 @@ Copyright: HZ.
Author: Hu Yaowu Author: Hu Yaowu
Date: 2018-11-23 Date: 2018-11-23
Mail: dongtingyueh@163.com Mail: dongtingyueh@163.com
Description: Skin White. Description: Affinetransfrom .
*************************************************************************/ *************************************************************************/
#ifndef __T_SKIN_WHITE__ #ifndef __T_AFFINE_TRANSFROM__
#define __T_SKIN_WHITE__ #define __T_AFFINE_TRANSFROM__
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -19,52 +19,50 @@ Description: Skin White. ...@@ -19,52 +19,50 @@ Description: Skin White.
#endif #endif
/************************************************************************* /*************************************************************************
*Function: SKIN WHITE *Function: Affinetransfrom matrix compute
*Params: *Params:
*srcData:32BGRA image buffer *x: x of input points
*width: width of image *y: y of input points
*height: height of image *tx: x of output points
*stride: Stride of image *ty: y of output points
*skinMask: skin mask *hMatrix: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*lutData: 32BGRA buffer of lut image. *Return: NULL
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/ **************************************************************************/
EXPORT int f_SkinWhite(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio); EXPORT void f_AffinetransformMetrixCompute(float x1, float y1, float x2, float y2, float x3, float y3, float tx1, float ty1, float tx2, float ty2, float tx3, float ty3, float hMatrix[6]);
/************************************************************************* /*************************************************************************
*Function: SKIN WHITE USING CURVE *Function: getWHFromHMatrix
*Params: *Params:
*srcData:32BGRA image buffer *width: source image width
*width: width of image *height: source image height
*height: height of image *H: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*stride: Stride of image *wh: the size of image outputs, wh[0]=dWidth, wh[1] = dHeight
*belta: intensity of curve enhancement,range[2,10],default:2 *Return: NULL
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
*Reference: "A Two-Stage Contrast Enhancement Algorithm for Digital Images"
**************************************************************************/ **************************************************************************/
EXPORT int f_SkinWhiteCurve(unsigned char* srcData, int width, int height, int stride, int belta, int ratio); EXPORT void getWHFromHMatrix(int width, int height, float H[6], int wh[2]);
/************************************************************************* /*************************************************************************
*Function: SKIN WHITE USING SMOOTH LIGHT OF PS *Function: Affinetransfrom
*Params: *Params:
*srcData:32BGRA image buffer *srcData:32BGRA image buffer
*width: width of image *width: width of image
*height: height of image *height: height of image
*stride: Stride of image *stride: Stride of image
*ratio: Intensity of softskin,range [0,100] *H: affinetransfrom matrix,[a11, a12, b1, a21, a22, b2]
*dstData: output image buffer with format bgra32
*dWidth: width of image outputs
*dHeight: height of image outputs
*dStride: Stride of image outputs
*Return: 0-OK,other failed *Return: 0-OK,other failed
**************************************************************************/ **************************************************************************/
EXPORT int f_SkinWhitePS(unsigned char* srcData, int width, int height, int stride, int ratio); EXPORT int f_AffineTransform(unsigned char* srcData, int width, int height, int stride, float H[6], unsigned char* dstData, int dWidth, int dHeight, int dStride);
#else #else
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int f_SkinWhite(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio); int f_AffineTransform(unsigned char* srcData, int width, int height, int stride, float H[6], unsigned char* dstData, int dWidth, int dHeight, int dStride);
int f_SkinWhiteCurve(unsigned char* srcData, int width, int height, int stride, int belta, int ratio); void getWHFromHMatrix(int width, int height, float H[6], int wh[2]);
int f_SkinWhitePS(unsigned char* srcData, int width, int height, int stride, int ratio); void f_AffinetransformMetrixCompute(float x1, float y1, float x2, float y2, float x3, float y3, float tx1, float ty1, float tx2, float ty2, float tx3, float ty3, float hMatrix[6]);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: BeautyIris .
*************************************************************************/
#ifndef __T_BEAUTY_IRIS__
#define __T_BEAUTY_IRIS__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: BeautyIris
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*srcPoints: 12 eyepoints and one center points
*maskData: 32BGRA mask image buffer
*mWidth: width of mask
*mHeight:height of mask
*mStride:Stride of mask
*maskPoints: 12 eyepoints and one center points of mask image
*ratio: intensity of iris, [0,100]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"Commen.h"
#include<math.h>
int ModeLinearLight(int basePixel,int mixPixel)
{
int res = 0;
res = 2 * mixPixel + basePixel - 256;
return CLIP3(res, 0, 255);
};
int ModeSuperposition(int basePixel,int mixPixel)//基色 < = 128:结果色 = 混合色 * 基色 / 128;基色 > 128:结果色 = 255 - (255 - 混合色)* (255 - 基色) / 128
{
int res = 0;
res = ((basePixel <= 128) ? (mixPixel * basePixel / 128):(255 - (255 - mixPixel) * (255 - basePixel) / 128));
return CLIP3(res, 0, 255);
};
\ No newline at end of file
#ifndef __COMMEN_MIX_LAYER__
#define __COMMEN_MIX_LAYER__
int ModeLinearLight(int basePixel,int mixPixel);//线性光
int ModeSuperposition(int basePixel,int mixPixel);//叠加//基色 < = 128:结果色 = 混合色 * 基色 / 128;基色 > 128:结果色 = 255 - (255 - 混合色)* (255 - 基色) / 128
#endif
\ No newline at end of file
This diff is collapsed.
/************************************************************************* /*************************************************************************
Copyright: HZ. Copyright: HZ.
Author: Hu Yaowu Author: Hu Yaowu
Date: 2018-4-23 Date: 2019-6-23
Mail: dongtingyueh@163.com Mail: dongtingyueh@163.com
Description: BeautyCamera . Description: EYE BROW .
Refference: None
*************************************************************************/ *************************************************************************/
#ifndef __T_BEAUTY_CAMERA__ #ifndef __T_MAKEUP_FACE_EYEBROW__
#define __T_BEAUTY_CAMERA__ #define __T_MAKEUP_FACE_EYEBROW__
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -18,22 +18,24 @@ Refference: None ...@@ -18,22 +18,24 @@ Refference: None
#else #else
#define EXPORT __declspec(dllexport) #define EXPORT __declspec(dllexport)
#endif #endif
/************************************************************************* /*************************************************************************
*Function: Smart Blur *Function: EyeBrow
*Params: *Params:
*srcData:32BGRA image buffer *srcData:32BGRA image buffer
*width: width of image *width: width of image
*height: height of image *height: height of image
*stride: Stride of image *stride: Stride of image
*softRatio: intensity of softskin, [0,100] *srcFacePoints: 101 face points.
*skinWhiteRatio: intensity of skin white, [0,100] *mskData: EyeBrow image buffer with format bgra32
*skinColorRatio: intensity of skin color, [-50,50] *mWidth: width of mask image
*sharpenRatio: intensity of sharpen, [0, 100],default 30 *mHeight: height of mask image
*mStride: Stride of mask image
*maskKeyPoints: 4 key points of brow mask.
*isLeft: left or right face.
*ratio: intensity of effect, [0, 100]
*Return: 0-OK,other failed *Return: 0-OK,other failed
**************************************************************************/ **************************************************************************/
EXPORT int f_BeautyCamera(unsigned char* srcData, int width, int height, int stride, int softRatio, int skinWhiteRatio, int skinColorRatio, int sharpenRatio); EXPORT int f_EyeBrow(unsigned char* srcData, int width, int height, int stride, int srcFacePoints[202], unsigned char* mskData, int mWidth, int mHeight, int mStride, int maskKeyPoints[2 * 4], bool isLeft, int ratio);
#else #else
...@@ -41,7 +43,8 @@ EXPORT int f_BeautyCamera(unsigned char* srcData, int width, int height, int str ...@@ -41,7 +43,8 @@ EXPORT int f_BeautyCamera(unsigned char* srcData, int width, int height, int str
extern "C" { extern "C" {
#endif #endif
int f_BeautyCamera(unsigned char* srcData, int width, int height, int stride, int softRatio, int skinWhiteRatio, int skinColorRatio, int sharpenRatio); /////////////////
int f_EyeBrow(unsigned char* srcData, int width, int height, int stride, int srcFacePoints[202], unsigned char* mskData, int mWidth, int mHeight, int mStride, int maskKeyPoints[2 * 4], bool isLeft, int ratio);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
#include"f_GaussFilter.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include"Commen.h"
/*************************************************************
*Function: Gauss mask compute
*Params:
* r-radius of gauss filter
* sigma-sigma of gauss filter
* gaussMask-gauss weight to compute with size of (2r+1)*(2r+1)
*Return NULL
************************************************************/
void GaussMask(int r, double sigma, double gaussMask[])
{
double PI = 3.1415926;
double sum = 0;
int stride = 2 * r + 1;
for (int y = -r, h = 0; y <= r; y++, h++)
{
for (int x = -r, w = 0; x <= r; x++, w++)
{
gaussMask[w + h * stride] = (1.0 / (2.0 * PI * sigma * sigma)) * (exp(-((double)x * (double)x + (double)y * (double)y) / (2.0 * sigma * sigma)));
sum += gaussMask[w + h * stride];
}
}
for (int i = 0; i < stride * stride; i++)
{
gaussMask[i] = gaussMask[i] / sum;
}
};
int f_FastGaussFilter(unsigned char* srcData,int width, int height,int stride,float r)
{
int ret = 0;
int radius = (int)r;
if(r == 0)
return ret;
unsigned char* dstData = (unsigned char*)malloc(sizeof(unsigned char)*height*stride);
unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char)*height*stride);
int totalWei = 0;
int i,j,k;
float sigma = r;
unsigned char *kernel = (unsigned char *)malloc(2*radius+1);
for (i = -radius; i <= radius; i++)
{
kernel[i+radius] = (unsigned char) (exp(-(float)i*i/(2*sigma*sigma))*128);
totalWei += kernel[i+radius];
}
int tempR = 0, tempG = 0, tempB = 0;
int v = 0;
int K = 0;
int rem = 0;
int t = 0;
int offset = stride - width * 4;
for ( j = 0; j < height; j++)
{
for ( i = 0; i < width; i++)
{
tempR = 0; tempG = 0; tempB = 0;
for ( k = -radius; k <= radius; k++)
{
rem = (abs(i + k) % width);
t = rem * 3 + j * stride;
K = kernel[k + radius];
tempB += srcData[t] * K;
tempG += srcData[t + 1] * K;
tempR += srcData[t + 2] * K;
}
v = i * 3 + j * stride;
tempData[v] = tempB / totalWei;
tempData[v + 1] = tempG / totalWei;
tempData[v + 2] = tempR / totalWei;
}
}
for ( i = 0; i < width; i++)
{
for ( j = 0; j < height; j++)
{
tempR = 0; tempG = 0; tempB = 0;
for ( k = -radius; k <= radius; k++)
{
rem = (abs(j + k) % height);
t = rem * stride + i * 3;
K = kernel[k + radius];
tempB += tempData[t] * K;
tempG += tempData[t + 1] * K;
tempR += tempData[t + 2] * K;
}
v = i * 3 + j * stride;
dstData[v] = tempB/totalWei;
dstData[v + 1] = tempG/totalWei;
dstData[v + 2] = tempR/totalWei;
}
}
memcpy(srcData, dstData, sizeof(unsigned char) * height * stride);
free(dstData);
free(tempData);
return ret;
};
\ No newline at end of file
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: Gauss Filter
*************************************************************************/
#ifndef __TEST_GAUSSFILTER__
#define __TEST_GAUSSFILTER__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/************************************************************
*Function: Gauss Filter
*Description: Gauss Filter process
*Params:
*srcData: image bgra data
*width :image width
*height :image height
*stride :image stride
*r: radius of gauss filter, range [0,]
*Return :0-OK,or failed
************************************************************/
EXPORT int f_FastGaussFilter(unsigned char* srcData,int width, int height,int stride,float r);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_FastGaussFilter(unsigned char* srcData,int width, int height,int stride,float r);
////
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"f_LUTFilter.h"
#include"Commen.h"
static int f_Filter512(unsigned char* srcData, int width ,int height, int stride, unsigned char*Map)
{
int i, j, r, g, b, offset, pos, nx, ny, k;
unsigned char* pSrc = srcData;
offset = stride - (width * 4);
for(j = 0; j < height; j++)
{
for(i = 0; i < width; i++)
{
b = pSrc[0];
g = pSrc[1];
r = pSrc[2];
k = (b >> 2);
nx = (int)(r >> 2) + ((k - ((k >> 3) << 3)) << 6);
ny = (int)(((b >> 5) << 6) + (g >> 2));
pos = (nx * 4) + (ny * 512 * 4);
pSrc[0] = Map[pos];
pSrc[1] = Map[pos + 1];
pSrc[2] = Map[pos + 2];
pSrc += 4;
}
pSrc += offset;
}
return 0;
};
int f_LUTFilter(unsigned char *srcData, int width, int height, int stride,unsigned char* Map)
{
return f_Filter512(srcData, width, height, stride, Map);
};
\ No newline at end of file
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: LUT Filter
*************************************************************************/
#ifndef __TEST_LUT_FILTER__
#define __TEST_LUT_FILTER__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/************************************************************
*Function: LUT Filter
*Description: LUT Filter process
*Params:
*srcData: image bgr data
*width :image width
*height :image height
*stride :image stride
*Map: 512x512 LUT
*Return :0-OK,or failed
************************************************************/
EXPORT int f_LUTFilter(unsigned char *srcData, int width, int height, int stride, unsigned char* Map);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_LUTFilter(unsigned char *srcData, int width, int height, int stride, unsigned char* Map);
////
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"f_LaplaceSharpen.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include"Commen.h"
int f_LaplaceSharpen(unsigned char* srcData,int width, int height,int stride,int mode)
{
int ret = 0;
unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) * height * stride);
int offset = stride - width * 4;
int pos;
memcpy(tempData, srcData, sizeof(unsigned char) * height * stride);
if(mode == 0)
{
for(int j = 1; j < height - 1; j++)
{
for(int i = 1; i < width - 1; i++)
{
pos = i * 3 + j * stride;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 4 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride]), 0, 255);
pos++;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 4 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride]), 0, 255);
pos++;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 4 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride]), 0, 255);
}
}
}
else
{
for(int j = 1; j < height - 1; j++)
{
for(int i = 1; i < width - 1; i++)
{
pos = i * 3 + j * stride;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 6 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride] - tempData[pos - 3 - stride] - tempData[pos + 3 - stride] - tempData[pos - 3 + stride] - tempData[pos + 3 + stride]), 0, 255);
pos++;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 6 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride] - tempData[pos - 3 - stride] - tempData[pos + 3 - stride] - tempData[pos - 3 + stride] - tempData[pos + 3 + stride]), 0, 255);
pos++;
srcData[pos] = CLIP3(tempData[pos] + (tempData[pos] * 6 - tempData[pos - stride] - tempData[pos - 3] - tempData[pos + 3] - tempData[pos + stride] - tempData[pos - 3 - stride] - tempData[pos + 3 - stride] - tempData[pos - 3 + stride] - tempData[pos + 3 + stride]), 0, 255);
}
}
}
free(tempData);
return ret;
};
\ No newline at end of file
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: Laplace sharpen
*************************************************************************/
#ifndef __TEST_LAPLACE_SHARPEN__
#define __TEST_LAPLACE_SHARPEN__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/************************************************************
*Function: Laplace sharpen
*Description: Laplace sharpen process
*Params:
*srcData: image bgra data
*width :image width
*height :image height
*stride :image stride
*mode :0-MASK4,1-MASK8
*Return :0-OK,or failed
************************************************************/
EXPORT int f_LaplaceSharpen(unsigned char* srcData,int width, int height,int stride,int mode);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_LaplaceSharpen(unsigned char* srcData,int width, int height,int stride,int mode);
////
#ifdef __cplusplus
}
#endif
#endif
#endif
This diff is collapsed.
#ifndef __T_MAKEUP_BASE__
#define __T_MAKEUP_BASE__
/*************************************************************************
*Function: Makeup base
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*srcFacePoints: 101 face points.
*mskData: blush image buffer with format bgra32
*mWidth: width of mask image
*mHeight: height of mask image
*mStride: Stride of mask image
*maskKeyPoints 3 key points of blush mask.
*ratio: intensity of effect, [0, 100]
*Return: 0-OK,other failed
**************************************************************************/
int f_MakeupBase(unsigned char* srcData, int width, int height, int stride, int srcKeyPoints[2 * 3], unsigned char* mskData, int mWidth, int mHeight, int mStride, int maskKeyPoints[2 * 3], int ratio);
/*************************************************************************
*Function: f_MakeupBaseShadow
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*srcKeyPoints: 4 key points of source image.
*mskData: eyeshadow image buffer with format bgra32
*mWidth: width of mask image
*mHeight: height of mask image
*mStride: Stride of mask image
*maskKeyPoints 4 key points of eyeshadow mask.
*mode: overlay mode.
*ratio: intensity of effect, [0, 100]
*Return: 0-OK,other failed
**************************************************************************/
int f_MakeupBaseShadow(unsigned char* srcData, int width, int height, int stride, int srcKeyPoints[2 * 4], unsigned char* mskData, int mWidth, int mHeight, int mStride, int maskKeyPoints[2 * 4], int mode, int ratio);
#endif
\ No newline at end of file
#include"f_MeanFilter.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include"Commen.h"
//Fast mean filter based histagram computation
int f_FastMeanFilter(unsigned char* srcData, int width, int height ,int stride, int radius)
{
int ret = 0;
if(radius == 0)
return ret;
if(radius > MIN2(width,height) / 2)
radius = (MIN2(width, height) / 2-0.5);
unsigned char* dstData = (unsigned char*)malloc(sizeof(unsigned char) * height * stride);
int unit = 3, t = 0, t1 = 0;
int i,j,k,len = width * height * unit;
int block = (radius << 1) + 1;
int winSize = block * block;
long sumB = 0, sumG = 0,sumR = 0;
unsigned char* pSrc = srcData;
int* temp = (int*)malloc(sizeof(int)* width * unit);
memset(temp,0,sizeof(int) * width * unit);
for(k = -radius; k <= radius; k++)
{
for(j = 0; j< width; j++)
{
t = j * unit;
t1 = abs(k) * stride;
temp[t] += pSrc[t + t1];
temp[t + 1] += pSrc[t + 1 + t1];
temp[t + 2] += pSrc[t + 2 + t1];
}
}
for (i = 0; i < height; i++)
{
sumB = sumG = sumR = 0;
for (j = -radius; j <= radius; j++)
{
t = abs(j) * unit;
sumB += temp[t];
sumG += temp[t + 1];
sumR += temp[t + 2];
}
for (j = 0; j < width; j++)
{
t = j * unit + i * stride;
dstData[t] = (sumB / winSize);
dstData[t + 1] = (sumG / winSize);
dstData[t + 2] = (sumR / winSize);
if (j < width - 1)
{
t = abs(j - radius) * unit;
t1 = (j + radius + 1) % width * unit;
sumB = sumB - temp[t] + temp[t1];
sumG = sumG - temp[t + 1] + temp[t1 + 1];
sumR = sumR - temp[t + 2] + temp[t1 + 2];
}
}
if (i < height - 1)
{
for (k = 0; k < width; k++)
{
t = k * unit + abs(i - radius) * stride;
t1 = k * unit + (i + radius + 1) % height * stride;
temp[k * unit] = temp[k * unit] - pSrc[t] + pSrc[t1];
temp[k * unit + 1] = temp[k * unit + 1] - pSrc[t + 1] + pSrc[t1 + 1];
temp[k * unit + 2] = temp[k * unit + 2] - pSrc[t + 2] + pSrc[t1 + 2];
}
}
}
memcpy(srcData, dstData, sizeof(unsigned char) * height * stride);
free(dstData);
free(temp);
return ret;
};
//std mean filter
int f_MeanFilter(unsigned char *srcData, int width, int height, int stride, int radius)
{
int ret = 0;
if(radius == 0)
return ret;
int offset = stride - width * 4;
unsigned char* temp = (unsigned char*)malloc(sizeof(unsigned char) * height * stride);
memcpy(temp, srcData, sizeof(unsigned char) * height * stride);
int M = (radius * 2 + 1) * (radius * 2 + 1);
int sumr = 0, sumg = 0, sumb = 0;
unsigned char* pSrc = srcData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
sumr = sumg = sumb = 0;
for(int n = -radius; n <=radius; n++)
{
for(int m = -radius; m <= radius; m++)
{
int ny = CLIP3(j + n, 0, height - 1);
int nx = CLIP3(i + m, 0, width - 1);
int pos = nx * 4 + ny * stride;
sumb += temp[pos];
sumg += temp[pos + 1];
sumr += temp[pos + 2];
}
}
pSrc[0] = sumb / M;
pSrc[1] = sumg / M;
pSrc[2] = sumr / M;
pSrc += 4;
}
pSrc += offset;
}
free(temp);
return ret;
};
/*************************************************************************
Copyright: Trent.
Author: Trent1985
Date: 2018-9-23
Mail: dongtingyueh@163.com
Description: Mean Filter
*************************************************************************/
#ifndef __TEST_MEANFILTER__
#define __TEST_MEANFILTER__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/************************************************************
*Function: Mean Filter
*Description: Mean Filter process
*Params:
*srcData: image bgr data
*width :image width
*height :image height
*stride :image stride
*radius: range [0,]
*Return :0-OK,or failed
************************************************************/
EXPORT int f_MeanFilter(unsigned char *srcData, int width, int height, int stride, int radius);
/************************************************************
*Function: Fast Mean Filter
*Description: Fast Mean Filter process
*Params:
*srcData: image bgr data
*width :image width
*height :image height
*stride :image stride
*radius: range [0,]
*Return :0-OK,or failed
************************************************************/
EXPORT int f_FastMeanFilter(unsigned char* srcData, int width, int height ,int stride, int radius);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_MeanFilter(unsigned char *srcData, int width, int height, int stride, int radius);
int f_FastMeanFilter(unsigned char* srcData, int width, int height ,int stride, int radius);
////
#ifdef __cplusplus
}
#endif
#endif
#endif
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"Commen.h"
#include"f_LUTFilter.h"
#include"f_SkinPDF.h"
#include"f_GaussFilter.h"
#include"f_SkinColor.h"
/*************************************************************************
*Function: SKIN COLOR
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*skinMask: skin mask
*lutData: 32BGRA buffer of lut image.
*ratio: Intensity of skin colored,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_SkinColor(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(tempData, srcData, sizeof(unsigned char) * length);
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(skinPDF, srcData, sizeof(unsigned char) * length);
ret = f_SkinPDF(skinPDF, width, height, stride);
int maskSmoothRadius = 3;
ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
ret = f_LUTFilter(tempData, width, height, stride, lutData);
unsigned char* pSrc = srcData;
unsigned char* pLut = tempData;
unsigned char* pSkin = skinPDF;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int r, g, b, a;
b = CLIP3((pSrc[0] * (100 - ratio) + pLut[0] * ratio) / 100, 0, 255);
g = CLIP3((pSrc[1] * (100 - ratio) + pLut[1] * ratio) / 100, 0, 255);
r = CLIP3((pSrc[2] * (100 - ratio) + pLut[2] * ratio) / 100, 0, 255);
a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);
pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);
pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);
pSrc += 4;
pLut += 4;
pSkin += 4;
}
}
free(tempData);
free(skinPDF);
return ret;
};
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: Skin Color.
*************************************************************************/
#ifndef __T_SKIN_COLOR__
#define __T_SKIN_COLOR__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: SKIN COLOR
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*skinMask: skin mask
*lutData: 32BGRA buffer of lut image.
*ratio: Intensity of skin colored,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_SkinColor(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_SkinColor(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include"f_SkinPDF.h"
#include"TRGB2YCbCr.h"
#define MIN2(a, b) ((a) < (b) ? (a) : (b))
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define CLIP3(x, a, b) MIN2(MAX2(a,x), b)
float Gaussian(float x, float mean, float var)
{
float t = -0.5f * (x - mean) * (x - mean) / var;
return exp(t);
}
float GetPDF(int R, int G, int B, float meanCb, float varCb, float meanCr, float varCr)
{
int Y, Cb, Cr;
RGBToYCbCr(R, G, B, &Y, &Cb, &Cr);
float pcb = Gaussian(Cb, meanCb, varCb);
float pcr = Gaussian(Cr, meanCr, varCr);
return 2.0f * pcb * pcr;
};
/*************************************************************************
*Function: Skin PDF
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*Return: 0-OK,other failed
**************************************************************************/
int f_SkinPDF(unsigned char* srcData, int width, int height, int stride)
{
int ret = 0;
float sum = 0, mean = 0, variance = 0;
unsigned char* pSrc = srcData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
//default setting is computed using special skin data.
//meanCb-varCb:102-196
//meanCr-varCr:143-196
int gray = CLIP3(GetPDF(pSrc[2], pSrc[1], pSrc[0], 102, 196, 143, 196) * 255.0f, 0, 255);
pSrc[0] = pSrc[1] = pSrc[2] = gray;
pSrc += 3;
}
}
return ret;
};
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-4-23
Mail: dongtingyueh@163.com
Description: Skin PDF .
*************************************************************************/
#ifndef __T_SKIN_PDF__
#define __T_SKIN_PDF__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: Skin PDF
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_SkinPDF(unsigned char* srcData, int width, int height, int stride);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_SkinPDF(unsigned char* srcData, int width, int height, int stride);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"Commen.h"
#include"f_LUTFilter.h"
#include"f_SkinPDF.h"
#include"f_GaussFilter.h"
#include"f_SkinWhite.h"
/*************************************************************************
*Function: SKIN WHITE
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*skinMask: skin mask
*lutData: 32BGRA buffer of lut image.
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_SkinWhite(unsigned char* srcData, int width, int height, int stride, unsigned char* lutData, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(tempData, srcData, sizeof(unsigned char) * length);
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(skinPDF, srcData, sizeof(unsigned char) * length);
// ret = f_SkinPDF(skinPDF, width, height, stride);
int maskSmoothRadius = 3;
// ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
ret = f_LUTFilter(tempData, width, height, stride, lutData);
unsigned char* pSrc = srcData;
unsigned char* pLut = tempData;
unsigned char* pSkin = skinPDF;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int r, g, b, a;
b = CLIP3((pSrc[0] * (100 - ratio) + pLut[0] * ratio) / 100, 0, 255);
g = CLIP3((pSrc[1] * (100 - ratio) + pLut[1] * ratio) / 100, 0, 255);
r = CLIP3((pSrc[2] * (100 - ratio) + pLut[2] * ratio) / 100, 0, 255);
a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);
pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);
pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);
pSrc += 3;
pLut += 3;
pSkin += 3;
}
}
free(tempData);
free(skinPDF);
return ret;
};
/*************************************************************************
*Function: SKIN WHITE USING CURVE
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*belta: intensity of curve enhancement,range[2,10],default:2
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
*Reference: "A Two-Stage Contrast Enhancement Algorithm for Digital Images"
**************************************************************************/
int f_SkinWhiteCurve(unsigned char* srcData, int width, int height, int stride, int belta, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(skinPDF, srcData, sizeof(unsigned char) * length);
ret = f_SkinPDF(skinPDF, width, height, stride);
int maskSmoothRadius = 3;
ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
unsigned char* pSrc = srcData;
unsigned char* pSkin = skinPDF;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int r, g, b, a;
//skin white curve
b = CLIP3(log((float)pSrc[0] * (belta - 1) / 255.0f + 1) / log((float)belta) * 255.0f, 0, 255);
g = CLIP3(log((float)pSrc[1] * (belta - 1) / 255.0f + 1) / log((float)belta) * 255.0f, 0, 255);
r = CLIP3(log((float)pSrc[2] * (belta - 1) / 255.0f + 1) / log((float)belta) * 255.0f, 0, 255);
b = CLIP3((b * ratio + pSrc[0] * (100 - ratio)) / 100, 0, 255);
g = CLIP3((g * ratio + pSrc[1] * (100 - ratio)) / 100, 0, 255);
r = CLIP3((r * ratio + pSrc[2] * (100 - ratio)) / 100, 0, 255);
//skin pdf
a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);
pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);
pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);
pSrc += 3;
pSkin += 3;
}
}
free(skinPDF);
return ret;
}
inline int ModeSmoothLight(int basePixel,int mixPixel)
{
int res = 0;
res = mixPixel > 128 ? ((int)((float)basePixel+((float)mixPixel+(float)mixPixel-255.0f)*((sqrt((float)basePixel/255.0f) )*255.0f-(float)basePixel)/255.0f)):
((int)((float)basePixel+((float)mixPixel+(float)mixPixel-255.0f)*((float)basePixel-(float)basePixel*(float)basePixel/255.0f)/255.0f));
return CLIP3(res, 0, 255);
};
/*************************************************************************
*Function: SKIN WHITE USING SMOOTH LIGHT OF PS
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_SkinWhitePS(unsigned char* srcData, int width, int height, int stride, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(skinPDF, srcData, sizeof(unsigned char) * length);
ret = f_SkinPDF(skinPDF, width, height, stride);
int maskSmoothRadius = 3;
// ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
unsigned char* pSrc = srcData;
unsigned char* pSkin = skinPDF;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int r, g, b, a;
//skin white using smoothlight of ps
b = ModeSmoothLight(pSrc[0], 255);
g = ModeSmoothLight(pSrc[1], 255);
r = ModeSmoothLight(pSrc[2], 255);
b = CLIP3((b * ratio + pSrc[0] * (100 - ratio)) / 100, 0, 255);
g = CLIP3((g * ratio + pSrc[1] * (100 - ratio)) / 100, 0, 255);
r = CLIP3((r * ratio + pSrc[2] * (100 - ratio)) / 100, 0, 255);
//skin pdf
a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);
pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);
pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);
pSrc += 3;
pSkin += 3;
}
}
free(skinPDF);
return ret;
}
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include"f_SmartBlur.h"
#include"TRGB2YCbCr.h"
#define MIN2(a, b) ((a) < (b) ? (a) : (b))
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define CLIP3(x, a, b) MIN2(MAX2(a,x), b)
int SmartBlurOneChannel(unsigned char* srcData, int width ,int height, int radius, int threshold)
{
int len = sizeof(unsigned long) * width * height;
int i, j;
int gray = 0;
unsigned char* tempData = (unsigned char*) malloc(sizeof(unsigned char) * height * width);
memcpy(tempData, srcData, sizeof(unsigned char) * height * width);
for(j = 0; j < height; j++ )
{
for(i = 0; i < width; i++)
{
len = i + j * width;
gray = tempData[len];
int low = CLIP3(gray - threshold, 0, 255);
int high = CLIP3(gray + threshold, 0, 255);
int sum = 0;
int count = 0;
for(int n = -radius; n <= radius; n++)
{
for(int m = -radius; m <= radius; m++)
{
int x = CLIP3(i + m, 0, width - 1);
int y = CLIP3(j + n, 0, height - 1);
int pos = x + y * width;
gray = tempData[pos];
if(gray > low && gray < high)
{
sum += gray;
count++;
}
}
}
gray = count == 0 ? srcData[len] : sum / count;//sum / MAX2(count, 1);
srcData[len] = CLIP3(gray, 0, 255);
}
}
free(tempData);
return 0;
};
/*************************************************************************
*Function: Smart Blur
*Params:
*srcData:32BGRA image buffer
*nWidth: width of image
*nHeight: height of image
*nStride: Stride of image
*radius: radius of filter, [0,+]
*threshold: threshold of pixels to count,[0,255]
*Return: 0-OK,other failed
**************************************************************************/
int f_SmartBlur(unsigned char* srcData, int nWidth, int nHeight, int nStride, int radius, int threshold)
{
int ret = 0;
if (srcData == NULL)
{
return ret;
}
if(radius == 0 || threshold == 0)
return ret;
unsigned char* yData = (unsigned char*)malloc(sizeof(unsigned char) * nWidth * nHeight);
unsigned char* cbData = (unsigned char*)malloc(sizeof(unsigned char) * nWidth * nHeight);
unsigned char* crData = (unsigned char*)malloc(sizeof(unsigned char) * nWidth * nHeight);
unsigned char* pSrc = srcData;
int Y, CB, CR;
unsigned char* pY = yData;
unsigned char* pCb = cbData;
unsigned char* pCr = crData;
for(int j = 0; j < nHeight; j++)
{
for(int i = 0; i < nWidth; i++)
{
RGBToYCbCr(pSrc[2],pSrc[1],pSrc[0],&Y,&CB,&CR);
*pY = Y;
*pCb = CB;
*pCr = CR;
pY++;
pCb++;
pCr++;
pSrc += 4;
}
}
SmartBlurOneChannel(yData, nWidth, nHeight, radius, threshold);
pSrc = srcData;
pY = yData;
pCb = cbData;
pCr = crData;
int R, G, B;
for(int j = 0; j < nHeight; j++)
{
for(int i = 0; i < nWidth; i++)
{
YCbCrToRGB(*pY, *pCb, *pCr, &R, &G, &B);
pSrc[0] = B;
pSrc[1] = G;
pSrc[2] = R;
pY++;
pCb++;
pCr++;
pSrc += 4;
}
}
free(yData);
free(cbData);
free(crData);
return ret;
}
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-4-23
Mail: dongtingyueh@163.com
Description: Smart Blur .
Refference: None
*************************************************************************/
#ifndef __T_SMART_BLUR__
#define __T_SMART_BLUR__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: Smart Blur
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*radius: radius of filter, [0,+]
*threshold: threshold of pixels to count,[0,255]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_SmartBlur(unsigned char* srcData, int width, int height, int stride, int radius, int threshold);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_SmartBlur(unsigned char* srcData, int width, int height, int stride, int radius, int threshold);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"f_SoftSkin_ChannelMethod.h"
#include"f_GaussFilter.h"
#include"f_LUTFilter.h"
#include"f_SkinPDF.h" //3.10
//#include"disabled/f_SkinDetect.h"//3.9
#include"f_Commen_MixLayer.h"
/*************************************************************************
*Function: SOFT SKIN CHANNEL METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*lightMap: light curve map data with format BGRA32
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_Softskin_ChannelMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int ratio)
{
int ret = 0;
unsigned char* greenData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* gaussData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* curveData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* skinData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* pSrc = srcData;
unsigned char* pGreen = greenData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
pGreen[0] = pSrc[0];
pGreen[1] = pSrc[0];
pGreen[2] = pSrc[0];
pSrc += 4;
pGreen += 4;
}
}
memcpy(gaussData, greenData, sizeof(unsigned char) * height * stride);
memcpy(curveData, srcData, sizeof(unsigned char) * height * stride);
ret = f_LUTFilter(curveData, width, height, stride, lightMap);
float hpRadius = 10.0f * width * height / (594 * 677);
ret = f_FastGaussFilter(gaussData, width, height, stride,hpRadius);
pSrc = srcData;
pGreen = greenData;
unsigned char* pCurve = curveData;
unsigned char* pGauss = gaussData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int t;
t = CLIP3(pGauss[0] - pGreen[0] + 128, 0, 255);
t = ModeSuperposition(t, t);
t = ModeSuperposition(t, t);
t = t * 220 / 255;
pGreen[0] = CLIP3((pCurve[0] * t + (255 - t) * pSrc[0]) / 255, 0, 255);
pGreen[1] = CLIP3((pCurve[1] * t + (255 - t) * pSrc[1]) / 255, 0, 255);
pGreen[2] = CLIP3((pCurve[2] * t + (255 - t) * pSrc[2]) / 255, 0, 255);
pGreen += 4;
pGauss += 4;
pSrc += 4;
pCurve += 4;
}
}
memcpy(skinData, greenData, sizeof(unsigned char) * height * stride);
int maskSmoothRadius = 3 * width * height / (594 * 677);
ret = f_SkinPDF(skinData, width, height, stride);
ret = f_FastGaussFilter(skinData, width, height, stride, maskSmoothRadius);
pGauss = skinData;
pSrc = srcData;
pGreen = greenData;
int k = ratio * 128 / 100;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int mask = (pGauss[0] + pGauss[1] + pGauss[2]) / 3;
int tb = CLIP3((pSrc[0] * (255 - mask) + pGreen[0] * mask) / 255, 0, 255);
int tg = CLIP3((pSrc[1] * (255 - mask) + pGreen[1] * mask) / 255, 0, 255);
int tr = CLIP3((pSrc[2] * (255 - mask) + pGreen[2] * mask) / 255, 0, 255);
pSrc[0] = CLIP3((pSrc[0] * (128 - k) + tb * k) >> 7, 0, 255);
pSrc[1] = CLIP3((pSrc[1] * (128 - k) + tg * k) >> 7, 0, 255);
pSrc[2] = CLIP3((pSrc[2] * (128 - k) + tr * k) >> 7, 0, 255);
pSrc += 4;
pGauss += 4;
pGreen += 4;
}
}
free(gaussData);
free(greenData);
free(curveData);
free(skinData);
return ret;
};
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: Soft skin .
*************************************************************************/
#ifndef __T_SOFT_SKIN_CHANNEL_METHOD__
#define __T_SOFT_SKIN_CHANNEL_METHOD__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: SOFT SKIN CHANNEL METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*lightMap: light curve map data with format BGRA32
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_Softskin_ChannelMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int ratio);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_Softskin_ChannelMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int ratio);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"f_GaussFilter.h"
#include"f_SkinPDF.h" //3.10
//#include"disabled/f_SkinDetect.h"//3.9
#include"f_Commen_MixLayer.h"
#include"f_SoftSkin_DetailsAddingMethod.h"
#include"f_SmartBlur.h"
#include"f_SurfaceBlur.h"
/*************************************************************************
*Function: SOFT SKIN DETAILSADDED METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*ratio: Intensity of softskin,range [0,100]
*K: intensity of details controled, range [0,300]
*Return: 0-OK,other failed
**************************************************************************/
int f_Softskin_DetailsAddingMethod(unsigned char* srcData, int width, int height, int stride, int ratio, float K)
{
int ret = 0;
int len = sizeof(unsigned char) * height * stride;
unsigned char*coarseSmoothData = (unsigned char*)malloc(len);
unsigned char*fineSmoothData = (unsigned char*)malloc(len);
memcpy(coarseSmoothData, srcData, len);
memcpy(fineSmoothData, srcData, len);
int std_fine = 5;
int std_coarse = 10;
f_SmartBlur(fineSmoothData, width, height, stride, std_fine, 30);
f_SmartBlur(coarseSmoothData, width, height, stride, std_coarse, 30);
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * len);
memcpy(skinPDF, coarseSmoothData, sizeof(unsigned char) * len);
ret = f_SkinPDF(skinPDF, width, height, stride);
float maskSmoothRadius = 3;
ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
unsigned char* pSrc = srcData;
unsigned char* pCoarse = coarseSmoothData;
unsigned char* pFine = fineSmoothData;
unsigned char* pSkin = skinPDF;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int alpha = *pSkin * ratio / 100;
int detailsFine = pSrc[0] - pFine[0];
int detailsCoarse = pFine[0] - pCoarse[0];
float K0 = alpha / 255.0f;
pSrc[0] = (unsigned char)CLIP3(pCoarse[0] + (255 - alpha) * detailsCoarse / 255 + (1.0f - K0 * K) * detailsFine, 0, 255);
detailsFine = pSrc[1] - pFine[1];
detailsCoarse = pFine[1] - pCoarse[1];
pSrc[1] = (unsigned char)CLIP3(pCoarse[1] + (255 - alpha) * detailsCoarse / 255 + (1.0f - K0 * K) * detailsFine, 0, 255);
detailsFine = pSrc[2] - pFine[2];
detailsCoarse = pFine[2] - pCoarse[2];
pSrc[2] = (unsigned char)CLIP3(pCoarse[2] + (255 - alpha) * detailsCoarse / 255 + (1.0f - K0 * K) * detailsFine, 0, 255);
pSrc += 4;
pCoarse += 4;
pFine += 4;
pSkin += 4;
}
}
free(skinPDF);
free(coarseSmoothData);
free(fineSmoothData);
return ret;
};
\ No newline at end of file
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: Soft skin .
*************************************************************************/
#ifndef __T_SOFT_SKIN_HP_METHOD__
#define __T_SOFT_SKIN_HP_METHOD__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: SOFT SKIN DETAILS ADDING METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*ratio: Intensity of softskin,range [0,100]
*K: details params, range [0,500]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_Softskin_DetailsAddingMethod(unsigned char* srcData, int width, int height, int stride, int ratio, float K);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_Softskin_DetailsAddingMethod(unsigned char* srcData, int width, int height, int stride, int ratio, float K);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"f_SoftSkin_HPMethod.h"
#include"f_GaussFilter.h"
#include"f_LUTFilter.h"
#include"f_SkinPDF.h" //3.10
//#include"disabled/f_SkinDetect.h"//3.9
#include"f_SmartBlur.h"
#include"f_SurfaceBlur.h"
#include"f_Commen_MixLayer.h"
/*************************************************************************
*Function: SOFT SKIN HP METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*textureRatio: intensity of details controled, range [0,100]
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_Softskin_HP(unsigned char* srcData, int width, int height, int stride, int textureRatio, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* smoothData = (unsigned char*)malloc(sizeof(unsigned char) * length);
unsigned char* hpData = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(smoothData, srcData, sizeof(unsigned char) * length);
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
int smoothRadius = 8;
int smoothThreshold = 38;
int maskSmoothRadius = 3;
ret = f_SurfaceBlur(smoothData, width, height, stride, smoothRadius, smoothThreshold);
memcpy(skinPDF, smoothData, sizeof(unsigned char) * length);
ret = f_SkinPDF(skinPDF, width, height, stride);
ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);
unsigned char* pSrc = srcData;
unsigned char* pSkin = skinPDF;
unsigned char* pSmooth = smoothData;
unsigned char* pHP = hpData;
int k = ratio * 128 / 100;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
pHP[0] = CLIP3(pSmooth[0] - pSrc[0] + 128, 0, 255);
pHP[1] = CLIP3(pSmooth[1] - pSrc[1] + 128, 0, 255);
pHP[2] = CLIP3(pSmooth[2] - pSrc[2] + 128, 0, 255);
pHP += 4;
pSmooth += 4;
pSrc += 4;
}
}
float hpRadius = 3.5f * textureRatio / 100.0f;
ret = f_FastGaussFilter(hpData, width, height, stride, hpRadius);
pSmooth = smoothData;
pHP = hpData;
pSrc = srcData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int hpb = pHP[0];
int hpg = pHP[1];
int hpr = pHP[2];
hpb = ModeLinearLight(pSrc[0], hpb);
hpg = ModeLinearLight(pSrc[1], hpg);
hpr = ModeLinearLight(pSrc[2], hpr);
int mask = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
hpb = CLIP3((hpb * mask + pSmooth[0] * (255 - mask)) / 255, 0, 255);
hpg = CLIP3((hpg * mask + pSmooth[1] * (255 - mask)) / 255, 0, 255);
hpr = CLIP3((hpr * mask + pSmooth[2] * (255 - mask)) / 255, 0, 255);
pSrc[0] = CLIP3((hpb * k + pSrc[0] * (128 - k)) >> 7, 0, 255);
pSrc[1] = CLIP3((hpg * k + pSrc[1] * (128 - k)) >> 7, 0, 255);
pSrc[2] = CLIP3((hpr * k + pSrc[2] * (128 - k)) >> 7, 0, 255);
pSrc += 4;
pHP += 4;
pSmooth += 4;
pSkin += 4;
}
}
free(skinPDF);
free(smoothData);
free(hpData);
return ret = 0;
};
\ No newline at end of file
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: Soft skin .
*************************************************************************/
#ifndef __T_SOFT_SKIN_HP_METHOD__
#define __T_SOFT_SKIN_HP_METHOD__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: SOFT SKIN HP METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*textureRatio: intensity of details controled, range [0,100]
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_Softskin_HP(unsigned char* srcData, int width, int height, int stride, int textureRatio, int ratio);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_Softskin_HP(unsigned char* srcData, int width, int height, int stride, int textureRatio, int ratio);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include"Commen.h"
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"f_SoftSkin_ChannelMethod.h"
#include"f_GaussFilter.h"
#include"f_LUTFilter.h"
#include"f_SkinPDF.h" //3.10
//#include"disabled/f_SkinDetect.h"//3.9
#include"f_SmartBlur.h"
#include"f_SoftSkin_HPMethod.h"
#include"f_SurfaceBlur.h"
#include"f_Commen_MixLayer.h"
#include"f_SoftSkin_MixMethod.h"
int Softskin_A(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int ratio)
{
int ret = 0;
unsigned char* greenData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* gaussData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* curveData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* skinData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* smoothData = (unsigned char*)malloc(sizeof(unsigned char) * stride * height);
unsigned char* pSrc = srcData;
unsigned char* pGreen = greenData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
pGreen[0] = pSrc[0];
pGreen[1] = pSrc[0];
pGreen[2] = pSrc[0];
pSrc += 4;
pGreen += 4;
}
}
memcpy(gaussData, greenData, sizeof(unsigned char) * height * stride);
memcpy(curveData, srcData, sizeof(unsigned char) * height * stride);
ret = f_LUTFilter(curveData, width, height, stride, lightMap);
float hpRadius = 10.0f * width * height / (594 * 677);
ret = f_FastGaussFilter(gaussData, width, height, stride,hpRadius);
pSrc = srcData;
pGreen = greenData;
unsigned char* pCurve = curveData;
unsigned char* pGauss = gaussData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int t;
t = CLIP3(pGauss[0] - pGreen[0] + 128, 0, 255);
t = ModeSuperposition(t, t);
t = ModeSuperposition(t, t);
t = t * 200 / 255;
pGreen[0] = CLIP3((pCurve[0] * t + (255 - t) * pSrc[0]) / 255, 0, 255);
pGreen[1] = CLIP3((pCurve[1] * t + (255 - t) * pSrc[1]) / 255, 0, 255);
pGreen[2] = CLIP3((pCurve[2] * t + (255 - t) * pSrc[2]) / 255, 0, 255);
pGreen += 4;
pGauss += 4;
pSrc += 4;
pCurve += 4;
}
}
int k = ratio * 128 / 100;
memcpy(smoothData, greenData, sizeof(unsigned char) * stride * height);
int smoothRadius = 6;
int smoothThreshold = 38;
ret = f_SmartBlur(smoothData, width, height, stride, smoothRadius, smoothThreshold);
memcpy(skinData, smoothData, sizeof(unsigned char) * height * stride);
int maskSmoothRadius = 3;
ret = f_SkinPDF(skinData, width, height, stride);
ret = f_FastGaussFilter(skinData, width, height, stride, maskSmoothRadius);
pGauss = skinData;
pSrc = srcData;
pGreen = greenData;
unsigned char* pSmooth = smoothData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int mask = (pGauss[0] + pGauss[1] + pGauss[2]) / 3;
int tb = CLIP3((pSrc[0] * (255 - mask) + pGreen[0] * mask) / 255, 0, 255);
int tg = CLIP3((pSrc[1] * (255 - mask) + pGreen[1] * mask) / 255, 0, 255);
int tr = CLIP3((pSrc[2] * (255 - mask) + pGreen[2] * mask) / 255, 0, 255);
tb = CLIP3((tb * (255 - mask) + pSmooth[0] * mask) / 255, 0, 255);
tg = CLIP3((tg * (255 - mask) + pSmooth[1] * mask) / 255, 0, 255);
tr = CLIP3((tr * (255 - mask) + pSmooth[2] * mask) / 255, 0, 255);
pSrc[0] = CLIP3((pSrc[0] * (128 - k) + tb * k) >> 7, 0, 255);
pSrc[1] = CLIP3((pSrc[1] * (128 - k) + tg * k) >> 7, 0, 255);
pSrc[2] = CLIP3((pSrc[2] * (128 - k) + tr * k) >> 7, 0, 255);
pSrc += 4;
pGauss += 4;
pGreen += 4;
pSmooth += 4;
}
}
free(gaussData);
free(greenData);
free(curveData);
free(skinData);
free(smoothData);
return ret;
}
//
//
/*************************************************************************
*Function: SOFT SKIN MIXED METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*lightMap: light curve map data with format BGRA32
*textureRatio: intensity of details controled, range [0,100]
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
int f_Softskin_MixMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int textureRatio, int ratio)
{
int ret = 0;
int length = height * stride;
unsigned char* smoothData = (unsigned char*)malloc(sizeof(unsigned char) * length);
unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) * length);
unsigned char* hpData = (unsigned char*)malloc(sizeof(unsigned char) * length);
memcpy(smoothData, srcData, sizeof(unsigned char) * length);
memcpy(tempData, srcData, sizeof(unsigned char) * length);
unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) * length);
int smoothRadius = 8;
int smoothThreshold = 38;
int maskSmoothRadius = 3;
ret = Softskin_A(smoothData, width, height, stride, lightMap, 95);
memcpy(skinPDF, smoothData, sizeof(unsigned char) * length);
ret = f_SkinPDF(skinPDF, width, height, stride);
unsigned char* pSrc = srcData;
unsigned char* pSkin = skinPDF;
unsigned char* pSmooth = smoothData;
unsigned char* pHP = hpData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int mask = 128 - textureRatio * 128 / 100;
pSrc[0] = CLIP3((pSrc[0] * (128 - mask) + pSmooth[0] * mask) >> 7, 0, 255);
pSrc[1] = CLIP3((pSrc[1] * (128 - mask) + pSmooth[1] * mask) >> 7, 0, 255);
pSrc[2] = CLIP3((pSrc[2] * (128 - mask) + pSmooth[2] * mask) >> 7, 0, 255);
pHP[0] = CLIP3(pSmooth[0] - pSrc[0] + 128, 0, 255);
pHP[1] = CLIP3(pSmooth[1] - pSrc[1] + 128, 0, 255);
pHP[2] = CLIP3(pSmooth[2] - pSrc[2] + 128, 0, 255);
pHP += 4;
pSmooth += 4;
pSrc += 4;
pSkin += 4;
}
}
float hpRadius = 3.1;
ret = f_FastGaussFilter(hpData, width, height, stride, hpRadius);
pSrc = srcData;
pSkin = skinPDF;
pSmooth = smoothData;
pHP = hpData;
int k = ratio * 128 / 100;
unsigned char* pTemp = tempData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
int hpb = pHP[0];
int hpg = pHP[1];
int hpr = pHP[2];
hpb = ModeLinearLight(pSrc[0], hpb);
hpg = ModeLinearLight(pSrc[1], hpg);
hpr = ModeLinearLight(pSrc[2], hpr);
int mask = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;
hpb = CLIP3((hpb * mask + pSmooth[0] * (255 - mask)) / 255, 0, 255);
hpg = CLIP3((hpg * mask + pSmooth[1] * (255 - mask)) / 255, 0, 255);
hpr = CLIP3((hpr * mask + pSmooth[2] * (255 - mask)) / 255, 0, 255);
pSrc[0] = CLIP3((hpb * k + pTemp[0] * (128 - k)) >> 7, 0, 255);
pSrc[1] = CLIP3((hpg * k + pTemp[1] * (128 - k)) >> 7, 0, 255);
pSrc[2] = CLIP3((hpr * k + pTemp[2] * (128 - k)) >> 7, 0, 255);
pSrc += 4;
pHP += 4;
pSmooth += 4;
pSkin += 4;
pTemp += 4;
}
}
free(skinPDF);
free(smoothData);
free(hpData);
free(tempData);
return ret;
};
\ No newline at end of file
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-11-23
Mail: dongtingyueh@163.com
Description: Soft skin .
*************************************************************************/
#ifndef __T_SOFT_SKIN_MIX_METHOD__
#define __T_SOFT_SKIN_MIX_METHOD__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*************************************************************************
*Function: SOFT SKIN MIXED METHOD
*Params:
*srcData:32BGRA image buffer
*width: width of image
*height: height of image
*stride: Stride of image
*lightMap: light curve map data with format BGRA32
*textureRatio: intensity of details controled, range [0,100]
*ratio: Intensity of softskin,range [0,100]
*Return: 0-OK,other failed
**************************************************************************/
EXPORT int f_Softskin_MixMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int textureRatio, int ratio);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_Softskin_MixMethod(unsigned char* srcData, int width, int height, int stride, unsigned char* lightMap, int textureRatio, int ratio);
#ifdef __cplusplus
}
#endif
#endif
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include"f_SurfaceBlur.h"
#include"TRGB2YCbCr.h"
#define MIN2(a, b) ((a) < (b) ? (a) : (b))
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define CLIP3(x, a, b) MIN2(MAX2(a,x), b)
static int SurfaceBlurOneChannel(unsigned char* srcData, int width, int height, float* map, int radius)
{
int ret = 0;
int i, j, n, m, len;
len = sizeof(unsigned char) * width * height;
unsigned char* tempData = (unsigned char*)malloc(len);
int* tmap = (int*)malloc(sizeof(int) * height);
if(tempData == NULL || tmap == NULL)
{
ret = 1;
return ret;
}
if(NULL == tempData || NULL == tmap)
return 1;
for(i = 0; i < height; i ++)
{
tmap[i] = i * width;
}
memcpy(tempData, srcData, len);
int kx, ky;
len = (radius << 1) + 1;
int gray = 0;
float sum, sum_a;
int pos, pos_a;
unsigned char val;
for(j = 0; j < height; j++)
{
for(i = 0; i < width; i++)
{
pos = i + tmap[j];
val = tempData[pos];
sum = 0;
sum_a = 0;
for(n = -radius; n <= radius; n++)
{
ky = CLIP3(j + n, 0, height - 1);
pos_a = tmap[ky];
for(m = -radius; m <= radius; m++)
{
kx = CLIP3(i + m, 0, width - 1);
gray = tempData[kx + pos_a];
sum_a += map[gray - val];
sum += gray * map[gray - val];
}
}
gray = sum_a == 0 ? gray : sum / sum_a;//(int)(sum / MAX2(sum_a, 0.1));
srcData[pos] = gray;//CLIP3(gray, 0 , 255);
}
}
free(tempData);
free(tmap);
return ret;
};
/*****************************************************
*Function: Surface blur
*Params:
*srcData-32BGRA image data
*width-width of image
*height-height of image
*stride-Stride of image
*radius-radius of surface blur, [0,100]
*threshold-Threshold of surface blur, [0,255]
*Return: 0-OK, or failed.
******************************************************/
int f_SurfaceBlur(unsigned char* srcData, int width, int height, int stride, int radius, int threshold)
{
if (srcData == NULL || radius == 0 || threshold == 0)
{
return 0;
}
unsigned char* yData = (unsigned char*)malloc(sizeof(unsigned char) * width * height);
unsigned char* cbData = (unsigned char*)malloc(sizeof(unsigned char) * width * height);
unsigned char* crData = (unsigned char*)malloc(sizeof(unsigned char) * width * height);
unsigned char* pSrc = srcData;
int Y, CB, CR;
unsigned char* pY = yData;
unsigned char* pCb = cbData;
unsigned char* pCr = crData;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
RGBToYCbCr(pSrc[2],pSrc[1],pSrc[0],&Y,&CB,&CR);
*pY = Y;
*pCb = CB;
*pCr = CR;
pY++;
pCb++;
pCr++;
pSrc += 3;
}
}
float matrixItems[511];//255*2+1
float* items = &matrixItems[255];
float fv = threshold * 2.5f;
for(int i = 0; i < 256; i++)
{
items[-i] = items[i] = MAX2(1 - i / fv, 0);
}
SurfaceBlurOneChannel(yData, width, height, items, radius);
SurfaceBlurOneChannel(cbData, width, height, items, radius);
SurfaceBlurOneChannel(crData, width, height, items, radius);
pSrc = srcData;
pY = yData;
pCb = cbData;
pCr = crData;
int R, G, B;
for(int j = 0; j < height; j++)
{
for(int i = 0; i < width; i++)
{
YCbCrToRGB(*pY, *pCb, *pCr, &R, &G, &B);
pSrc[0] = B;
pSrc[1] = G;
pSrc[2] = R;
pY++;
pCb++;
pCr++;
pSrc += 3;
}
}
free(yData);
free(cbData);
free(crData);
return 0;
}
/*************************************************************************
Copyright: HZ.
Author: Hu Yaowu
Date: 2018-4-23
Mail: dongtingyueh@163.com
Description: Surface blur .
*************************************************************************/
#ifndef __T_SURFACE_BLUR__
#define __T_SURFACE_BLUR__
#ifdef _MSC_VER
#ifdef __cplusplus
#define EXPORT extern "C" _declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
/*****************************************************
*Function: Surface blur
*Params:
*srcData-32BGRA image data
*width-width of image
*height-height of image
*stride-Stride of image
*radius-radius of surface blur, [0,100]
*threshold-Threshold of surface blur, [0,255]
*Return: 0-OK, or failed.
******************************************************/
EXPORT int f_SurfaceBlur(unsigned char* srcData, int width, int height, int stride, int radius, int threshold);
#else
#ifdef __cplusplus
extern "C" {
#endif
int f_SurfaceBlur(unsigned char* srcData, int width, int height, int stride, int radius, int threshold);
#ifdef __cplusplus
}
#endif
#endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment