📄 warpipl.cpp
字号:
IPL_ALIGN_DWORD, // 4 bytes align out_width, // image width out_height, // image height NULL, NULL, NULL, NULL); // not tiledelse } if( NULL == srcImage ) return; srcImage->imageData = (char*)in_image; if( NULL == dstImage ) return; dstImage->imageData = (char*)out_image; iplSet(dstImage, 0); srcImage->roi = &SrcROI; dstImage->roi = &DstROI; iplResize(srcImage, dstImage, twidth, swidth, theight, sheight, IPL_INTER_LINEAR); iplDeallocate( srcImage, IPL_IMAGE_HEADER ); iplDeallocate( dstImage, IPL_IMAGE_HEADER );}// iColor: BGRA : 0xaarrggbbvoid SetBackgroundColor(BYTE *in_image, int in_width, int in_height, unsigned int iColor){ ASSERT(in_width % 2 == 0); int iLoopCount = in_width * in_height / 2; // 8 byte = 4byte * 2 __m64 vColor = _mm_set_pi32(int(iColor), int(iColor)); __m64 *pvImage = (__m64*)in_image; for(int i=0; i<iLoopCount; i++) { pvImage[i] = vColor; } _mm_empty();}// iColor: BGRA : 0xaarrggbbBOOL AlphaCompositeWithColor(char *in_image, int width, int height, unsigned int iColor){ IplImage *srcImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of float point type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align width, // image width height, // image height NULL,NULL,NULL,NULL); if( NULL == srcImage ) return FALSE; iplAllocateImage(srcImage , 0, 0); SetBackgroundColor((unsigned char*)srcImage->imageData, width, height, iColor); IplImage *dstImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of float point type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align width, // image width height, // image height NULL,NULL,NULL,NULL); if( NULL == dstImage ) return FALSE; dstImage->imageData = in_image; // 菊,第,搬苞. iplAlphaComposite(dstImage, srcImage, dstImage, IPL_COMPOSITE_OVER, NULL, NULL, NULL, TRUE, FALSE); iplDeallocate(srcImage, IPL_IMAGE_ALL); iplDeallocate(dstImage, IPL_IMAGE_HEADER ); return TRUE;}// 盔夯俊 write窍骨肺 林狼(鞘夸矫 荤夯 包府绰 观俊辑)BOOL FusionImages(BYTE *pBackgroundImage, BYTE *pForegroundImage, BYTE *pOutputImage, CSize szImage, float fBackWeight, float fFrontWeight){ ASSERT(szImage.cx % 8 == 0); ASSERT(fBackWeight <= 1.0f && fBackWeight >= 0.0f); IplImage *BackImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == BackImage) return FALSE; BackImage->imageData = (char *)pBackgroundImage; IplImage *ForeImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == ForeImage) return FALSE; ForeImage->imageData = (char *)pForegroundImage; IplImage *OutImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == OutImage) return FALSE; OutImage->imageData = (char *)pOutputImage; int iBackWeight = (int)(fBackWeight * 255); int iFrontWeight = (int)(fFrontWeight * 255); iplMultiplySScale(BackImage, BackImage, iBackWeight); iplMultiplySScale(ForeImage, ForeImage, iFrontWeight); iplAdd(BackImage, ForeImage, OutImage); iplDeallocate(OutImage, IPL_IMAGE_HEADER); iplDeallocate(BackImage, IPL_IMAGE_HEADER); iplDeallocate(ForeImage, IPL_IMAGE_HEADER); return TRUE;}BOOL MultiplyScale(BYTE *pInputImage, BYTE *pOutputImage, CSize szImage, float fWeight){ ASSERT(szImage.cx % 8 == 0); ASSERT(fWeight <= 1.0f && fWeight >= 0.0f); IplImage *InImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == InImage) return FALSE; InImage->imageData = (char *)pInputImage; IplImage *OutImage = iplCreateImageHeader( 4, // number of channels 4, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == OutImage) return FALSE; OutImage->imageData = (char *)pOutputImage; int iWeight = (int)(fWeight * 255); iplMultiplySScale(InImage, OutImage, iWeight); iplDeallocate(InImage, IPL_IMAGE_HEADER); iplDeallocate(OutImage, IPL_IMAGE_HEADER); return TRUE;}BOOL MultiplyScaleByte(BYTE *pInputImage, BYTE *pOutputImage, CSize szImage, float fWeight){ ASSERT(szImage.cx % 8 == 0); ASSERT(fWeight <= 1.0f && fWeight >= 0.0f); IplImage *InImage = iplCreateImageHeader( 1, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "Gray", // color model "Gray", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == InImage) return FALSE; InImage->imageData = (char *)pInputImage; IplImage *OutImage = iplCreateImageHeader( 1, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "Gray", // color model "Gray", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == OutImage) return FALSE; OutImage->imageData = (char *)pOutputImage; int iWeight = (int)(fWeight * 255); iplMultiplySScale(InImage, OutImage, iWeight); iplDeallocate(InImage, IPL_IMAGE_HEADER); iplDeallocate(OutImage, IPL_IMAGE_HEADER); return TRUE;}// 盔夯俊 write窍骨肺 林狼(鞘夸矫 荤夯 包府绰 观俊辑)BOOL FusionImagesBYTE(BYTE *pBackgroundImage, BYTE *pForegroundImage, BYTE *pOutputImage, CSize szImage, float fBackWeight){ ASSERT(szImage.cx % 8 == 0); ASSERT(fBackWeight <= 1.0f && fBackWeight >= 0.0f); IplImage *BackImage = iplCreateImageHeader( 1, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "Gray", // color model "Gray", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == BackImage) return FALSE; BackImage->imageData = (char *)pBackgroundImage; IplImage *ForeImage = iplCreateImageHeader( 1, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "Gray", // color model "Gray", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == ForeImage) return FALSE; ForeImage->imageData = (char *)pForegroundImage; IplImage *OutImage = iplCreateImageHeader( 1, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "Gray", // color model "Gray", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_QWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == OutImage) return FALSE; OutImage->imageData = (char *)pOutputImage; int iBackWeight = (int)(fBackWeight * 255); iplMultiplySScale(BackImage, BackImage, iBackWeight); iplMultiplySScale(ForeImage, ForeImage, 255-iBackWeight); iplAdd(BackImage, ForeImage, OutImage); iplDeallocate(OutImage, IPL_IMAGE_HEADER); iplDeallocate(BackImage, IPL_IMAGE_HEADER); iplDeallocate(ForeImage, IPL_IMAGE_HEADER); return TRUE;}BOOL AlphaComposite(BYTE *pBackgroundImage, BYTE *pForegroundImage, BYTE *pOutputImage, CSize szImage, float fBackWeight){ ASSERT(fBackWeight <= 1.0f && fBackWeight >= 0.0f); IplImage *BackImage = iplCreateImageHeader( 4, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_DWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == BackImage) return FALSE; BackImage->imageData = (char *)pBackgroundImage; IplImage *ForeImage = iplCreateImageHeader( 4, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_DWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == ForeImage) return FALSE; ForeImage->imageData = (char *)pForegroundImage; IplImage *OutImage = iplCreateImageHeader( 4, // number of channels 0, // no alpha channel IPL_DEPTH_8U, // data of byte type "RGBA", // color model "BGRA", // color order IPL_DATA_ORDER_PIXEL, // channel arrangement IPL_ORIGIN_TL, // top left orientation IPL_ALIGN_DWORD, // 8 bytes align szImage.cx, // image width szImage.cy, // image height NULL, // no ROI NULL, // no mask ROI NULL, // no image ID NULL); // not tiled if (NULL == OutImage) return FALSE; OutImage->imageData = (char *)pOutputImage; int iBackWeight = (int)(fBackWeight * 255); const int constant_composite = 1; if(constant_composite) { iplAlphaCompositeC(ForeImage, BackImage, OutImage, IPL_COMPOSITE_PLUS, 255-iBackWeight, iBackWeight, FALSE, FALSE); } else { iplMultiplySScale(BackImage, OutImage, iBackWeight); BackImage->alphaChannel = 4; ForeImage->alphaChannel = 4; OutImage->alphaChannel = 4; iplAlphaComposite(OutImage, ForeImage, OutImage, IPL_COMPOSITE_OVER, NULL, NULL, NULL, TRUE, FALSE); } iplDeallocate(OutImage, IPL_IMAGE_HEADER); iplDeallocate(BackImage, IPL_IMAGE_HEADER); iplDeallocate(ForeImage, IPL_IMAGE_HEADER); return TRUE;}void CompositeC(short*pSrcImage1, short*pSrcImage2, short*pDstImage, int loop, short Aa, short Ab){ ASSERT(0 <= Aa && Aa <= 8 && Aa+Ab == 8); __m64 alpha1 = _mm_set1_pi16(Aa); __m64 alpha2 = _mm_set1_pi16(Ab); __m64 *pvSrcImage1 = (__m64*)pSrcImage1; __m64 *pvSrcImage2 = (__m64*)pSrcImage2; __m64 *pvDstImage = (__m64*)pDstImage; for(int i=0; i<loop; i++) { __m64 dst1 = _mm_mullo_pi16(*pvSrcImage1, alpha1); __m64 dst2 = _mm_mullo_pi16(*pvSrcImage2, alpha2); __m64 dst = _mm_add_pi16(dst1, dst2); *pvDstImage = _mm_srli_pi16(dst, 3); } _mm_empty();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -