Beispiel #1
0
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
void CAGSymImage::LoadDIB(const BITMAPINFOHEADER* pHdr, const BYTE* pBits)
{
	Free();

	if (pHdr->biCompression == BI_RGB && (pHdr->biBitCount == 1 || pHdr->biBitCount == 4 || pHdr->biBitCount == 8 || pHdr->biBitCount == 24))
	{
		BITMAPINFOHEADER bi;
		bi = *pHdr;
		bi.biCompression = BI_RGB;

		if (!bi.biSizeImage)
			bi.biSizeImage = DibSizeImage(&bi);
		if (!bi.biClrUsed)
			bi.biClrUsed = DibNumColors(&bi);

		if (m_pDIB = (BITMAPINFOHEADER*)malloc(DibSize(&bi)))
		{
			*m_pDIB = bi;

			if (bi.biClrUsed)
				memcpy((void*)DibColors(m_pDIB), (void*)DibColors(pHdr), DibPaletteSize(pHdr));

			BYTE* pNewBits = (BYTE*)DibPtr(m_pDIB);
			const BYTE* pSrcBits;
			if (pBits)
				pSrcBits = pBits;
			else
				pSrcBits = (BYTE*)(DibColors(pHdr) + bi.biClrUsed);

			memcpy(pNewBits, pSrcBits, bi.biSizeImage);
		}
	}
}
Beispiel #2
0
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
void CAGSymImage::Draw(CAGDC& dc)
{
	if (!m_pDIB)
		return;

	dc.PushModelingMatrix(m_Matrix);
	dc.StretchBlt(m_DestRect, DibPtr(m_pDIB), (BITMAPINFO*)m_pDIB);
	dc.PopModelingMatrix();
}
Beispiel #3
0
////////////////////////////////////////////////////////////
// TWallTextureontrol
// -----------------
//
void
TWallTextureControl::BuildBitmapData (const char *texname, SHORT /*remapPlayer*/)
{
   Bitmaps b;
   PDIB pdib;
   BYTE *bits;
   int size;
   
   if (DibOpenFile(texname, &b) == False)
   {
      Notify("Couldn't load texture %s", texname);
      return;
   }
   
   pdib = BitmapsGetPdib(b, 0, 0);
   if (pdib == NULL)
   {
      Notify("Missing bitmap 0 in texture %s", texname);
      return;
   }
	
   BitmapXSize = DibWidth(pdib);
   BitmapYSize = DibHeight(pdib);
   bits = DibPtr(pdib);
   
   size = BitmapXSize * BitmapYSize;
   pBitmapData = (BYTE *) GetMemory(size);
   memcpy(pBitmapData, bits, size);
   
   BitmapsFree(&b);

   // Mark used colors
   BYTE *ptrData = pBitmapData;
   for (int i = 0 ; i < size ; i++ )
   {
      pUsedColors[*ptrData] = TRUE;
      ptrData++;
   }

   return;
}
Beispiel #4
0
/*
 * DibReadBits:  Read bits of an image into the given PDIB.  The file pointer
 *   for f must be positioned at the start of the image information.
 *   version is version of BGF file.
 *   Return True on success.
 */
Bool DibReadBits(file_node *f, PDIB pdib, int version)
{
   BYTE *bits, type;
   int length, temp, compressed_length, retval;
   uLongf len;

   bits = DibPtr(pdib);
   length = DibWidth(pdib) * DibHeight(pdib);

   if (version < 10)
      return False;
   
   // See if image is compressed
   if (MappedFileRead(f, &type, 1) != 1) return False;

   switch (type)
   {
   case 0:
      if (MappedFileRead(f, &temp, 4) != 4) return False;  // Skip unused bytes
      if (MappedFileRead(f, bits, length) != length) return False;
      break;
   case 1:
      if (MappedFileRead(f, &compressed_length, 4) != 4) return False;

      len = length;
      retval = uncompress((Bytef *) bits, &len, (const Bytef *) f->ptr, compressed_length);
      if (retval != Z_OK)
      {
         dprintf("DibReadBits error during decompression\n");
         return False;
      }

      f->ptr += compressed_length;
      break;
   default:
      dprintf("DibReadBits got bad type byte %d\n", (int) type);
      return False;
   }
   return True;
}
Beispiel #5
0
BOOL CImageBMP::ReadFile(const CString& imageFileName)
{
  if (imageFileName != "")
	 filename = imageFileName;

  if (lpbi = DibOpenFile((char *)(const char *)filename))  {
		Width =  DibWidth(lpbi);
		Height = DibHeight(lpbi);
		Depth = DibBitCount(lpbi);
		RawImage = (ImagePointerType)DibPtr(lpbi);
		EffWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
		HPALETTE palette;
		if (palette = MakePalette((const BITMAPINFO FAR*)lpbi, 0))
		{
		  imagePalette = new CImagePalette;
		  imagePalette->Attach(palette);
		  DibSetUsage(lpbi, (HPALETTE) (*imagePalette), CIMAGE_COLORS);
		  ColorType = (COLORTYPE_PALETTE | COLORTYPE_COLOR);
		} 

		return TRUE;
  }
  return FALSE;
}
Beispiel #6
0
BOOL CDib::Open(HWND hWnd, const char *pFileName, BOOL bOpenFromFile)
{
	/*
	UINT fuLoad;

	if(bOpenFromFile==TRUE)
		fuLoad = LR_CREATEDIBSECTION|LR_LOADFROMFILE|LR_DEFAULTSIZE;
	else
		fuLoad = (bOpenFromFile?LR_CREATEDIBSECTION:0)|LR_LOADFROMFILE|LR_DEFAULTSIZE;
	*/
	m_hBitmap=(HBITMAP)::LoadImage(
		bOpenFromFile? NULL : (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
		pFileName,
		IMAGE_BITMAP,
		0,0,
		//fuLoad);
		LR_CREATEDIBSECTION|(bOpenFromFile?LR_LOADFROMFILE:0)|LR_DEFAULTSIZE);
	if(m_hBitmap==NULL){
//		SetErrors(CMERR_CANT_OPEN_FILE,pFileName);
		return FALSE;
	}

	BITMAP bm;
	BITMAPINFOHEADER bi;
	LPBITMAPINFOHEADER lpbi;	// 24bit라서 팔레트 정보가 없을 것이므로 필요없으나... 확장을 위해

	GetObject(m_hBitmap,sizeof(BITMAP),&bm);

	if(bm.bmHeight>=0)m_bTopDown=FALSE;
	else m_bTopDown=TRUE;

    bi.biSize				= sizeof(BITMAPINFOHEADER);
    bi.biWidth				= bm.bmWidth;
    bi.biHeight				= bm.bmHeight;
    bi.biPlanes				= 1;
    //bi.biBitCount           = bm.bmPlanes * bm.bmBitsPixel;
	bi.biBitCount			= 24;			// 8bit 도 24bit로 읽어낸다. 따라서 Pal 정보가 없다.
    bi.biCompression		= BI_RGB;
    bi.biSizeImage			= 0;
    bi.biXPelsPerMeter		= 0;
    bi.biYPelsPerMeter		= 0;
    bi.biClrUsed			= 0;
    bi.biClrImportant		= 0;

// 팔레트 개수
#define DibNumColors(lpbi)	((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
								? (WORD)(1 << (int)(lpbi)->biBitCount) \
								: (WORD)(lpbi)->biClrUsed)

	// BITMAPINFO( BITMAPINFOHEADER+PAL ) 의 크기
	DWORD nLen  = bi.biSize + DibNumColors(&bi) * sizeof(RGBQUAD);

	lpbi=(LPBITMAPINFOHEADER)new char[nLen];

	*lpbi=bi;

	HDC hDC=GetDC(hWnd);
	GetDIBits(hDC,m_hBitmap,0,bi.biHeight,NULL,(LPBITMAPINFO)lpbi,DIB_RGB_COLORS);
	ReleaseDC(hWnd,hDC);

	bi=*lpbi;

	// 드라이버가 biSizeImage를 채우지 않는 경우
	if(bi.biSizeImage==0){
		bi.biSizeImage=(DWORD)WIDTHBYTES(bm.bmWidth*bi.biBitCount)*bm.bmHeight;
		if(bi.biCompression!=BI_RGB)
			bi.biSizeImage=(bi.biSizeImage*3)/2;
	}

	delete[] lpbi;

	nLen=bi.biSize+DibNumColors(&bi)*sizeof(RGBQUAD)+bi.biSizeImage;

	//lpbi=(LPBITMAPINFOHEADER)new char[nLen];
	m_pBitmapData=new BYTE[nLen];

	if(m_pBitmapData==NULL){
		//_RPT0(_CRT_WARN,"Memory Allocation Error");
//		SetError(CMERR_OUT_OF_MEMORY);
		return FALSE;
	}

	*(LPBITMAPINFOHEADER)m_pBitmapData=bi;

	hDC=GetDC(hWnd);
	GetDIBits(hDC,m_hBitmap,0,bi.biHeight,DibPtr((LPBITMAPINFOHEADER)m_pBitmapData),(LPBITMAPINFO)m_pBitmapData,DIB_RGB_COLORS);
	ReleaseDC(hWnd,hDC);
	
	return TRUE;
}
Beispiel #7
0
LPBYTE CDib::GetData(void)
{
	_ASSERT(m_pBitmapData!=NULL);
	return (LPBYTE)DibPtr((LPBITMAPINFOHEADER)m_pBitmapData);
}
Beispiel #8
0
HGLOBAL CPng::PNGToDIB(png_structp png_ptr, png_infop info_ptr)
{
	//Read the image
	png_read_info(png_ptr, info_ptr);

	int nBitDepth = 0;
	int nColorType = 0;
	png_uint_32 width = 0;
	png_uint_32 height = 0;
	png_get_IHDR(png_ptr, info_ptr, &width, &height, &nBitDepth, &nColorType, NULL, NULL, NULL);

	IMAGE img;
	img.width = (LONG)width;
	img.height = (LONG)height;

	//Determine the type of format
	if (nColorType==PNG_COLOR_TYPE_RGB || nColorType==PNG_COLOR_TYPE_RGB_ALPHA)
	{
		img.pixdepth = 24;		// nBitDepth 8, 16
		img.palnum   = 0;
	}
	else
	{
		switch(nBitDepth) // bit depths 1, 2, 4, 8, 16
		{	
			case 2:  
				img.pixdepth = 4;		
				break;
			case 16: 
				img.pixdepth = 8;		
				break;
			default: 
				img.pixdepth = nBitDepth;
		}

		img.palnum = 1 << img.pixdepth;
	}

	//Allocate the image struct that will be used to transport file info
	if (!AllocImageStruct(&img))
	{
		longjmp(png_ptr->jmpbuf, 1);
	}

	//Not sure if we can take advantage of this info in a BMP, thus remove it.
	if (nColorType & PNG_COLOR_MASK_ALPHA)
		png_set_strip_alpha(png_ptr);

	//Set user transform function to deal with a Bitdepth of 2
	if (nBitDepth == 2)
	{
		png_set_user_transform_info(png_ptr, NULL, 4, 1);
		png_set_read_user_transform_fn(png_ptr, ConvertTo4BitsPerPix);
	}

	//Tell libpng to strip 16 bit/color files down to 8 bits/color
	if (nBitDepth == 16) 
		png_set_strip_16(png_ptr);

	if (nColorType==PNG_COLOR_TYPE_RGB || nColorType==PNG_COLOR_TYPE_RGB_ALPHA)
	{
		png_set_bgr(png_ptr);
	}

	png_read_update_info(png_ptr, info_ptr);

	//If palette, get it and fill our img struct
	if (img.palnum > 0)
	{
		if (nColorType == PNG_COLOR_TYPE_PALETTE)
		{
			png_colorp palette;
			int num_palette;
			png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
			if (num_palette > (int)img.palnum) 
				num_palette = img.palnum;

			memset(img.palette, 0, img.palnum * sizeof(png_color));
			memcpy(img.palette, palette, num_palette * sizeof(png_color));
		}
		else
		{
			int depth = (nBitDepth == 16)? 8 : nBitDepth ;
			png_build_grayscale_palette(depth, img.palette);
		}
	}

	png_read_image(png_ptr, img.rowptr);

	png_infop end_info = NULL;
	png_read_end(png_ptr, end_info);

	// Alloc the buffer to be big enough to hold all the bits
	DWORD dwLen = (DWORD)sizeof(BITMAPINFOHEADER) + (img.palnum * sizeof(RGBQUAD)) + img.imgbytes;

	// Allocate enough memory to hold the entire DIB
	HGLOBAL hMemory = ::GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwLen);
	if (!hMemory)
		return NULL;

	//Begin filling out DIB info
	BITMAPINFOHEADER* pDib = (BITMAPINFOHEADER*)::GlobalLock(hMemory);
	if (!pDib)
	{
		::GlobalFree(hMemory);
		return NULL;
	}

	::ZeroMemory(pDib, dwLen);
	pDib->biSize			= sizeof(BITMAPINFOHEADER);
	pDib->biWidth			= (DWORD)img.width; 
	pDib->biHeight			= (DWORD)img.height; 
	pDib->biPlanes			= 1;
	pDib->biCompression		= BI_RGB;
	pDib->biXPelsPerMeter	= 3937; // 100 pixels/inch
	pDib->biYPelsPerMeter	= 3937;
	pDib->biSizeImage		= img.imgbytes;
	pDib->biBitCount		= img.pixdepth; 
	pDib->biClrUsed			= img.palnum;

	if (pDib->biBitCount >= 16)
		pDib->biBitCount = 24;	

	if (pDib->biClrUsed)
	{
		RGBQUAD* pRgb = DibColors(pDib);
		BYTE rgbq[RGBQUAD_SIZE];
		PALETTE* pal;
		UINT nIndex;
		memset(rgbq, 0, sizeof(rgbq));
		for (pal = img.palette, nIndex = img.palnum ; nIndex > 0 ; nIndex--, pal++)
		{
			rgbq[RGBQ_RED]			= pal->red;
			rgbq[RGBQ_GREEN]		= pal->green;
			rgbq[RGBQ_BLUE]			= pal->blue;
			rgbq[RGBQ_RESERVED]		= 0;
			memcpy((LPVOID)pRgb, rgbq, sizeof(RGBQUAD));
			pRgb++;
		}
	}

	memcpy(DibPtr(pDib), img.bmpbits, DibSizeImage(pDib));

	FreeImageStruct(&img);

	::GlobalUnlock(hMemory);
	return hMemory;
}
Beispiel #9
0
void AboutTimer(HWND hwnd, UINT id)
{
   HWND hwndBitmap;
   HDC hdc;
   int i, j, k, x, y;
   RECT r;
   PDIB pdib;
   BYTE *bits, index;
   object_node *obj;

   // Copy bits to offscreen area
   for (i=0; i < scroll_height; i++)
   {
      int yBitmap = (scroll_y + i) % DibHeight(credits_pdib);
      BYTE *pSource = DibPtr(credits_pdib) + (yBitmap * DibWidth(credits_pdib));
      BYTE *pDest = gBits + i*DIBWIDTH(gbits_width);
      memcpy(pDest,pSource,scroll_width);
   }
   scroll_y++;
   if (scroll_y >= DibHeight(credits_pdib))
      scroll_y = 0;

   hwndBitmap = GetDlgItem(hwnd, IDC_SCROLL);
   hdc = GetDC(hwndBitmap);
   SelectPalette(hdc, hPal, FALSE);
   BitBlt(hdc, 0, 0, scroll_width, scroll_height, gDC, 0, 0, SRCCOPY);
   ReleaseDC(hwndBitmap, hdc);

   // Draw animated characters
   r.left = r.top = 0;
   r.right = gbits_width;
   r.bottom = gbits_height;
   FillRect(gDC, &r, GetSysColorBrush(COLOR_3DFACE));
   GdiFlush();

   hdc = GetDC(hwnd);
   for (i=0; i < NUM_DUDES; i++)
   {
      if (dudes[i].obj != NULL)
      {
	 obj = dudes[i].obj;
	 if (rand() % 30 == 0)
	 {
	    obj->animate->animation = ANIMATE_ONCE;
	    obj->animate->group = obj->animate->group_low = 3;
	    obj->animate->group_high = 4;
	    obj->animate->group_final = 0;
	    obj->animate->period = obj->animate->tick = 400;

	    if (config.play_sound)
	    {
	       switch (dudes[i].obj->icon_res)
	       {
	       case ABOUT_RSC1: index = 3; break;
	       case ABOUT_RSC2: index = 4; break;
	       case ABOUT_RSC3: index = 5; break;
	       default: index = rand() % num_sounds; break;
	       }
		   SoundPlayFile(sounds[index], SF_RANDOM_PITCH);
	    }
	 }
		
	 AnimateObject(dudes[i].obj, ABOUT_INTERVAL);
	
	 pdib = GetObjectPdib(dudes[i].obj->icon_res, dudes[i].angle, dudes[i].obj->animate->group);
	 if (pdib == NULL)
	    continue;
	
	 bits = DibPtr(pdib);
	 x = dudes[i].x - DibWidth(pdib) / 2;
	 y = DUDE_MAX_HEIGHT - DibHeight(pdib);
	 for (j=0; j < DibHeight(pdib); j++)
	 {
	    for (k=0; k < DibWidth(pdib); k++)
	    {
	       index = *(bits + j * DibWidth(pdib) + k);
	       if (index != TRANSPARENT_INDEX)
		  *(gBits + (j + y) * DIBWIDTH(gbits_width) + x + k) = index;
	    }
	 }
      }
   }
   SelectPalette(hdc, hPal, FALSE);
   BitBlt(hdc, dude_x, dude_y, DUDE_AREA_WIDTH, DUDE_MAX_HEIGHT, gDC, 0, 0, SRCCOPY);
   ReleaseDC(hwnd, hdc);
}
Beispiel #10
0
/*
 * DibOpenFile: Load the bitmaps in the file given by filename into the
 *   given bitmap structure.  Return TRUE on success.
 */
Bool DibOpenFile(const char *szFile, Bitmaps *b)
{
   file_node f;
   DWORD   dwLen, dwBits;
   DWORD   width, height, xoffset, yoffset;
	BYTE    num_hotspots, shrink;
   int     i, j, size, offset, num_indices;

   if (!MappedFileOpenRead(szFile, &f))
      return False;

   if (!DibReadHeader(&f, b, &shrink))
      return MappedFileClose(&f);
   
   // Allocate memory for bitmap pointers and indices
   size  = b->num_bitmaps * sizeof(PDIB) + b->num_groups * b->max_indices * sizeof(int);
   b->pdibs = (PDIB *) SafeMalloc(size);
   b->indices = (int *) ((BYTE *) b->pdibs + b->num_bitmaps * sizeof(PDIB));
   memset(b->pdibs, 0, size);
   
   // Read in bitmaps
   for (i=0; i < b->num_bitmaps; i++)
   {
      // Switch width and height since walls are rotated 90 degrees
      if (MappedFileRead(&f, &height, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &width, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &xoffset, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &yoffset, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &num_hotspots, 1) != 1)
	 return MappedFileClose(&f);
      
      /* How much memory do we need to hold the PDIB? */
      dwBits = width * height;
      dwLen  = dwBits + sizeof(DIBHEADER) + num_hotspots * (sizeof(POINT) + sizeof(BYTE));
      
      // Arrangement of PDIB in memory:
      // Header
      // bytes of bitmap
      // array of hotspot numbers
      // array of hotspot positions
      
      b->pdibs[i] = (PDIB) SafeMalloc(dwLen);
      
      b->pdibs[i]->width        = width;
      b->pdibs[i]->height       = height;
      b->pdibs[i]->xoffset      = xoffset;
      b->pdibs[i]->yoffset      = yoffset;
      b->pdibs[i]->num_hotspots = num_hotspots;
      b->pdibs[i]->numbers      = (char *) (DibPtr(b->pdibs[i]) + dwBits);
      b->pdibs[i]->hotspots     = (POINT *) (b->pdibs[i]->numbers + num_hotspots * sizeof(BYTE));
      b->pdibs[i]->shrink       = shrink;
      
      // read in the hotspots
      for (j=0; j < num_hotspots; j++)
      {
	 if ((MappedFileRead(&f, &b->pdibs[i]->numbers[j], 1) != 1) ||
	     (MappedFileRead(&f, &b->pdibs[i]->hotspots[j].x, 4) != 4) ||
	     (MappedFileRead(&f, &b->pdibs[i]->hotspots[j].y, 4) != 4))
	 {
	    BitmapsFree(b);
	    return MappedFileClose(&f);
	 }
      }
      
      /* read in the bits */
      if (!DibReadBits(&f, b->pdibs[i], version))
      {
	 BitmapsFree(b);
	 return MappedFileClose(&f);
      }
      RotateBits(DibPtr(b->pdibs[i]), height, width);
   }
   
   // Read in indices
   for (i=0; i < b->num_groups; i++)
   {
      // offset stores where we are in indices array
      offset = b->max_indices * i;
      if (MappedFileRead(&f, &num_indices, 4) != 4)
      {
	 BitmapsFree(b);
	 return MappedFileClose(&f);
      }
      b->indices[offset] = num_indices;
      for (j=0; j < num_indices; j++)
      {
	 offset++;
	 if (MappedFileRead(&f, &b->indices[offset], 4) != 4)
	 {
	    BitmapsFree(b);
	    return MappedFileClose(&f);
	 }
      }
   }
   
   MappedFileClose(&f);
   return True;
}
Beispiel #11
0
/*
 * WriteBitmap:  Write bytes of given PDIB out to given file.
 *   Return FALSE on error.
 */
BOOL WriteBitmap(file_node *f, PDIB pdib, Options *options)
{
    int width, height, row, col, len, temp;
    BYTE *bits;
    BYTE *buf, *bufptr, byte;

    width = DibWidth(pdib);
    height = DibHeight(pdib);

    buf = (BYTE *) malloc(width * height);
    bufptr = buf;

    if (options->rotate)
    {
        for (col=0; col < width; col++)
        {
            bits = (BYTE *) DibPtr(pdib) + col;

            for (row = 0; row < height; row++)
            {
                *bufptr++ = *bits;
                bits += DibWidthBytes(pdib);
            }
        }
    }
    else
    {
        for (row=0; row < height; row++)
        {
            // Watch out--rows are 4-bytes aligned
            bits = (BYTE *) DibPtr(pdib) + row * DibWidthBytes(pdib);
            memcpy(bufptr, bits, width);
            bufptr += width;
        }
    }

    // Leave space for # of bytes

    if (options->compress)
    {
        len = WrapCompress((char *) buf, f->ptr + 5, width * height);
        if (len > 0)
        {
            byte = 1;
            // Save compressed length
            MappedFileWrite(f, &byte, 1);
            MappedFileWrite(f, &len, 4);
            f->ptr += len;
        }
    }
    else len = -1;

    if (len < 0)
    {
        byte = 0;
        MappedFileWrite(f, &byte, 1);
        temp = 0;
        MappedFileWrite(f, &temp, 4);

        // Buffer is incompressible; just write out bits themselves
        MappedFileWrite(f, buf, width * height);
    }

    free(buf);
    return True;
}
Beispiel #12
0
/*
 * IntroShowSplash:  Display splash screen.
 */
void IntroShowSplash(void)
{
   RECT rect;
   BYTE *gTitleBits;
   int i;
   Bitmaps b;
   PDIB pdib;

   if (cinfo->config->quickstart)
   {
      OfflineConnect();
      return;
   }
   if (showing_splash)
     return;
   showing_splash = True;

   IntroFreeLogo();
   hwndDialButton = CreateWindow("button", NULL, 
		WS_CHILD | WS_VISIBLE,
		0, 0, 0, 0, cinfo->hMain, (HMENU) IDC_DIALBUTTON,
		hInst, NULL);
   SetWindowText(hwndDialButton, GetString(hInst, IDS_INTRO));

   /* Subclass button */
   lpfnDefButtonProc = SubclassWindow(hwndDialButton, MainButtonProc);

   /* Get bits of bitmap from bgf file */   
   if (DibOpenFile(splash_filename, &b))
   {
      pdib = BitmapsGetPdibByIndex(b, 0);

      /* Get bitmap's size */
      bm_width  = DibWidth(pdib);
      bm_height = DibHeight(pdib);

      /* Create bitmap */
      hTitleDC = CreateMemBitmap(bm_width, bm_height, &hOldTitleBitmap, &gTitleBits);
      if (hTitleDC == NULL)
      {
	 debug(("IntroShowSplash couldn't create bitmap!\n"));
	 BitmapsFree(&b);
	 return;
      }
      
      /* Copy bits into bitmap */
      for (i=0; i < bm_height; i++)
	 memcpy(gTitleBits + i * DIBWIDTH(bm_width), DibPtr(pdib) + i * bm_width, bm_width);

      BitmapsFree(&b);

   }
   else 
   {
      hTitleDC = NULL;
      bm_width = BUTTON_XSIZE;
   }

   button_width = bm_width;
   button_height = BUTTON_YSIZE;

   /* Simulate resize to get positions right */
   GetClientRect(cinfo->hMain, &rect);
   EventResize(rect.right, rect.bottom, NULL);

   SetFocus(hwndDialButton);

   timer_id = SetTimer(NULL, 0, MUSIC_DELAY, PlayMusicProc);
}
void  CPictureListView::DrawListViewThumbnails()
{
	// Set the length of the space between thumbnails
	// You can also calculate and set it based on the length of your list control

	// Hold the window update to avoid flicking
	SetRedraw(FALSE);

	// Reset the image list
	for (int i=0; i<m_ImageList.GetImageCount(); i++)
		m_ImageList.Remove(i);	

	// Remove all items from list view
	if (GetItemCount())
		DeleteAllItems();

	// Draw the thumbnails
	i = 0;
	for (int nIndex = 0; nIndex < MAX_NUM_PICTURES; nIndex++)
	{
		CAGSymImage* pImage = m_pParent->GetEnvelopeWizard()->m_pGraphics[nIndex];
		if (!pImage)
			continue;

		BITMAPINFOHEADER* pDib = pImage->GetDib();
		if (!pDib)
			continue;

		// Borrow our dib header to create our thumbnail bitmap
		int nWidth = pDib->biWidth;
		int nHeight = pDib->biHeight;
		pDib->biWidth = m_nThumbnailSize;
		pDib->biHeight = m_nThumbnailSize;

		// Create thumbnail bitmap section
		HBITMAP hBitmap = ::CreateDIBSection(NULL, (BITMAPINFO*)pDib, DIB_RGB_COLORS, NULL, NULL, 0); 

		// Restore the dib header
		pDib->biWidth = nWidth;
		pDib->biHeight = nHeight;

		// Select the thumbnail bitmap into screen dc
		HDC	hMemDC = ::CreateCompatibleDC(NULL);	
		HGDIOBJ	hOldObj = ::SelectObject(hMemDC, hBitmap);

		// Set stretch mode
		::SetStretchBltMode(hMemDC, COLORONCOLOR);

		int dx = m_nThumbnailSize;
		int dy = m_nThumbnailSize;
		ScaleToFit(&dx, &dy, nWidth, nHeight, true/*bUseSmallerFactor*/);

		// Populate the thumbnail bitmap bits
		RECT rect = {0, 0, m_nThumbnailSize, m_nThumbnailSize};
		::FillRect(hMemDC, &rect, CAGBrush(RGB(255,255,255)));
		::StretchDIBits(hMemDC,
						(m_nThumbnailSize - dx)/2, (m_nThumbnailSize - dy)/2,
						dx, dy, 0, 0, nWidth, nHeight, DibPtr(pDib), 
						(BITMAPINFO*)pDib, DIB_RGB_COLORS, SRCCOPY);

		// Restore DC object
		::SelectObject(hMemDC, hOldObj);
	  
		// Clean up
		::DeleteObject(hMemDC);
		
		// Add the bitmap to our image list
		m_ImageList.Add(hBitmap);

		// Set the image file name as item text
		InsertItem(i, "", i);

		// Get the current item position	 
		POINT pt;
		GetItemPosition(i, &pt);	 
	  
		// Shift the thumbnail to desired position
		pt.x = 0; 
		pt.y = i * m_nThumbnailSize;
		SetItemPosition(i, pt);
		i++;
	}

	// Show the new thumbnails
//j	Arrange(LVA_ALIGNLEFT);
	SetRedraw(TRUE); 
}
Beispiel #14
0
HX_RESULT
CHXDIBits::GetDIBits(HDC		hDC,
		     HBITMAP		hBM,
		     UCHAR*&		pBits,
		     BITMAPINFOHEADER*&	pHeader)
{
    HX_RESULT		hr = HXR_OK;
    WORD		wBits = 0;
    DWORD   		dwLen = 0;
    BITMAP		bm;
    BITMAPINFOHEADER	bi;
    LPBITMAPINFOHEADER	lpbi = NULL;

    pBits = NULL;
    pHeader = NULL;

    if (!hDC || !hBM)
    {
	hr = HXR_FAILED;
	goto cleanup;
    }

    GetObject(hBM, sizeof(bm), &bm);

    wBits = (WORD)(bm.bmPlanes * bm.bmBitsPixel);

    bi.biSize		= sizeof(BITMAPINFOHEADER);
    bi.biWidth		= bm.bmWidth;
    bi.biHeight		= bm.bmHeight;
    bi.biPlanes		= 1;
    bi.biBitCount	= wBits;
    bi.biCompression	= BI_RGB;
    bi.biSizeImage	= WIDTHBYTES(bm.bmWidth * wBits) * bm.bmHeight;
    bi.biXPelsPerMeter	= 0;
    bi.biYPelsPerMeter  = 0;
    bi.biClrUsed	= 0;
    bi.biClrImportant	= 0;

    dwLen = bi.biSize + DibNumColors(&bi) * sizeof(RGBQUAD) + bi.biSizeImage;

    if (!m_hDIB)
    {
	m_hDIB = GlobalAlloc(GMEM_MOVEABLE, dwLen);
    }
    else if (m_hDIB && (GlobalSize(m_hDIB) != dwLen))
    {
	GlobalFree(m_hDIB);
	m_hDIB = GlobalAlloc(GMEM_MOVEABLE, dwLen);
    }

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(m_hDIB);

    if (!lpbi)
    {
	// This is bad, it's not clear how callers of this class can
	// really handle a failure case. So, we need to make sure that
	// all our callers do handle this correctly.
	HX_ASSERT(lpbi);
	hr = HXR_FAILED;
	goto cleanup;
    }

    *lpbi = bi;

    ::GetDIBits(hDC,
	      hBM,
	      0,
	      (WORD)bi.biHeight,
	      DibPtr(lpbi),
	      (LPBITMAPINFO)lpbi,
	      DIB_RGB_COLORS);

    bi = *lpbi;

    lpbi->biClrUsed = DibNumColors(lpbi);

    pBits = (UCHAR*)DibPtr(lpbi);
    pHeader = lpbi;

    GlobalUnlock(m_hDIB);

cleanup:

    return hr;
}