사진 4장 뒤집기..

----Doc

public:

HGLOBAL m_hFile[4];

int m_nWidth;

int m_nHeight;

void OnImageHorizon(int Index);//함수

void OnImageVertical(int Index);//함수

CRrDoc::CRrDoc()

{	for (int x=0;x<4;x++)	{m_hFile[x] = NULL;	}}

void CRrDoc::OnImageVertical(int Index)

{	if (m_hFile[Index] == NULL) return;

LPBYTE pFile = (LPBYTE)GlobalLock(m_hFile[Index]);

LPBYTE pImage = pFile + ((BITMAPFILEHEADER *)pFile)->bfOffBits;

int nBytesPerLine = (m_nWidth*3 + 3) / 4 * 4;

for (int y=0; y<m_nHeight/2; y++) {

LPBYTE p1 = pImage + y * nBytesPerLine;

LPBYTE p2 = pImage + (m_nHeight-1-y) * nBytesPerLine;

BYTE temp[512*3];

memcpy(temp, p1, nBytesPerLine);

memcpy(p1, p2, nBytesPerLine);

memcpy(p2, temp, nBytesPerLine);	}

GlobalUnlock(m_hFile[Index]);

UpdateAllViews(NULL);}

void CRrDoc::OnImageHorizon(int Index)

{	LPBYTE pFile = (LPBYTE)GlobalLock(m_hFile[Index]);

LPBYTE pImage = pFile + ((BITMAPFILEHEADER *)pFile)->bfOffBits;

int nBytesPerLine = (m_nWidth*3 + 3) / 4 * 4;

for (int y=0; y<m_nHeight; y++) {

LPBYTE p1 = pImage + y * nBytesPerLine;

LPBYTE p2 = p1 + (m_nWidth-1)*3;

for (int x=0; x<m_nWidth/2; x++) {

BYTE temp[3];

memcpy(temp, p1, 3);memcpy(p1, p2, 3);memcpy(p2, temp, 3);

p1 += 3;	p2 -= 3;}	}

GlobalUnlock(m_hFile[Index]);	UpdateAllViews(NULL);}

BOOL CRrDoc::OnOpenDocument(LPCTSTR lpszPathName)

{	for (int x=0; x<4; x++)

{

if (m_hFile != NULL) GlobalFree(m_hFile[x]);

CFile file;

file.Open(lpszPathName, CFile::modeRead);

DWORD dwFileSize = file.GetLength();

m_hFile[x] = GlobalAlloc(GHND, dwFileSize);

LPBYTE pFile = (LPBYTE)GlobalLock(m_hFile[x]);

file.Read(pFile, dwFileSize);

file.Close();

BITMAPINFOHEADER *pbmpInfoHeader = (BITMAPINFOHEADER *)(pFile + sizeof(BITMAPFILEHEADER));

m_nWidth = pbmpInfoHeader->biWidth;

m_nHeight = pbmpInfoHeader->biHeight;

GlobalUnlock(m_hFile[x]);	}

OnImageHorizon(1);// 우상 좌우 반전

OnImageVertical(2);// 좌하 상하 반전

OnImageHorizon(3);OnImageVertical(3); // 우하 상하좌우반전}

----------view

void CRrView::OnDraw(CDC* pDC)

{	if (pDoc->m_hFile[0] == NULL) return;

LPBYTE pFile;

LPBYTE pImage;

BITMAPINFO *pbmpInfo;

for (int x=0; x<4; x++)

{	int px, py;

switch (x)

{	case 0: px=0; py=0; break;

case 1: px=256; py=0;; break;

case 2: px=0; py=256; break;

case 3: px=256; py=256; break;	}

pFile = (LPBYTE)GlobalLock(pDoc->m_hFile[x]);

pImage = pFile + ((BITMAPFILEHEADER *)pFile)->bfOffBits;

pbmpInfo = (BITMAPINFO *)(pFile + sizeof(BITMAPFILEHEADER));

SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);

SetDIBitsToDevice(pDC->m_hDC, 0+px, 0+py, pDoc->m_nWidth, pDoc->m_nHeight, 0, 0, 0,

pDoc->m_nHeight, pImage, pbmpInfo, DIB_RGB_COLORS);

GlobalUnlock(pDoc->m_hFile[x]);}}