#include "StdAfx.h" #include "SharedImageData.h" CSharedImageData::CSharedImageData(void) { m_pSMImageData = NULL; m_nImageCount = 0; m_nImageInfoSize = sizeof(SSharedImageInfo); //m_nMaxImageSize = 2456 * 2058 * 4; m_nMaxImageSize = 2464 * 2056 * 4; m_hAsignedMemory = NULL; m_pSharedMemory = NULL; m_pImageInfo = NULL; m_pImageData = NULL; } CSharedImageData::~CSharedImageData(void) { DeleteMemory(); } void CSharedImageData::DeleteMemory() { if(m_pSharedMemory) { UnmapViewOfFile(m_pSharedMemory); m_pSharedMemory = NULL; } if(m_hAsignedMemory) { CloseHandle(m_hAsignedMemory); m_hAsignedMemory = NULL; } if (m_pSMImageData) { for (int i=0; i=m_nImageCount) return 0; if (m_pImageInfo[nIndex]) { return m_pImageInfo[nIndex]->nUpdated; } return 0; } int CSharedImageData::GetSelected(int nIndex) { if (nIndex<0 || nIndex>=m_nImageCount) return 0; if (m_pImageInfo[nIndex]) { return m_pImageInfo[nIndex]->nSelected; } return 0; } BOOL CSharedImageData::LockImageData(int nIndex) { if (nIndex<0 || nIndex>=m_nImageCount) return FALSE; if (m_pSMImageData[nIndex]) { m_pSMImageData[nIndex]->Lock(); } else { return FALSE; } return TRUE; } BOOL CSharedImageData::UnlockImageData(int nIndex) { if (nIndex<0 || nIndex>=m_nImageCount) return FALSE; if (m_pImageInfo[nIndex]) { m_pImageInfo[nIndex]->nUpdated--; } else { return FALSE; } if (m_pSMImageData[nIndex]) { m_pSMImageData[nIndex]->Unlock(); } else { return FALSE; } return TRUE; } const BYTE* CSharedImageData::GetImageData(int nIndex) { if (nIndex<0 || nIndex>=m_nImageCount) return NULL; return m_pImageData[nIndex]; } const SSharedImageInfo* CSharedImageData::GetImageInfo(int nIndex) { if (nIndex<0 || nIndex>=m_nImageCount) return NULL; return m_pImageInfo[nIndex]; } BOOL CSharedImageData::SetImageData(int nIndex, SSharedImageInfo *pImageInfo, BYTE* pImageData) { if (pImageInfo==NULL || pImageData==NULL) return FALSE; if(m_hAsignedMemory==NULL) return FALSE; if (nIndex<0 || nIndex>=m_nImageCount) return FALSE; int nSrcSize = pImageInfo->nImageWidthStep * pImageInfo->nImageHeight; if (nSrcSize>m_nMaxImageSize) return FALSE; if (m_pSMImageData[nIndex]==NULL) return FALSE; m_pSMImageData[nIndex]->Lock(); // 함수를 Atomic 하게 동작시키자 // 이미지 정보 기록 pImageInfo->nUpdated = 1; memcpy(m_pImageInfo[nIndex], pImageInfo, m_nImageInfoSize); // 이미지 기록 memcpy(m_pImageData[nIndex], pImageData, nSrcSize); m_pSMImageData[nIndex]->Unlock();// 함수 동기화 종료 return TRUE; }