Esempio n. 1
0
bool CImageEx::SetGray()
{
	CImage *pImage = &m_ImageClone;
	if ( pImage == NULL && pImage->IsNull() ) 
	{
		pImage = this;
	}

	int nWidth = pImage->GetWidth();
	int nHeight = pImage->GetHeight();

	BYTE* pArray = (BYTE*)pImage->GetBits();
	int nPitch = pImage->GetPitch();
	int nBitCount = pImage->GetBPP() / 8;

	for (int i = 0; i < nHeight; i++) 
	{
		for (int j = 0; j < nWidth; j++) 
		{
			int grayVal = (BYTE)(((*(pArray + nPitch * i + j * nBitCount) * 306)
				+ (*(pArray + nPitch * i + j * nBitCount + 1) * 601)
				+ (*(pArray + nPitch * i + j * nBitCount + 2) * 117) + 512 ) >> 10);	// 计算灰度值

			*(pArray + nPitch * i + j * nBitCount) = grayVal;							// 赋灰度值
			*(pArray + nPitch * i + j * nBitCount + 1) = grayVal;
			*(pArray + nPitch * i + j * nBitCount + 2) = grayVal;
		}
	}

	return true;
}
Esempio n. 2
0
static BOOL CImageToMat(const CImage& image, Mat& img)
{
	img.create(image.GetHeight(), image.GetWidth(), CV_8UC3);
	if (img.data == NULL)
		return FALSE;

	// 支持24位、32位图
	int bpp = image.GetBPP() / 8;
	if (bpp < 3)
		return FALSE;
	for (int y = 0; y < image.GetHeight(); y++)
	{
		BYTE* src = (BYTE*)image.GetPixelAddress(0, y);
		BYTE* dst = img.ptr<BYTE>(y);
		for (int x = 0; x < image.GetWidth(); x++)
		{
			dst[0] = src[0];
			dst[1] = src[1];
			dst[2] = src[2];
			src += bpp;
			dst += 3;
		}
	}
	return TRUE;
}
Esempio n. 3
0
void CChildView::OnSrtpEnvironmentbrdf()
{
	CWaitCursor wait;//在函数执行过程中使鼠标图标变成等待图标
	int newX = 256, newY = 256;
	CImage tmpimg;
	tmpimg.Create(newX, newY, 24, 0);
	float NoV, roughness;
	float* res = new float[2];
	for (int x = 0; x < newX; x++){
		NoV = x*1.0f / newX;
		for (int y = 0; y < newY; y++){
			roughness = y*2.0f / newY;
			IntegrateBRDF(res, roughness, NoV);
			tmpimg.SetPixelRGB(x, y, (byte)(res[0] * 255), (byte)(res[1] * 255), 0);
		}
	}
	delete[] res;
	imgOriginal.Destroy();
	imgOriginal.Create(newX, newY, tmpimg.GetBPP());//根据新的大小建立CImage,GetBPP是获取其大小
	for (int x = 0; x < newX; x++){
		for (int y = 0; y < newY; y++){
			imgOriginal.SetPixel(x, y, tmpimg.GetPixel(x, y));
		}
	}
	tmpimg.Destroy();
	//刷新显示图像
	Invalidate();
	UpdateWindow();
}
Esempio n. 4
0
double img_get_pxl(int img_no, int i, int j, int channel) {
	// Reading input texture sample
	CImage* pImage = saved_images[img_no];
	unsigned char *pData = (unsigned char*)pImage->GetBits();
	int pitch = pImage->GetPitch();
	int byte_pp = pImage->GetBPP() / 8;
	//fout << "Initial sizeof: " << sizeof(pData) << std::endl;
	if (pitch < 0)
	{
		//fout << "NEGATIVE; pitch = " << pitch << std::endl;
		pData += pitch * (image_shapes[img_no].second - 1);
		//pitch = -pitch;
	}
	/*for (int i = 0; i < pImage->GetHeight(); i++) // Image lines
	{
		for (int j = 0; j < pImage->GetWidth(); j++) // Pixels in line
		{
			unsigned char b = pCurrentLine[j * 4];
			unsigned char g = pCurrentLine[j * 4 + 1];
			unsigned char r = pCurrentLine[j * 4 + 2];
			unsigned char alpha = pCurrentLine[j * 4 + 3];
		}
		pCurrentLine += pitch;
	}*/
	//fout << i << ' ' << pitch << ' ' << j << ' ' << byte_pp << ' ' << channel << std::endl << i * pitch + j * byte_pp + channel <<
	//	' ' << sizeof(pData) << std::endl;
	unsigned char *pxl_addr = (unsigned char *)pImage->GetPixelAddress(i, j); // j, i?
	double pxl = double(*(pxl_addr + channel));
	return pxl;
}
Esempio n. 5
0
BOOL CChildView::OnEraseBkgnd(CDC* pDC)
{
    CRect r;

    CImage img;
    img.Attach(m_img);

    if ((m_pMainFrame->GetLoadState() != MLS::CLOSED || (!m_bFirstMedia && m_pMainFrame->m_controls.DelayShowNotLoaded())) &&
            !m_pMainFrame->IsD3DFullScreenMode() && !m_pMainFrame->m_fAudioOnly) {
        pDC->ExcludeClipRect(m_vrect);
    } else if (!img.IsNull()) {
        const double dImageAR = double(img.GetWidth()) / img.GetHeight();

        GetClientRect(r);
        int width = r.Width();
        int height = r.Height();
        if (!m_bCustomImgLoaded) {
            // Limit logo size
            // TODO: Use vector logo to preserve quality and remove limit.
            width = std::min(img.GetWidth(), width);
            height = std::min(img.GetHeight(), height);
        }

        double dImgWidth = height * dImageAR;
        double dImgHeight;
        if (width < dImgWidth) {
            dImgWidth = width;
            dImgHeight = dImgWidth / dImageAR;
        } else {
            dImgHeight = height;
        }

        int x = std::lround((r.Width() - dImgWidth) / 2.0);
        int y = std::lround((r.Height() - dImgHeight) / 2.0);

        r = CRect(CPoint(x, y), CSize(std::lround(dImgWidth), std::lround(dImgHeight)));

        if (!r.IsRectEmpty()) {
            if (m_resizedImg.IsNull() || r.Width() != m_resizedImg.GetWidth() || r.Height() != m_resizedImg.GetHeight() || img.GetBPP() != m_resizedImg.GetBPP()) {
                m_resizedImg.Destroy();
                m_resizedImg.Create(r.Width(), r.Height(), std::max(img.GetBPP(), 24));

                HDC hDC = m_resizedImg.GetDC();
                SetStretchBltMode(hDC, STRETCH_HALFTONE);
                img.StretchBlt(hDC, 0, 0, r.Width(), r.Height(), SRCCOPY);
                m_resizedImg.ReleaseDC();
            }

            m_resizedImg.BitBlt(*pDC, r.TopLeft());
            pDC->ExcludeClipRect(r);
        }
    }
    img.Detach();

    GetClientRect(r);
    pDC->FillSolidRect(r, 0);

    return TRUE;
}
void Csmoothorsharp::FilterImg(int* temp,CImage imga){
	
	int nW=imga.GetWidth()-1;
	int nH=imga.GetHeight()-1;


	byte *pRealData;
	pRealData=(byte*)imga.GetBits();
	int pit=imga.GetPitch();
	int bitCount=imga.GetBPP()/8;

	for (int i=1;i<nH;i++)
	{
		for (int j=1;j<nW;j++)
		{
			int Rval=0,Gval=0,Bval=0,indx=0;
			for ( int row=-1;row<=1;row++)
			{
				for (int col=-1;col<=1;col++)
				{
					 Bval+=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount))) *temp[indx];
					 Gval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+1)))*temp[indx];
					 Rval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+2)))*temp[indx];
					 indx++;
				}
			}
//template work is over,You need get the center point pixel.
			Rval=(int)(Rval*cval);
			if (Rval>255)
				Rval=255;
			else if(Rval<0)
				Rval=0;

			Gval=(int)(Gval*cval);
			if (Gval>255)
				Gval=255;
			else if(Gval<0)
				Gval=0;

			Bval=(int)(Bval*cval);
			if (Bval>255)
				Bval=255;
			else if (Bval<0)
				Bval=0;

//ok,write the new pixel into the pic.
			*(pRealData+pit*(i-1)+(j-1)*bitCount)=Bval;
			*(pRealData+pit*(i-1)+(j-1)*bitCount+1)=Gval;
			*(pRealData+pit*(i-1)+(j-1)*bitCount+2)=Rval;
		}
	}




//CALL the OnDraw in MFC
	
}
Esempio n. 7
0
UINT InverseThread(LPVOID pParam)
{
	LANGID id = PIGetThreadUILanguage();
	SetThreadUILanguage(id);

	CString str;
	str.LoadString(ID_IMAGE_INVERSE);
	PIProgressInit(PI_PROGRESS_DLG, str);
//	PIProgressInit(PI_PROGRESS_BAR, str);

	CImage* pImage = (CImage*)pParam;

	int nWidth = pImage->GetWidth();
	int nHeight = pImage->GetHeight();
	BYTE* pImageData = (BYTE*)pImage->GetBits();
	int nPitch = pImage->GetPitch();
	int nBitCount = pImage->GetBPP() / 8;

	for (int j=0; j<nHeight; j++)
	{
		for (int i=0; i<nWidth; i++)
		{
			int nPixelIndex = j * nPitch + i * nBitCount;
			BYTE* pPixel = pImageData + j * nPitch + i * nBitCount;
			*(pPixel) = 255 - *(pPixel);
			*(pPixel + 1) = 255 - *(pPixel + 1);
			*(pPixel + 2) = 255 - *(pPixel + 2);
		}

		LRESULT lResult = PIProgressPercent(j * 100 / nHeight);
		if (!lResult)
		{
			// quit thread
			return 1;
		}
	}

	PIProgressDone();

	// refresh view
	PIGetActiveView()->Invalidate(FALSE);

	return 0;
}
//
// Copies the content of a byte buffer to a MFC image with respect to the image's alignment
//
// Parameters:
//  [in]    pInbuffer       The byte buffer as received from the cam
//  [in]    ePixelFormat    The pixel format of the frame
//  [out]   OutImage        The filled MFC image
//
void CAsynchronousGrabDlg::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, CImage &OutImage )
{
    const int               nHeight         = m_ApiController.GetHeight();
    const int               nWidth          = m_ApiController.GetWidth();
    const int               nStride         = OutImage.GetPitch();
    const int               nBitsPerPixel   = OutImage.GetBPP();
    VmbError_t              Result;
    if( ( nWidth*nBitsPerPixel ) /8 != nStride )
    {
        Log( _TEXT( "Vimba only supports stride that is equal to width." ), VmbErrorWrongType );
        return;
    }
    VmbImage                SourceImage,DestinationImage;
    SourceImage.Size        = sizeof( SourceImage );
    DestinationImage.Size   = sizeof( DestinationImage );

    SourceImage.Data        = pInBuffer;
    DestinationImage.Data   = OutImage.GetBits();

    Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, &SourceImage );
    if( VmbErrorSuccess != Result )
    {
        Log( _TEXT( "Error setting source image info." ), static_cast<VmbErrorType>( Result ) );
        return;
    }
    static const std::string DisplayFormat( "BGR24" );
    Result = VmbSetImageInfoFromString( DisplayFormat.c_str(),DisplayFormat.size(), nWidth,nHeight, &DestinationImage );
    if( VmbErrorSuccess != Result )
    {
        Log( _TEXT( "Error setting destination image info." ),static_cast<VmbErrorType>( Result ) );
        return;
    }
    Result = VmbImageTransform( &SourceImage, &DestinationImage,NULL,0 );
    if( VmbErrorSuccess != Result )
    {
        Log( _TEXT( "Error transforming image." ), static_cast<VmbErrorType>( Result ) );
    }
}
Esempio n. 9
0
bool LoadPicture(CImage& bmp, UINT nImgID, LPCTSTR lpImgType)			//含Alpha通道的图片处理成CImage
{
	LoadImageFromResourse(&bmp, nImgID, lpImgType);					//加载图片资源

	if (bmp.IsNull())
	{
		return false;
	}
	if(bmp.GetBPP() == 32)												//确认该图片包含Alpha通道
	{
		for (int i=0; i < bmp.GetWidth(); i++)
		{
			for(int j=0; j < bmp.GetHeight(); j++)
			{
				byte* pByte = (byte*)bmp.GetPixelAddress(i, j);
				pByte[0] = pByte[0] * pByte[3] / 255;
				pByte[1] = pByte[1] * pByte[3] / 255;
				pByte[2] = pByte[2] * pByte[3] / 255;
			}
		}
	}

	return true;
}
Esempio n. 10
0
BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
{
    VERIFY(__super::CreateEx(pParentWnd,
                             TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_AUTOSIZE | TBSTYLE_CUSTOMERASE,
                             WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_TOOLTIPS,
                             CRect(2, 2, 0, 1)));

    VERIFY(LoadToolBar(IDB_PLAYERTOOLBAR));

    // Should never be RTLed
    ModifyStyleEx(WS_EX_LAYOUTRTL, WS_EX_NOINHERITLAYOUT);

    CToolBarCtrl& tb = GetToolBarCtrl();
    tb.DeleteButton(tb.GetButtonCount() - 1);
    tb.DeleteButton(tb.GetButtonCount() - 1);

    SetMute(AfxGetAppSettings().fMute);

    UINT styles[] = {
        TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP,
        TBBS_SEPARATOR,
        TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON,
        TBBS_SEPARATOR,
        TBBS_BUTTON,
        TBBS_SEPARATOR,
        TBBS_SEPARATOR,
        TBBS_CHECKBOX,
    };

    for (int i = 0; i < _countof(styles); ++i) {
        // This fixes missing separator in Win 7
        if (styles[i] & TBBS_SEPARATOR) {
            SetButtonInfo(i, GetItemID(i), styles[i], -1);
        } else {
            SetButtonStyle(i, styles[i] | TBBS_DISABLED);
        }
    }

    m_volctrl.Create(this);
    m_volctrl.SetRange(0, 100);

    m_nButtonHeight = 16; // reset m_nButtonHeight
    CImage image;
    if (LoadExternalToolBar(&image)) {
        CBitmap* bmp = CBitmap::FromHandle(image);
        int width = image.GetWidth();
        int height = image.GetHeight();
        int bpp = image.GetBPP();
        if (width == height * 15) {
            // the manual specifies that sizeButton should be sizeImage inflated by (7, 6)
            SetSizes(CSize(height + 7, height + 6), CSize(height, height));

            m_pButtonsImages = DEBUG_NEW CImageList();
            if (bpp == 32) {
                m_pButtonsImages->Create(height, height, ILC_COLOR32 | ILC_MASK, 1, 0);
                m_pButtonsImages->Add(bmp, nullptr); // alpha is the mask
            } else {
                m_pButtonsImages->Create(height, height, ILC_COLOR24 | ILC_MASK, 1, 0);
                m_pButtonsImages->Add(bmp, RGB(255, 0, 255));
            }
            m_nButtonHeight = height;
            GetToolBarCtrl().SetImageList(m_pButtonsImages);
        }
        image.Destroy();
    }

    return TRUE;
}
Esempio n. 11
0
//根据文件路径获取单张图片
Texture2D* TextureLoader::CreateTexture2D(const char* fileName)
{	

	GLuint texture;
	glGenTextures(1, &texture);
	glBindTexture( GL_TEXTURE_2D, texture);
    CImage *img = new CImage;		// 新建CImage对象
	char *complete_path = FileTool::GetInstance()->GetCompletePath(fileName);
	if (complete_path == NULL)
	{
		SAFDelete(img);
		return NULL;
	}
	wchar_t *wchat_file_name = ATC2W(complete_path);
	img->Load(wchat_file_name);			// 读入图像文件
	SAFDelete(wchat_file_name);
	SAFDelete(complete_path);
    int width = img->GetWidth();	// 获取图像宽度
    int height = img->GetHeight();	// 获取图像高度
    int n = img->GetBPP() / 8;
    int test = img->GetPitch();//图片是正的还是反的
    GLubyte *image = new GLubyte[width * height * n];	// 用于保存图像数据的数组
    // 将图像数据读入image数组
    if(test<0)
        for(int j = height-1,k=0; j >=0; j--,k++){
            for(int i = width-1,z=width-1; i >=0; i--,z--){
                int index = (k * width + z) * n;
                RGBQUAD rgb = GetPixelColor(img, i, j);
                image[index] = rgb.rgbRed;
                image[index+1] = rgb.rgbGreen;
                image[index+2] = rgb.rgbBlue;
                if(n==4)
                    image[index+3] = rgb.rgbReserved;
            }
        }
    else
        for(int j = 0; j < height; j++){
            for(int i = 0; i < width; i++){
                int index = (j * width + i) * n;
                RGBQUAD rgb = GetPixelColor(img, i, j);
                image[index] = rgb.rgbRed;
                image[index+1] = rgb.rgbGreen;
                image[index+2] = rgb.rgbBlue;
                if(n==4)
                    image[index+3] = rgb.rgbReserved;
            }
        }

    delete img;		// CImage对象已无用,数据已读入image数组
    // 根据image中的数据在纹理内存中创建纹理
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);	// 每行图像数据紧密排列
    if(n==4)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
    else
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

	
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    delete image;	// 纹理数据已在显卡纹理内存中了,主机内存中的image已无用

	Texture2D *tex = new Texture2D();
	tex->texture_name_ = fileName;
	tex->height_ = height;
	tex->width_ = width;
	tex->tex_res_ = texture;
	return tex;
}
Esempio n. 12
0
bool CScene::OnProcessingWindowMessage(HWND hWnd, UINT nMessageID, WPARAM wParam, LPARAM lParam)
{
    switch (nMessageID)
    {
    case WM_DROPFILES:
    {
        HDROP hDrop = (HDROP)wParam;
        TCHAR szPathFileName[MAX_PATH + 1];
        DragQueryFile(hDrop, 0, szPathFileName, MAX_PATH);

        if (m_cImage) {
            DeleteObject(m_cImage);
            m_cImage = nullptr;
        }
        if (m_hIcon) {
            DestroyIcon(m_hIcon);
            m_hIcon = nullptr;
        }

        std::wstring strExtension(PathFindExtension(szPathFileName));
        if (   strExtension == TEXT(".png")
                || strExtension == TEXT(".jpg")
                || strExtension == TEXT(".bmp")
                || strExtension == TEXT(".jpeg")
                || strExtension == TEXT(".PNG")
                || strExtension == TEXT(".JPG")
                || strExtension == TEXT(".JPEG")
                || strExtension == TEXT(".BMP")
           )
        {
            CImage m_cImageSumnail;
            m_cImageSumnail.Load(szPathFileName);

            float height = (float)m_cImageSumnail.GetHeight();
            float width = (float)m_cImageSumnail.GetWidth();
            bool bStand = false;
            int space = 0;
            if (height > width) {
                bStand = true;
                width /= height;
                height = 1;
            }
            else if (height < width) {
                bStand = false;
                height /= width;
                width = 1;
            }
            else {
                height = width = 1;
            }

            height *= 64.f;
            width *= 64.f;

            space = 32 - (bStand ? width : height) * 0.5f;

            CImage cImage;
            cImage.Create(64, 64, 32, CImage::createAlphaChannel);

            HDC hdc = cImage.GetDC();
            RECT rc = { 0,0,64,64 };
            SetDCBrushColor(hdc, RGB(255, 0, 255));
            FillRect(hdc, &rc, (HBRUSH)GetStockObject(DC_BRUSH));
            if (bStand)	m_cImageSumnail.TransparentBlt(hdc, int(space), 0, int(width), int(height), RGB(255, 0, 255));
            else		m_cImageSumnail.TransparentBlt(hdc, 0, int(space), int(width), int(height), RGB(255, 0, 255));
            cImage.ReleaseDC();

            ///////////////////////////////////////////////////////

            BITMAPINFO m_bif;
            ZeroMemory(&m_bif, sizeof(BITMAPINFO));

            // 비트맵(DDB) 정보 얻기
            BITMAP bmp;
            GetObject(cImage, sizeof(BITMAP), &bmp);

            // 비트맵(DIB) 정보 설정
            BITMAPINFOHEADER& bmih = m_bif.bmiHeader;
            ZeroMemory(&bmih, sizeof(BITMAPINFOHEADER));
            bmih.biSize = sizeof(BITMAPINFOHEADER);
            bmih.biWidth = bmp.bmWidth;    // 가로
            bmih.biHeight = bmp.bmHeight;  // 세로
            bmih.biPlanes = 1;
            bmih.biBitCount = cImage.GetBPP();          // 픽셀당 비트수(BPP)
            bmih.biCompression = BI_RGB;

            // 비트맵(DIB) 데이터 추출
            // 데이터의 크기를 알아낸다
            HDC hDC = GetDC(NULL);
            GetDIBits(hDC, cImage, 0, bmp.bmHeight, NULL,
                      (LPBITMAPINFO)&bmih, DIB_RGB_COLORS);

            DWORD m_dwImageSize = bmih.biSizeImage;

            // 데이터 저장 공간 확보
            LPBYTE m_bytes = new BYTE[m_dwImageSize];
            GetDIBits(hDC, cImage, 0, bmp.bmHeight, m_bytes, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS);
            ReleaseDC(NULL, hDC);

            size_t cnt = 0;
            for (int y = 0; y < m_bif.bmiHeader.biHeight; y++)  for (int x = 0; x < m_bif.bmiHeader.biWidth; x++)
                {
                    if (!(m_bytes[cnt] == 255 && m_bytes[cnt + 1] == 0 && m_bytes[cnt + 2] == 255))
                        m_bytes[cnt + 3] = 255;
                    cnt += 4;
                }

            LPVOID pNewBytes;
            m_cImage = ::CreateDIBSection(NULL, &m_bif, DIB_RGB_COLORS, &pNewBytes, 0, 0);

            hDC = GetDC(NULL);

            SetDIBits(hDC, m_cImage, 0, m_bif.bmiHeader.biHeight, m_bytes, &m_bif, DIB_RGB_COLORS);

            ReleaseDC(NULL, hDC);


            m_cImageSumnail.Destroy();
            cImage.Destroy();
            delete[] m_bytes;


        }
        else
        {
            SHFILEINFO sfi;
            ZeroMemory(&sfi, sizeof(SHFILEINFO));
            SHGetFileInfo(szPathFileName, 0, &sfi, sizeof(SHFILEINFO),
                          SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME);

            m_hIcon = sfi.hIcon;

        }
    }
    default:
        return false;
    }
    return true;
}
Esempio n. 13
0
void CStorageDoc::OnFileImport () {
	CFile		fImport;
	CFileDialog	dlgOpen (true);
	// #### TODO: Place here initial directory name taken from configuration structures
	dlgOpen.m_ofn.lpstrInitialDir = ".";
	dlgOpen.m_ofn.lpstrFilter = "Kontron Elektronik Images (*.img)""\0""*.IMG""\0"
		"All supported signle image formats""\0""*.JPG;*.JPEG;*.GIF;*.PNG;*.BMP;*.DIB""\0"
		"JPEG Bitmap (*.jpg, *.jpeg)""\0""*.JPG;*.JPEG""\0"
		"CumpuServe GIF (*.gif)""\0""*.GIF""\0"
		"Prtable Network Graphics (*.png)""\0""*.PNG""\0"
		"MS Windows Bitmap (*.bmp, *.dib)""\0""*.BMP;*.DIB""\0";
	dlgOpen.m_ofn.nFilterIndex = 1;
//	dlgOpen.SetWindowText (theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION));
	if (dlgOpen.DoModal () != IDOK)
		return;

	// #### TODO: Add support for video formats
	// #### TODO: Add support for multi-page tif format
	// #### TODO: Create import dialog
	// #### TODO: Add progress control on the status bar

	uvar32_64	selected;
	svar32_64	nImages;
	uvar32_64	dwSize = m_nDimX * m_nDimY;
	CString		strTitle;
	BYTE		*pbPixels = (BYTE *)aimMemoryCommit (dwSize, "CStorageDoc::OnDocAddImportseq", "pbPixels");


	if ((selected = Frames[aimActive].GetActiveImageNo()) == -1)
		selected = Images.GetCount () - 1;

	theApp.StatusState (IDI_INDICATOR_IMPORT);
	if (dlgOpen.m_ofn.nFilterIndex == 1) {
		if (!fImport.Open (dlgOpen.GetPathName (), CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite)) {
			MessageBox (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_IMPORTSEQ_OPENERR), theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION), MB_OK | MB_ICONERROR);
			return;
		}
		BYTE	*pbHeader = new BYTE[0x80];
		fImport.Read ( pbHeader, 0x80 );
		if (((DWORD*)(pbHeader + 2))[0] != 0xB06D1247) {
			MessageBox  (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_IMPORTSEQ_TYPEERR), theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION), MB_OK | MB_ICONERROR);
			return;
		}
		if (((WORD*)pbHeader)[5] != 0x4321) {
			MessageBox  (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_IMPORTSEQ_TYPEERR), theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION), MB_OK | MB_ICONERROR);
			return;
		}
		if (((WORD*)pbHeader)[3] != m_nDimX || ((WORD*)pbHeader)[4] != m_nDimY || m_nBPP != 8) {
			MessageBox  (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_IMPORTSEQ_SIZEERR), theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION), MB_OK | MB_ICONERROR);
			return;
		}
		nImages = ((WORD*)pbHeader)[6];

		theApp.StatusState (IDI_INDICATOR_IMPORT);
		while (--nImages >= 0) {
			strTitle.Format ("%s #%03d", dlgOpen.GetFileTitle (), ((WORD*)pbHeader)[6] - nImages);
			CPicture *pImg = new CPicture (this, strTitle, "");
			fImport.Read (pbPixels, dwSize);
			pImg->Channels(aimAll).SetBits (pbPixels, dwSize);
			Images.Insert (selected++, *pImg);
		}
		nImages = ((WORD*)pbHeader)[6];

		fImport.Close ();
		delete [] pbHeader;
		aimMemoryRelease (pbPixels, "CStorage::OnDocAddImportseq", "pbPixels");
	} else if (dlgOpen.m_ofn.nFilterIndex >= 2) {
		CImage image;
		image.Load (dlgOpen.GetPathName ());
		if (image.GetBPP () != m_nBPP || image.GetHeight () != m_nDimY || image.GetWidth () != m_nDimX) {
			MessageBox  (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_IMPORTSEQ_SIZEERR), theApp.LoadString (IDS_IMPORTSEQ_DLGCAPTION), MB_OK | MB_ICONERROR);
			return;
		}
		CPicture *pImg = new CPicture (this, dlgOpen.GetFileTitle (), "");
		ubyte *pBits;
		if (image.IsDIBSection () && image.GetPitch () < 0)
			pBits = (ubyte*)image.GetBits () - (m_nDimY - 1) * m_nDimX;
		else
			pBits = (ubyte*)image.GetBits ();
		pImg->Channels(aimAll).SetBits (pBits, m_nDimX * m_nDimY * m_nBPP / 8);
		Images.Insert (selected++, *pImg);
	}

	theApp.StatusState (0);
}
/*
	OnDraw()
*/
void CWallBrowserStretchView::OnDraw(CDC* pDC)
{
	// documento
	CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument();
	if(!pDoc)
		return;

	// nome file
	memset(m_szFileName,'\0',sizeof(m_szFileName));
	strcpyn(m_szFileName,pDoc->GetFileName(),sizeof(m_szFileName));
	if(m_szFileName[0]=='\0')
		return;

	// immagine
	CImage *pImage = pDoc->GetImage();
	if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0)
		m_ImageDraw.SetImage(pImage);
	else
		return;

	// immagine valida
	if(!pDoc->GetPictureFlag())
		return;

	// dimensione corrente della vista
	GetClientRect(&m_rcClient);

	// adatta l'immagine alla dimensione corrente della vista
	double nRemains = 0.0;
	double nWidth   = (double)pImage->GetWidth();
	double nHeight  = (double)pImage->GetHeight();

	if(nHeight > (double)m_rcClient.bottom)
	{
		nRemains = FDIV(nHeight,(double)m_rcClient.bottom);
		if(nRemains > 0.0)
		{
			nHeight = FDIV(nHeight,nRemains);
			nWidth  = FDIV(nWidth,nRemains);
		}
	}
	if(nWidth > (double)m_rcClient.right)
	{
		nRemains = FDIV(nWidth,(double)m_rcClient.right);
		if(nRemains > 0.0)
		{
			nHeight = FDIV(nHeight,nRemains);
			nWidth  = FDIV(nWidth,nRemains);
		}
	}

	m_rcInvalid.SetRect(0,0,(int)nWidth,(int)nHeight);

	// nome del file
	if(m_pMainFrameStatusBar)
	{
		strcpyn(m_szStatus,pDoc->GetFileName(),sizeof(m_szStatus));
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILENAME_ID,m_szStatus);
	}

	double nFactor = 0.0;
	char szFactor[8] = {0};
	if(m_nViewType==VIEWTYPE_SCROLL)
	{
		nFactor = GetZoomRatio();
		if(nFactor >= 1.0)
			sprintf(szFactor,"%.2f:1",nFactor);
		else
			sprintf(szFactor,"1:%.2f",1/nFactor);
	}

	// fattore di zoom e % di visualizzazione dell'immagine nella vista
	int nRatio = (int)((nWidth * 100.0)/pImage->GetWidth());
	if(m_pMainFrameStatusBar)
	{
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_ZOOM_ID,szFactor);
		
		if(m_nViewType==VIEWTYPE_STRETCH)
			_snprintf(m_szStatus,sizeof(m_szStatus)-1,"%d%% (stretch)",nRatio);
		else
			_snprintf(m_szStatus,sizeof(m_szStatus)-1,"%.1f%% (scroll)",nFactor * 100.0);
		
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_RATIO_ID,m_szStatus);
	}
	
	// area della vista (client rect)
	m_rcClient.right  = (int)nWidth;
	m_rcClient.bottom = (int)nHeight;

	// ricava le informazioni per il titolo
	char szTitle[_MAX_PATH+1] = {0};
	int nColors = pImage->GetNumColors();
	if(m_nViewType==VIEWTYPE_STRETCH)
		_snprintf(szFactor,sizeof(szFactor)-1,"%d%%",nRatio);
	_snprintf(szTitle,
			sizeof(szTitle)-1,
			"%s (%s) - %d x %d x %d%s",
			pDoc->GetFileName(),
			szFactor,
			pImage->GetWidth(),
			pImage->GetHeight(),
			(nColors > 256 || nColors==0) ? 16 : nColors,
			(nColors > 256 || nColors==0) ? "M" : ""
			);
	pDoc->SetTitle(szTitle);

	// ricava le informazioni per la status bar
	if(m_pMainFrameStatusBar)
	{
		int nColors = pImage->GetNumColors();
		_snprintf(m_szStatus,
				sizeof(m_szStatus)-1,
				"%d x %d x %d%s colors, %d bpp",
				pImage->GetWidth(),
				pImage->GetHeight(),
				(nColors > 256 || nColors==0) ? 16 : nColors,
				(nColors > 256 || nColors==0) ? "M" : "",
				pImage->GetBPP()
				);
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_INFO_ID,m_szStatus);

		UINT nMemUsed = pImage->GetMemUsed();
		if(nMemUsed < 1024L)
			_snprintf(m_szStatus,sizeof(m_szStatus)-1,"%ld bytes",nMemUsed);
		else if(nMemUsed < 1048576L)
			_snprintf(m_szStatus,sizeof(m_szStatus)-1,"%0.1f KB",FDIV(((float)nMemUsed),1024.0f));
		else
			_snprintf(m_szStatus,sizeof(m_szStatus)-1,"%0.2f MB",FDIV(((float)nMemUsed),1048576.0f));
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_MEM_ID,m_szStatus);

		strcpyn(m_szStatus,pImage->GetLibraryName(),sizeof(m_szStatus));
		m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_LIBRARY_ID,m_szStatus);
	}
	
	// area dell'immagine
	CRect rcImg(0,0,pImage->GetWidth(),pImage->GetHeight());

	// se per la vista deve usare lo scroll, imposta le aree in modo tale che vengano visualizzate le barre di scorrimento
	if(m_nViewType==VIEWTYPE_SCROLL)
		m_rcClient = rcImg;

	// visualizza l'immagine scalata rispetto alla dimensione corrente della vista
	m_ImageDraw.DrawEx(pDC->GetSafeHdc(),
					&m_rcClient,
					&rcImg,
					NULL,
					FALSE,
					COLORONCOLOR,
					m_nDrawMode,
					SRCCOPY,
					m_bRebuildPalette
					);

	m_bRebuildPalette = FALSE;
}