Exemplo n.º 1
0
static BOOL WriteDIBClip(
/************************************************************************/
LPBITMAPINFOHEADER lpInfo,
LPSTR lpImageFile,
LPSTR lpMaskFile)
{
FNAME szFileName;

if ( lpInfo->biSize != 40 || // make sure it's the correct length
	 lpInfo->biCompression != BI_RGB ) // no compression
	return(FALSE);

if ( lpImageFile )
	{
	if ( !WriteDIB(lpInfo, lpImageFile) )
		return(FALSE);
	}

if ( lpMaskFile )
	{
	if ( !WriteDIBMask(lpInfo, lpMaskFile) )
		{
		lstrcpy(szFileName, lpImageFile);
		FileDelete(szFileName);
		return(FALSE);
		}
	}

return(TRUE);
}
Exemplo n.º 2
0
	void Bitmap::Save(aiTexture* texture, IOStream* file) {
		if(file != NULL) {
			Header header;
			DIB dib;

			dib.size = DIB::dib_size;
			dib.width = texture->mWidth;
			dib.height = texture->mHeight;
			dib.planes = 1;
			dib.bits_per_pixel = 8 * mBytesPerPixel;
			dib.compression = 0;
			dib.image_size = (((dib.width * mBytesPerPixel) + 3) & 0x0000FFFC) * dib.height;
			dib.x_resolution = 0;
			dib.y_resolution = 0;
			dib.nb_colors = 0;
			dib.nb_important_colors = 0;

			header.type = 0x4D42; // 'BM'
			header.offset = Header::header_size + DIB::dib_size;
			header.size = header.offset + dib.image_size;
			header.reserved1 = 0;
			header.reserved2 = 0;

			WriteHeader(header, file);
			WriteDIB(dib, file);
			WriteData(texture, file);
		}
	}
Exemplo n.º 3
0
BOOL CImageBMP::SaveFile(const CString& imageFileName)
{                         
  if (imageFileName != "")
	 filename = imageFileName;

  HPALETTE hPal = 0;
  if (imagePalette)
    hPal = (HPALETTE) (*imagePalette);
    
  DibSetUsage(lpbi, hPal, DIB_RGB_COLORS);

  BOOL retValue = WriteDIB((const char *)imageFileName, lpbi);

  DibSetUsage(lpbi, hPal, DIB_PAL_COLORS);

  return retValue;

/*
//  return WriteDIB(ImageFileName, HandleFromDib(lpbi));
  // This was the original code used in wxImage, but the resulting
  // file isn't a valid BMP file.
  DibSetUsage(lpbi, (HPALETTE) (*imagePalette), DIB_RGB_COLORS);
  if (!DibWriteFile((char *)(const char *)filename, lpbi))
	return FALSE;
	else return TRUE;
*/
}
Exemplo n.º 4
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Создаем временный DIB куда отпишем, что получили
Bool32 CRIControl::CloseDestinationDIB(char*  cDIBName)
{
	Handle hDIB = NULL;
	pvoid  pDIB = NULL;

	if ( DIBOpeningType == TRUE )
	{
		return SetDestinationDIBtoStorage(cDIBName);
	}

	if ( !mpDestinationDIB )
		return FALSE;

	if ( !mpDestinationDIB->GetDIBHandle(&hDIB) ||
		 !mpDestinationDIB->GetDIBPtr( &pDIB )     )
	{
		delete mpDestinationDIB;
		mpDestinationDIB = NULL;
		return FALSE;
	}

	if ( !WriteDIB(cDIBName, pDIB) )
	{
		SetReturnCode_rimage(IDS_RIMAGE_NO_IMAGE_FOUND);
		return FALSE;
	}

	/*
	while ( mpDestinationDIB )
	{
		if ( mpDestinationDIB->DestroyDIB() )
		{
			hDIB = NULL;
		}
		else
		{
			if ( mpDestinationDIB->GetDIBHandle(&hDIB) )
			{
				RIMAGEUnlock(hDIB);
				RIMAGEFree(hDIB);
			}
			else
			{
				delete mpDestinationDIB;
				mpDestinationDIB = NULL;
			}
		}
	}
	*/
	delete mpDestinationDIB;
	mpDestinationDIB = NULL;

	return TRUE;
}
Exemplo n.º 5
0
void CImageWindow::Screenshot(BOOL bShotImage, BOOL bShotROI, LPCTSTR szFilePath)
{
	m_pImpl->Screenshot(bShotImage, bShotROI, __ddbScreenshot);

	HANDLE hDIB = DDBToDIB(m_pImpl->GetDC(), __ddbScreenshot, NULL);

	if( !hDIB ) return;

	WriteDIB(szFilePath, hDIB);

	::GlobalFree(hDIB);
}
Exemplo n.º 6
0
STDMETHODIMP DropTarget_Drop(DropTarget *dt,
			     IDataObject *ido,
			     DWORD keyState,
			     POINTL pt,
			     DWORD *effect) {
  STGMEDIUM medium;
  FORMATETC fmtetc;
  HRESULT hRes;

  freeDropFiles();

  DPRINTF(("DropTarget_Drop\n"));
  fmtetc.cfFormat = CF_HDROP;
  fmtetc.ptd = NULL;
  fmtetc.lindex = -1;
  fmtetc.dwAspect = DVASPECT_CONTENT;
  fmtetc.tymed = TYMED_HGLOBAL;
  DPRINTF(("Looking for file...\n"));

  hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
  if(hRes == S_OK) {
    HGLOBAL hDrop = medium.hGlobal;
    DWORD i;

    DPRINTF(("Success\n"));
    numDropFiles = DragQueryFile(hDrop, -1, NULL, 0);
    dropFiles = calloc(numDropFiles, sizeof(char*));
    for(i=0; i<numDropFiles; i++) {
      WCHAR *tmpPath;
      int len;
      len = DragQueryFileW(hDrop, i, NULL, 0);
      tmpPath = calloc(len+1, sizeof(WCHAR));
      DragQueryFileW(hDrop, i, tmpPath, len+1);
      len = WideCharToMultiByte(CP_UTF8, 0, tmpPath, -1, NULL, 0,NULL,NULL);
      dropFiles[i] = malloc(len);
      WideCharToMultiByte(CP_UTF8,0,tmpPath,-1,dropFiles[i],len,NULL,NULL);
      free(tmpPath);
      DPRINTF(("File: %s\n", dropFiles[i]));
    }
    DragFinish(hDrop);
    signalDrop(pt);
    if(medium.pUnkForRelease == NULL) {
      GlobalFree(hDrop);
    } else {
      medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease);
    }
    return S_OK;
  }

  if(FAILED(hRes)) {
    DPRINTF(("GetData failed (errCode = %x)\n", hRes));
  }

  fmtetc.cfFormat = CF_DIB;
  fmtetc.ptd = NULL;
  fmtetc.lindex = -1;
  fmtetc.dwAspect = DVASPECT_CONTENT;
  fmtetc.tymed = TYMED_HGLOBAL;
  DPRINTF(("Looking for HDIB...\n"));

  hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
  if(hRes == S_OK) {
    TCHAR tmpName[MAX_PATH+1];
    HANDLE hDib = medium.hGlobal;

    DPRINTF(("Success\n"));

    GetTempPath(MAX_PATH,tmpName);
    strcat(tmpName,"$$squeak$$.bmp");
    if(WriteDIB(tmpName, hDib)) {
      numDropFiles = 1;
      dropFiles = calloc(1, sizeof(void*));
      dropFiles[0] = _strdup(tmpName);
    }
    if(medium.pUnkForRelease == NULL) {
      GlobalFree(hDib);
    } else {
      medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease);
    }
    signalDrop(pt);
    return S_OK;
  }

  if(FAILED(hRes)) {
    DPRINTF(("GetData failed (errCode = %x)\n", hRes));
  }

  fmtetc.cfFormat = CF_BITMAP;
  fmtetc.ptd = NULL;
  fmtetc.lindex = -1;
  fmtetc.dwAspect = DVASPECT_CONTENT;
  fmtetc.tymed = TYMED_HGLOBAL;
  DPRINTF(("Looking for bitmap...\n"));

  hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
  if(hRes == S_OK) {
    TCHAR tmpName[MAX_PATH+1];
    HANDLE hDib;
    HBITMAP hBM = medium.hBitmap;

    DPRINTF(("Success\n"));

    GetTempPath(MAX_PATH,tmpName);
    strcat(tmpName,"$$squeak$$.bmp");
    hDib = DibFromBitmap(hBM, BI_RGB, 0, NULL);
    if(hDib) {
      if(WriteDIB(tmpName, hDib)) {
	numDropFiles = 1;
	dropFiles = calloc(1, sizeof(void*));
	dropFiles[0] = _strdup(tmpName);
      }
      DeleteObject(hDib);
    }
    if(medium.pUnkForRelease == NULL) {
      DeleteObject(hBM);
    } else {
      medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease);
    }
    signalDrop(pt);
    return S_OK;
  }
  if(FAILED(hRes)) {
    DPRINTF(("GetData failed (errCode = %x)\n", hRes));
  }

  fmtetc.cfFormat = CF_ENHMETAFILE;
  fmtetc.ptd = NULL;
  fmtetc.lindex = -1;
  fmtetc.dwAspect = DVASPECT_CONTENT;
  fmtetc.tymed = TYMED_ENHMF;
  DPRINTF(("Looking for ENHMF...\n"));

  hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
  if(hRes == S_OK) {
    TCHAR tmpName[MAX_PATH+1];
    HANDLE hMF = medium.hGlobal;
    HANDLE hDib;
    BITMAPINFO bmi;
    ENHMETAHEADER header;

    DPRINTF(("Success\n"));

    if(GetEnhMetaFileHeader(hMF, sizeof(header), &header) == 0) {
      DPRINTF(("GetEnhMetaFileHeader failed\n"));
    }
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 24;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biWidth = header.rclBounds.right - header.rclBounds.left;
    bmi.bmiHeader.biHeight = header.rclBounds.bottom - header.rclBounds.top;
    DPRINTF(("w=%d\nh=%d\n", bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight));
    {
      HDC hDC, mDC;
      HANDLE old, hBM;
      RECT rect;

      hDC = GetDC(stWindow);
      if(!hDC) DPRINTF(("GetDC() failed\n"));
      //      hDib = CreateDIBitmap(hDC, &bmi, 0, NULL, &bmi, DIB_RGB_COLORS);
      hBM = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
      if(!hBM) DPRINTF(("CreateDIBSection() failed\n"));
      mDC = CreateCompatibleDC(hDC);
      if(!mDC) DPRINTF(("CreateCompatibleDC() failed\n"));
      old = SelectObject(mDC, hBM);
      rect.left = rect.top = 0;
      rect.right = bmi.bmiHeader.biWidth;
      rect.bottom = bmi.bmiHeader.biHeight;
      if(!PlayEnhMetaFile(mDC, hMF, &rect))
	DPRINTF(("PlayEnhMetaFile() failed\n"));
      SelectObject(mDC, old);
      DeleteDC(mDC);
      ReleaseDC(stWindow, hDC);
      hDib = DibFromBitmap(hBM, BI_RGB, 0, NULL);
      DeleteObject(hBM);
    }

    GetTempPath(MAX_PATH,tmpName);
    strcat(tmpName,"$$squeak$$.bmp");
    if(WriteDIB(tmpName, hDib)) {
      numDropFiles = 1;
      dropFiles = calloc(1, sizeof(void*));
      dropFiles[0] = _strdup(tmpName);
    }
    GlobalFree(hDib);
    if(medium.pUnkForRelease == NULL) {
      DeleteObject(hMF);
    } else {
      medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease);
    }
    signalDrop(pt);
    return S_OK;
  }

  if(FAILED(hRes)) {
    DPRINTF(("GetData failed (errCode = %x)\n", hRes));
  }


  return S_OK;
}
Exemplo n.º 7
0
BOOL WriteWindowToDIB( LPTSTR szFile, CWnd* wnd)
{
	CDC *pDC = wnd->GetDC();

	CBitmap 	bitmap;
	CDC 		memDC;
	CRect		rect;

	int W = 640;
	int H = 480;

	memDC.CreateCompatibleDC(pDC);

	wnd->GetWindowRect(rect);

//	W = rect.Width() - 10;
//	H = rect.Height() - 10;

	bitmap.CreateCompatibleBitmap(pDC, W,H );

	CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);

	int x = rect.Width()  - W; x /= 2;
	int y = rect.Height() - H; y /= 2;

	memDC.BitBlt(0, 0, W,H, pDC, x, y, SRCCOPY);

	// Create logical palette if device support a palette
	CPalette pal;
	if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE )
	{
		UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
		LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
		pLP->palVersion = 0x300;

		pLP->palNumEntries =
			GetSystemPaletteEntries( *pDC, 0, 255, pLP->palPalEntry );

		// Create the palette
		pal.CreatePalette( pLP );

		delete[] pLP;
	}

	memDC.SelectObject(pOldBitmap);

	// Convert the bitmap to a DIB
	HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal );

	if( hDIB == NULL )
		return FALSE;

	// Write it to file
	WriteDIB( szFile, hDIB );

	// Free the memory allocated by DDBToDIB for the DIB
	GlobalFree( hDIB );

	wnd->ReleaseDC(pDC);
	return TRUE;
}
Exemplo n.º 8
0
Bool32 CRIControl::Rotate(char*  cDIBIn, char*  cDIBOut, int32_t High, int32_t Low, uint32_t UseMargins)
{
	Bool32 Ret = TRUE;
	Bool32 NoDest = FALSE;

	// открываем исходный
	if ( !OpenSourceDIB(cDIBIn) )
	{
		return FALSE;
	}

	if ( mpDestinationDIB )
	{
		SetReturnCode_rimage(IDS_RIMAGE_INTERNAL_MODULE_ERROR);
		return FALSE;
	}

	mpDestinationDIB = new CTDIB;

	//открываем вертелку
	if ( !mpRotator )
	{
		mpRotator = new CRRotator(&mcProgress);
	}

	// забываем старое имя
	mcLastDIBName[0] = 0x0;

	if ( !mpRotator->Rotate(mpSourceDIB, mpDestinationDIB, High, Low) )
	{
		uint16_t wRet = GetReturnCode_rimage();
// !!! Art Изменил - теперь она заносит не хендлы, а указатели, а то память утекала
//почему-то...
		//		Handle hDIBtoSet;
		pvoid  pDIBtoSet;

		if ( (wRet == IDS_RIMAGE_ZERO_NUMERATOR_OR_DENUMERATOR ||
			  wRet == IDS_RIMAGE_ANGLE_LEAST_MINIMUM )         &&
			  mpSourceDIB->GetDIBPtr( &pDIBtoSet )
			  /*mpSourceDIB->GetDIBHandle(&hDIBtoSet)*/ )
		{
//			SetDIB(cDIBOut, hDIBtoSet);
			WriteDIB(cDIBOut, pDIBtoSet);
			SetReturnCode_rimage(IDS_RIMAGE_ERR_NO);
			NoDest = Ret = TRUE;
		}
		else
		{
			SetReturnCode_rimage(IDS_RIMAGE_CANNOT_ROTATE_IMAGE);
			Ret = FALSE;
		}
	}
	else
	{
		WriteDIBtoBMP("Allex.DIBBeforeDeskew.bmp",mpSourceDIB);
		WriteDIBtoBMP("Allex.DIBAfterDeskew.bmp",mpDestinationDIB);
	}

	//отписваем новый в контейнер и освобождаем
	if ( !CloseDestinationDIB(cDIBOut) )
	{
		if ( NoDest == FALSE )
		{
			SetReturnCode_rimage(IDS_RIMAGE_CANNT_SAVE_OUTCOMING_DIB);
			Ret = FALSE;
		}
	}

	strcpy(mcLastDIBName, cDIBOut);

	//закрываем исходный
	if ( !CloseSourceDIB() )
	{
		SetReturnCode_rimage(IDS_RIMAGE_UNDER_CONSTRUCTION);
		Ret = FALSE;
	}
	return Ret;
}