먼저 IppDib를 IppImage로 변환하는 함수를 살펴보자. 두 개의 IppDibToImage 함수 정의를 소스 4-16에 나타내었다. 각각의 함수 시작 부분에서는 전달된 dib 객체가 유효한 DIB인지, 그리고 입력 DIB의 색상 수가 적절한지를 먼저 검사한다. 그리고 DIB의 픽셀 데이터를 한 줄씩 참조하여 IppImage의 픽셀 데이터로 복사한다.
#include "stdafx.h" #include <assert.h> #include "IppConvert.h" void IppDibToImage(IppDib& dib, IppByteImage& img) { assert(dib.IsValid()); assert(dib.GetBitCount() == 8); int w = dib.GetWidth(); int h = dib.GetHeight(); int ws = (w + 3) & ~3; BYTE* pDIBits = dib.GetDIBitsAddr(); img.CreateImage(w, h); BYTE** pixels = img.GetPixels2D(); for (int i = 0; i < h; i++) { memcpy(pixels[i], &pDIBits[(h - 1 - i) * ws], w); } } void IppDibToImage(IppDib& dib, IppRgbImage& img) { assert(dib.IsValid()); assert(dib.GetBitCount() == 24); int w = dib.GetWidth(); int h = dib.GetHeight(); int ws = (w * 3 + 3) & ~3; BYTE* pDIBits = dib.GetDIBitsAddr(); img.CreateImage(w, h); RGBBYTE** pixels = img.GetPixels2D(); for (int i = 0; i < h; i++) { memcpy(pixels[i], &pDIBits[(h - 1 - i) * ws], w * 3); } }