Beispiel #1
0
/*
 * initializeImage - initialize the bitmaps according to the image type
 */
static void initializeImage( img_node *node, const char *filename )
{
    node->imgtype = imgType;
    node->width = imgWidth;
    node->height = imgHeight;
    node->bitcount = bitCount;
    node->hotspot.x = 0;
    node->hotspot.y = 0;
    node->num_of_images = 1;
    node->nexticon = NULL;
    node->issaved = TRUE;
    node->next = NULL;
    if( filename != NULL ) {
        strcpy( node->fname, filename );
    } else {
        sprintf( node->fname, "%s.%d", IEImageUntitled, imageCount );
    }

    if( imgType == BITMAP_IMG ) {
        MakeBitmap( node, TRUE );
    } else {
        MakeIcon( node, TRUE );           // also makes cursors
    }

} /* initializeImage */
Beispiel #2
0
void CTextureTool::DrawTexture (INT16 texture1, INT16 texture2, int x0, int y0) 
{
	UINT8 bitmap_array [64*64];
	int x_offset;
	int y_offset;
	x_offset = 0;
	y_offset = 0;
	CDC	*pDC = m_textureWnd.GetDC ();
	CDTexture tx (bmBuf);

memset (bitmap_array,0,sizeof (bitmap_array));
if (DefineTexture(texture1,texture2,&tx,x0,y0))
	return;
BITMAPINFO *bmi;
bmi = MakeBitmap ();
CPalette	*oldPalette = pDC->SelectPalette (thePalette, FALSE);
pDC->RealizePalette ();
//SetDIBitsToDevice (pDC->m_hDC, x_offset, y_offset, 64, 64, 0, 0, 0, 64, bitmap_array, bmi, DIB_RGB_COLORS);
CRect	rc;
m_textureWnd.GetClientRect (&rc);
StretchDIBits (pDC->m_hDC, x_offset, y_offset, rc.Width (), rc.Height (), 0, 0, tx.width, tx.height,
		        	(void *) bitmap_array, bmi, DIB_RGB_COLORS, SRCCOPY);
pDC->SelectPalette(oldPalette, FALSE);
m_textureWnd.ReleaseDC (pDC);
}
Beispiel #3
0
//---------------------------------------------------------------------
void __fastcall TFreqDispDlg::Execute(CIIR *ip, double max, double SampleFreq)
{
	m_type = 2;
	m_piir = ip;
	m_Max = max;
    m_SampleFreq = SampleFreq;
    MakeBitmap();
	ShowModal();
}
Beispiel #4
0
//! 画面有効範囲を変更
//
bool WinDrawD2D::Resize( uint _width, uint _height )
{
	m_width  = _width;
	m_height = _height;

	status |= Draw::shouldrefresh;

	HRESULT hr = S_OK;

	::SetWindowPos( m_hCWnd, HWND_BOTTOM, 0, 0, 640, 400, SWP_SHOWWINDOW);

	if ( !m_RenderTarget ) {

		D2D1_SIZE_U size = D2D1::SizeU(
			_width,
			_height
			);

		D2D1_RENDER_TARGET_PROPERTIES RTProps = D2D1::RenderTargetProperties();
		m_D2DFact->GetDesktopDpi( &RTProps.dpiX, &RTProps.dpiY );
		RTProps.usage =  D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;

		// Create a GDI compatible Hwnd render target.
		hr = m_D2DFact->CreateHwndRenderTarget(
			RTProps,
			D2D1::HwndRenderTargetProperties( m_hCWnd, size ),
			&m_RenderTarget
			);

		if (SUCCEEDED(hr)) {
			hr = m_RenderTarget->QueryInterface(
				__uuidof(ID2D1GdiInteropRenderTarget),
				(void**)&m_GDIRT
				);
		}

		if ( MakeBitmap() == false ) {
			return false;
		}
		memset( m_image, 0x40, _width * _height);
	} else {
		RECT rc;
		GetClientRect( m_hCWnd, &rc );
		D2D1_SIZE_U size = D2D1::SizeU(
			rc.right - rc.left,
			rc.bottom - rc.top
			);
		m_RenderTarget->Resize( size );
	}

	if ( !SUCCEEDED(hr) ) {
		return false;
	}


	return true;
}
Beispiel #5
0
//---------------------------------------------------------------------
void __fastcall TFreqDispDlg::Execute(CIIRTANK &tank, double SampleFreq)
{
	m_type = 4;
	m_a10 = tank.a0;
	m_b11 = tank.b1;
	m_b12 = tank.b2;
    m_SampleFreq = SampleFreq;
    MakeBitmap();
	ShowModal();
}
Beispiel #6
0
//---------------------------------------------------------------------
void __fastcall TFreqDispDlg::Execute(const double *H, int Tap, int max, double SampleFreq)
{
	m_type = 0;
	m_H1 = H;
	m_Tap1 = Tap ? Tap : 1;
	m_Tap2 = 0;
	m_Max = max;
    m_SampleFreq = SampleFreq;
    MakeBitmap();
	ShowModal();
}
Beispiel #7
0
//---------------------------------------------------------------------
void __fastcall TFreqDispDlg::Execute(CFIRX *pFIR, int max, double SampleFreq)
{
	m_type = 0;
	m_H1 = pFIR->GetHP();
	m_Tap1 = pFIR->GetTap();
	m_Tap2 = 0;
    m_Max = max;
    m_SampleFreq = SampleFreq;
    MakeBitmap();
	ShowModal();
}
Beispiel #8
0
//---------------------------------------------------------------------
void __fastcall TFreqDispDlg::Execute(double a10, double b11, double b12, double a20, double b21, double b22, double SampleFreq)
{
	m_type = 1;
	m_a10 = a10;
	m_b11 = b11;
	m_b12 = b12;
	m_a20 = a20;
	m_b21 = b21;
	m_b22 = b22;
    m_SampleFreq = SampleFreq;
    MakeBitmap();
	ShowModal();
}
Beispiel #9
0
BOOL CInfBam::MakeBitmap(int nFrameWanted, COLORREF clrTrans, HBITMAP &hBitmap,
	BOOL bForceSize, int nWidth, int nHeight)
{
	ASSERT(m_pHeader);

	if (m_pHeader->wFrameCount < 1 )
		return(FALSE);

	if (nFrameWanted >= m_pHeader->wFrameCount)
		nFrameWanted = 0;

	INF_BAM_FRAME *pFrame = (INF_BAM_FRAME*)(m_pData+m_pHeader->dwFrameOffset+(nFrameWanted*sizeof(INF_BAM_FRAME)));

	if (pFrame->wWidth > MAX_ICON_WIDTH || pFrame->wHeight > MAX_ICON_HEIGHT)
		return(FALSE);

	COLORREF *pPal = (COLORREF*)(m_pData+m_pHeader->dwPaletteOffset);
	BYTE *pRawBits = m_pData+(pFrame->dwFrameDataOffset&0x7FFFFFFF);
	BOOL bIsCompressed;
	if (pFrame->dwFrameDataOffset&0x80000000)
		bIsCompressed = FALSE;
	else
		bIsCompressed = TRUE;

	if (!ExpandBamBits(
			pRawBits,
			pFrame->wWidth*pFrame->wHeight,
			pFrame->wWidth,
			pFrame->wHeight,
			m_pHeader->chTransparentIndex,
			clrTrans,
			pPal,
			m_clrDIBits,
			bIsCompressed))
		return(FALSE);

	if (!MakeBitmap(
			m_clrDIBits,
			pFrame->wWidth,
			pFrame->wHeight,
			hBitmap))
		return(FALSE);

	if (bForceSize)
		if (!FitAndCenterBitmap(hBitmap,clrTrans,nWidth,nHeight))
			return(FALSE);

	return(TRUE);
}
Beispiel #10
0
void CamArtProvider::GetBitmapEvent(wxCamArtProviderEvent& event)
{
	if (m_pHash && !m_pHash->empty())
	{
		BOOL FoundBitmapToLoad = FALSE;
		ResIDWithFlagsToBitmapPtr::iterator current;
		for( current = m_pHash->begin(); current != m_pHash->end(); ++current )
		{
			if (!current->second.m_pImage) // we have no blank bitmap
			{
				FoundBitmapToLoad = TRUE;

//				ResourceID r = GetResourceID(current->first);
//				CamArtFlags f = GetFlags(current->first);
//				TRACE(_T("Hash for bitmap 0x%x:%d %s"),f,r,CamResource::GetObjectName(r));

				wxImage * pBitmap = MakeBitmap(current->first);
				current->second.m_pImage = pBitmap?pBitmap:m_pMissingImage;
			}
		}

		if (FoundBitmapToLoad)
		{
			if (!m_InvalidateArtEventPending)
			{
				m_InvalidateArtEventPending = TRUE;
				BOOL defer=!event.m_deferred; //Defer the invalidate if this is immediate
				wxCamArtProviderEvent event (wxEVT_CAMARTPROVIDER_INVALIDATEART, 0, defer);
				if (defer)
					AddPendingEvent(event);
				else
					ProcessEvent(event);	
			}
		}
	}
	m_GetBitmapEventPending=FALSE;
}
Beispiel #11
0
/*
 * doReadInBitmapFile
 */
static BOOL doReadInBitmapFile( HBITMAP hbitmap, bitmap_info *bmi, char *fullname,
                                WRInfo *info, WResLangNode *lnode )
{
    HBITMAP             oldbmp1;
    HBITMAP             oldbmp2;
    img_node            node;
    char                filename[_MAX_FNAME + _MAX_EXT];
    BITMAPINFOHEADER    *h;
    HDC                 hdc;
    HDC                 srcdc;
    HDC                 destdc;

    GetFnameFromPath( fullname, filename );

    if( hbitmap != NULL ) {
        h = &bmi->u.bm_info->bmiHeader;

        if( h->biWidth > MAX_DIM || h->biHeight > MAX_DIM ) {
            WImgEditError( WIE_ERR_BITMAP_TOO_BIG, filename );
            MemFree( bmi->u.bm_info );
            DeleteObject( hbitmap );
            return( FALSE );
        }

#if 0
        /* Should not be an error... */
        else if( h->biBitCount > 8 ) {
            WImgEditError( WIE_ERR_TOO_MANY_COLOURS, filename );
            MemFree( bmi->u.bm_info );
            DeleteObject( hbitmap );
            return( FALSE );
        }
#endif
        node.imgtype = BITMAP_IMG;
        node.width = bmi->u.bm_info->bmiHeader.biWidth;
        node.height = bmi->u.bm_info->bmiHeader.biHeight;
        node.bitcount = bmi->u.bm_info->bmiHeader.biBitCount;
        node.hotspot.x = 0;
        node.hotspot.y = 0;
        node.num_of_images = 1;
        node.nexticon = NULL;
        node.issaved = TRUE;
        if( node.bitcount == 1 ) {
            hdc = GetDC( NULL );
            srcdc = CreateCompatibleDC( hdc );
            destdc = CreateCompatibleDC( hdc );
            ReleaseDC( NULL, hdc );

            node.hxorbitmap = CreateCompatibleBitmap( destdc, node.width, node.height );
            oldbmp1 = SelectObject( srcdc, hbitmap );
            oldbmp2 = SelectObject( destdc, node.hxorbitmap );
            BitBlt( destdc, 0, 0, node.width, node.height, srcdc, 0, 0, SRCCOPY );
            SelectObject( srcdc, oldbmp1 );
            SelectObject( destdc, oldbmp2 );
            DeleteDC( srcdc );
            DeleteDC( destdc );
            DeleteObject( hbitmap );
        } else {
            node.hxorbitmap = hbitmap;
        }

        strcpy( node.fname, fullname );
        PrintHintTextByID( WIE_OPENEDTEXT, filename );

        node.wrinfo = info;
        node.lnode = lnode;

        MakeBitmap( &node, FALSE );
        CreateNewDrawPad( &node );

        MemFree( bmi->u.bm_info );
        return( TRUE );
    }
    return( FALSE );

} /* doReadInBitmapFile */
Beispiel #12
0
BOOL CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   HDC hDC;
   TEXTMETRIC tm;
   PAINTSTRUCT ps;
   RECT rect;
   COLORREF clrref;
   LPDRAWITEMSTRUCT pDIS;
   HBRUSH hbr;
   int lineHeight;
   HWND hWndList;
   int nItem;
   HANDLE hFile;
   char filename[MAX_PATH];
   char file[MAX_PATH];
   char full_filename[MAX_PATH];
   int length;
   int index;
   HWND hItemWnd;
   BYTE palette_color;
   BYTE red, green, blue;
   float r_scale, g_scale, b_scale;
   CHAR item_name[16];
   CHAR wad_name[16];
   int x,y;
   int width, height;
   int difference, min_difference, min_index;
   DWORD dwSize;
   int mip_index;
   CHAR mip_name[16];
   int value, max_value;
   palette_t *pMipPalette;
   char src_filename[MAX_PATH], dest_filename[MAX_PATH];
   int miplevel, mipstep;
   unsigned char *pLump, *pLump0;
   int mip_width, mip_height;
   int count, xx, yy;
   int testpixel;

   switch (message)
   {
      case WM_INITDIALOG:

         if (!CenterWindow( hWnd ))
            return( FALSE );

         clrref = GetSysColor(COLOR_BTNFACE);
         h_background = CreateSolidBrush(clrref);

         hItemWnd = GetDlgItem(hWnd, IDC_ADD);
         EnableWindow(hItemWnd, FALSE);

         hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
         EnableWindow(hItemWnd, FALSE);

         hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
         EnableWindow(hItemWnd, FALSE);

         g_palette_color = 0;

         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));

         hFile = NULL;
         strcpy(filename, szParentPath);
         strcat(filename, "\\logos\\*.bmp");

         // display the .bmp files in the logos folder...
         while ((hFile = FindFile(hFile, file, filename)) != NULL)
         {
            strcpy(full_filename, szParentPath);
            strcat(full_filename, "\\logos\\");
            strcat(full_filename, file);

            if (CheckBitmapFormat(full_filename))
            {
               length = strlen(file);

               file[length-4] = 0;

               SendDlgItemMessage(hWnd, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)file));
            }
         }

         SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);

         strcpy(filename, szParentPath);
         strcat(filename, "\\");
         strcat(filename, g_szMODdir);
         strcat(filename, "\\decals.wad");

         if (!LoadWADFile(filename))
         {
            strcpy(filename, szParentPath);
            strcat(filename, "\\");
            strcat(filename, "valve");
            strcat(filename, "\\decals.wad");

            if (!LoadWADFile(filename))
            {
               MessageBox(hWnd, "Error loading WAD file!", "Error", MB_OK);
               SendMessage(hWnd, WM_COMMAND, IDCLOSE, 0L);

               return FALSE;
            }

            strcpy(g_szMODdir, "valve");

            MessageBox(hWnd, "This MOD uses the decals.wad file\nfrom the Half-Life valve directory", "Warning", MB_OK);
         }

         // display the lumps from the WAD file...
         for (index=0; index < MAX_MIPS; index++)
         {
            if (pMips[index])
            {
               if (strncmp(pMips[index]->name, "{__", 3) == 0)
               {
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[index]->name[3])));
               }

               if (strncmp(pMips[index]->name, "__", 2) == 0)
               {
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[index]->name[2])));
               }
            }
         }


         SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);
 
        break;

      case WM_MEASUREITEM:

         hDC = GetDC( hWnd );
         GetTextMetrics( hDC, &tm );
         ReleaseDC( hWnd, hDC );

         lineHeight = tm.tmExternalLeading +
                      tm.tmInternalLeading + tm.tmHeight;

         ((MEASUREITEMSTRUCT FAR *)(lParam))->itemHeight = lineHeight;

         return TRUE;

      case WM_DRAWITEM:

         pDIS = (LPDRAWITEMSTRUCT) lParam;

         // Draw the focus rectangle for an empty list box or an
         // empty combo box to indicate that the control has the focus

         if ((int)(pDIS->itemID) < 0)
         {
//            if ((pDIS->itemState) & (ODS_FOCUS))
//               DrawFocusRect (pDIS->hDC, &pDIS->rcItem);
            return TRUE;
         }

         if ((pDIS->itemAction == ODA_SELECT) ||
             (pDIS->itemAction == ODA_DRAWENTIRE))
         {
            hbr = NULL;

            palette_color = 0;

            if ((pDIS->itemID >= 1) && (pDIS->itemID <= 8))
            {
               palette_color = pDIS->itemID;

               red   = colors[palette_color-1][0];
               green = colors[palette_color-1][1];
               blue  = colors[palette_color-1][2];

//               hDC = CreateCompatibleDC(pDIS->hDC);
               hbr = CreateSolidBrush(RGB(red,green,blue));

               SelectObject(pDIS->hDC, hbr);
               Rectangle(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top,
                                    pDIS->rcItem.right,  pDIS->rcItem.bottom);
               DeleteObject(hbr);
//               DeleteDC(hDC);
            }

//            if (pDIS->itemState & ODS_FOCUS)
//               DrawFocusRect (pDIS->hDC, &pDIS->rcItem);

//            if (pDIS->itemState & ODS_SELECTED)
//            {
//               DrawFocusRect(pDIS->hDC, &pDIS->rcItem);
//            }
         }
//         else if (pDIS->itemAction == ODA_FOCUS)
//         {
//            DrawFocusRect (pDIS->hDC, &pDIS->rcItem);
//         }

         return TRUE; 

      case WM_PAINT:

         hDC = BeginPaint(hWnd, &ps);

         RedrawClientArea(hWnd, hDC);

         EndPaint(hWnd, &ps);

         return TRUE;

      case WM_COMMAND:

         switch (LOWORD(wParam))
         {
            case IDC_LIST1:
               if (HIWORD(wParam) == LBN_SELCHANGE)
               {
                  index = SendDlgItemMessage(hWnd, IDC_LIST1, LB_GETCURSEL, 0, 0L);

                  SendDlgItemMessage(hWnd, IDC_LIST1, LB_GETTEXT, index, (LPARAM)((LPSTR)filename));

                  strcpy(g_szBitmapName, filename);

                  strcpy(g_szFileName, szParentPath);
                  strcat(g_szFileName, "\\logos\\");
                  strcat(g_szFileName, filename);
                  strcat(g_szFileName, ".bmp");

                  hDC = GetDC(hWnd);

                  if (hBitmap)
                  {
                     if ((pbmi->bmiHeader.biHeight > 128) ||
                         (pbmi->bmiHeader.biWidth > 128))
                     {
                        GetClientRect(hWnd, &rect);
                        InvalidateRect(hWnd, &rect, TRUE);
                     }
                  }

                  LoadBitmapFromFile(hDC, g_szFileName);

                  if ((hBitmap) && (h_background))
                  {
                     rect.left = offset_x;
                     rect.top = offset_y;
                     rect.right = offset_x + size_x;
                     rect.bottom = offset_y + size_y;

                     FillRect(hDC, &rect, h_background);
                  }

                  MakeBitmap(hDC, OriginalPalette, pOriginalData);

                  ReleaseDC(hWnd, hDC);


                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);

                  SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

                  g_palette_color = 0;

                  hItemWnd = GetDlgItem(hWnd, IDC_ADD);
                  EnableWindow(hItemWnd, TRUE);

                  hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
                  EnableWindow(hItemWnd, FALSE);

                  hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
                  EnableWindow(hItemWnd, TRUE);

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_LIST2:
               if (HIWORD(wParam) == LBN_SELCHANGE)
               {
                  index = SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETCURSEL, 0, 0L);

                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETTEXT, index, (LPARAM)((LPSTR)item_name));

                  strcpy(wad_name, "{__");
                  strcat(wad_name, item_name);

                  // find the correct index based on name...

                  index = 0;
                  while (index < MAX_MIPS)
                  {
                     if (pMips[index])
                     {
                        if (strcmp(wad_name, pMips[index]->name) == 0)
                           break;
                     }

                     index++;
                  }

                  if (index == MAX_MIPS)
                  {
                     strcpy(wad_name, "__");
                     strcat(wad_name, item_name);

                     // find the correct index based on name...

                     index = 0;
                     while (index < MAX_MIPS)
                     {
                        if (pMips[index])
                        {
                           if (strcmp(wad_name, pMips[index]->name) == 0)
                              break;
                        }

                        index++;
                     }
                  }

                  if (index == MAX_MIPS)
                  {
                     MessageBox(hWnd, "Error finding mip!", "Error", MB_OK);
                     return TRUE;
                  }

                  hDC = GetDC(hWnd);

                  if (hBitmap)
                  {
                     if ((pbmi->bmiHeader.biHeight > 128) ||
                         (pbmi->bmiHeader.biWidth > 128))
                     {
                        GetClientRect(hWnd, &rect);
                        InvalidateRect(hWnd, &rect, TRUE);
                     }
                  }

                  LoadBitmapFromMip(index);

                  if ((hBitmap) && (h_background))
                  {
                     rect.left = offset_x;
                     rect.top = offset_y;
                     rect.right = offset_x + size_x;
                     rect.bottom = offset_y + size_y;

                     FillRect(hDC, &rect, h_background);
                  }

                  memcpy(Palette, OriginalPalette, (1 << pbmi->bmiHeader.biBitCount) * 4);

                  if ((Palette[255].rgbRed != 0) ||
                      (Palette[255].rgbGreen != 0) ||
                      (Palette[255].rgbBlue != 255))
                  {
                     r_scale = (float)Palette[255].rgbRed / (float)255.0;
                     g_scale = (float)Palette[255].rgbGreen / (float)255.0;
                     b_scale = (float)Palette[255].rgbBlue / (float)255.0;

                     // set palette 255 index back to pure white
                     Palette[255].rgbRed   = 255;
                     Palette[255].rgbGreen = 255;
                     Palette[255].rgbBlue  = 255;

                     for (index = 0; index < (1 << pbmi->bmiHeader.biBitCount); index++)
                     {
                        Palette[index].rgbRed   = (BYTE)((float)Palette[index].rgbRed * r_scale);
                        Palette[index].rgbGreen = (BYTE)((float)Palette[index].rgbGreen * g_scale);
                        Palette[index].rgbBlue  = (BYTE)((float)Palette[index].rgbBlue * b_scale);
                        Palette[index].rgbReserved = 0;
                     }
                  }

                  MakeBitmap(hDC, Palette, pOriginalData);

                  ReleaseDC(hWnd, hDC);

                  SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);

                  SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

                  g_palette_color = 0;

                  hItemWnd = GetDlgItem(hWnd, IDC_ADD);
                  EnableWindow(hItemWnd, FALSE);

                  hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
                  EnableWindow(hItemWnd, TRUE);

                  hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
                  EnableWindow(hItemWnd, FALSE);

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_COMBO1:
               switch(HIWORD(wParam))
               {
                  case CBN_SELCHANGE:
                     hWndList = GetDlgItem(hWnd, IDC_COMBO1);
                     nItem = SendMessage(hWndList, CB_GETCURSEL, 0, 0);

                  if (nItem == 0)
                  {
                     // restore palette to original color...
                     hDC = GetDC(hWnd);
                     MakeBitmap(hDC, OriginalPalette, pOriginalData);
                     ReleaseDC(hWnd, hDC);
                  }
                  else
                  {
                     g_palette_color = nItem;

                     red   = colors[g_palette_color-1][0];
                     green = colors[g_palette_color-1][1];
                     blue  = colors[g_palette_color-1][2];

                     // set the palette color
                     hDC = GetDC(hWnd);

                     memcpy(Palette, OriginalPalette, (1 << pbmi->bmiHeader.biBitCount) * 4);

                     r_scale = (float)red / (float)255.0;
                     g_scale = (float)green / (float)255.0;
                     b_scale = (float)blue / (float)255.0;

                     for (index = 0; index < (1 << pbmi->bmiHeader.biBitCount); index++)
                     {
                        Palette[index].rgbRed   = (BYTE)((float)Palette[index].rgbRed * r_scale);
                        Palette[index].rgbGreen = (BYTE)((float)Palette[index].rgbGreen * g_scale);
                        Palette[index].rgbBlue  = (BYTE)((float)Palette[index].rgbBlue * b_scale);
                        Palette[index].rgbReserved = 0;
                     }

                     MakeBitmap(hDC, Palette, pOriginalData);

                     ReleaseDC(hWnd, hDC);
                  }

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_ADD:

               if (num_mips >= MAX_MIPS)
                  return TRUE;

               changes = TRUE;

               width = pbmi->bmiHeader.biWidth;
               height = pbmi->bmiHeader.biHeight;

               // assume all of the colors are used for mip mapping...
               colors_used = 256;
               for (x=0; x < 256; x++) color_used[x] = 1;

               // write the bitmap data and palette to the lump array...
               index = 0;
               while (pMips[index])
                  index++;

               mip_index = index;

               dwSize = sizeof(miptex_t) + (width * height) +
                        (width * height / 4) + (width * height / 16) +
                        (width * height / 64) + sizeof(palette_t);

               pMips[mip_index] = (miptex_t *)LocalAlloc(LPTR, dwSize);

               pMips[mip_index]->height = pbmi->bmiHeader.biHeight;
               pMips[mip_index]->width = pbmi->bmiHeader.biWidth;
               pMips[mip_index]->offsets[0] = sizeof(miptex_t);
               pMips[mip_index]->offsets[1] = pMips[mip_index]->offsets[0] + width * height;
               pMips[mip_index]->offsets[2] = pMips[mip_index]->offsets[1] + (width * height) / 4;
               pMips[mip_index]->offsets[3] = pMips[mip_index]->offsets[2] + (width * height) / 16;

               pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[0];

               index = height - 1;

               for (y=0; y < height; y++)
               {
                  memcpy(pLump+(width * y), pOriginalData+(width * index), width);
                  index--;
               }

               pMipPalette = (palette_t *)((char *)pMips[mip_index] +
                             pMips[mip_index]->offsets[3] + (width * height / 64));

               pMipPalette->palette_size = 256;

               for (index = 0; index < 256; index++)
               {
                  pMipPalette->palette[index * 3 + 0] = OriginalPalette[index].rgbRed;
                  pMipPalette->palette[index * 3 + 1] = OriginalPalette[index].rgbGreen;
                  pMipPalette->palette[index * 3 + 2] = OriginalPalette[index].rgbBlue;
               }

               pMipPalette->padding = 0;

               memcpy(lbmpalette, pMipPalette->palette, 256 * 3);

               // calculate gamma corrected linear palette
               for (x = 0; x < 256; x++)
               {
                  for (y = 0; y < 3; y++)
                  {
                     float f;
                     f = (float)(lbmpalette[x*3+y] / 255.0);
//                     linearpalette[x][y] = (float)pow(f, 2.2 ); // assume textures are done at 2.2, we want to remap them at 1.0
                     linearpalette[x][y] = (float)pow(f, 1.0);
                  }
               }

               pLump0 = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[0];

               maxdistortion = 0;

               for (miplevel = 1; miplevel < 4; miplevel++)
      	      {
                  int pixTest;
                  d_red = d_green = d_blue = 0;	// no distortion yet

                  pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                  mipstep = 1 << miplevel;
                  pixTest = (int)((float)(mipstep * mipstep) * 0.4);	// 40% of pixels

                  for (y = 0; y < height ; y += mipstep)
                  {
                     for (x = 0 ; x < width ; x += mipstep)
                     {
                        count = 0;

                        for (yy = 0; yy < mipstep; yy++)
                        {
                           for (xx = 0; xx < mipstep; xx++)
                           {
                              testpixel = pLump0[(y+yy)*width + x + xx ];
						
                              // If this isn't a transparent pixel, add it in to the image filter
                              if ( testpixel != 255 )
                              {
                                 pixdata[count] = testpixel;
                                 count++;
                              }
                           }
                        }

                        if ( count <= pixTest )	// Solid pixels account for < 40% of this pixel, make it transparent
                        {
                           *pLump++ = 255;
                        }
                        else
                        {
                           *pLump++ = AveragePixels(count);
                        }
                     }	
                  }
               }


               if (!g_monochrome)
               {
                  // assume none of the colors are used for palette 255 setting...
                  colors_used = 0;

                  for (x=0; x < 256; x++)
                     color_used[x] = 0;

                  for (x=0; x < width; x++)
                  {
                     for (y=0; y < height; y++)
                     {
                        if (!color_used[pOriginalData[x*height + y]])
                        {
                           color_used[pOriginalData[x*height + y]] = 1;
                           colors_used++;
                        }
                     }
                  }

                  // if all colors used and index 255 is NOT pure blue...
                  if ((colors_used == 256) &&
                      ((OriginalPalette[255].rgbRed !=0) ||
                       (OriginalPalette[255].rgbGreen != 0) ||
                       (OriginalPalette[255].rgbBlue != 255)))
                  {
                     // replace index 255 color with closest color...

                     red   = OriginalPalette[255].rgbRed;
                     green = OriginalPalette[255].rgbGreen;
                     blue  = OriginalPalette[255].rgbBlue;

                     min_difference = 256*3;
                     min_index = 0;

                     for (index=0; index < 255; index++)
                     {
                        difference = abs(OriginalPalette[index].rgbRed - red) +
                                     abs(OriginalPalette[index].rgbGreen - green) +
                                     abs(OriginalPalette[index].rgbBlue - blue);

                        if (difference < min_difference)
                        {
                           min_difference = difference;
                           min_index = index;
                        }
                     }

                     for (miplevel = 0; miplevel < 4; miplevel++)
                     {
                        mipstep = 1 << miplevel;
                        pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                        mip_width = width/mipstep;
                        mip_height = height/mipstep;

                        for (x=0; x < mip_width; x++)
                        {
                           for (y=0; y < mip_height; y++)
                           {
                              if (pLump[x*mip_height + y] == 255)
                                 pLump[x*mip_height + y] = min_index;
                           }
                        }
                     }

                     colors_used--;
                     color_used[255] = 0;
                  }

                  if ((colors_used < 256) && (color_used[255]))
                  {
                     // move index 255 to first unused position...

                     index = 0;
                     while (color_used[index])
                        index++;

                     pMipPalette->palette[index * 3 + 0] = OriginalPalette[255].rgbRed;
                     pMipPalette->palette[index * 3 + 1] = OriginalPalette[255].rgbGreen;
                     pMipPalette->palette[index * 3 + 2] = OriginalPalette[255].rgbBlue;

                     for (miplevel = 0; miplevel < 4; miplevel++)
                     {
                        mipstep = 1 << miplevel;
                        pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                        mip_width = width/mipstep;
                        mip_height = height/mipstep;

                        for (x=0; x < mip_width; x++)
                        {
                           for (y=0; y < mip_height; y++)
                           {
                              if (pLump[x*mip_height + y] == 255)
                                 pLump[x*mip_height + y] = index;
                           }
                        }
                     }
                  }

                  pMipPalette->palette[255 * 3 + 0] = 0;
                  pMipPalette->palette[255 * 3 + 1] = 0;
                  pMipPalette->palette[255 * 3 + 2] = 255;
               }

               if (g_palette_color != 0)
               {
                  pMipPalette->palette[255 * 3 + 0] = colors[g_palette_color-1][0];
                  pMipPalette->palette[255 * 3 + 1] = colors[g_palette_color-1][1];
                  pMipPalette->palette[255 * 3 + 2] = colors[g_palette_color-1][2];
               }


               if (strlen(g_szBitmapName) > 9)
                  g_szBitmapName[10] = 0;

               if (g_monochrome)
                  strcpy(mip_name, "__");
               else
                  strcpy(mip_name, "{__");

               strcat(mip_name, g_szBitmapName);

               length = strlen(mip_name);

               max_value = 0;

               // find the highest number for this name...
               for (index = 0; index < num_mips; index++)
               {
                  if (pMips[index])
                  {
                     if (strncmp(pMips[index]->name, mip_name, length) == 0)
                     {
                        sscanf(&(pMips[index]->name[length+1]), "%d", &value);

                        if (value > max_value)
                           max_value = value;
                     }
                  }
               }

               max_value++;

               if (max_value > 99)
               {
                  MessageBox(hWnd, "Too many mips for this file!", "Error", MB_OK);
                  LocalFree(pMips[mip_index]);
                  pMips[mip_index] = NULL;
                  return TRUE;
               }

               sprintf(pMips[mip_index]->name, "%s_%02d", mip_name, max_value);

               if (g_monochrome)
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[mip_index]->name[2])));
               else
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[mip_index]->name[3])));

               num_mips++;


               return TRUE;

            case IDC_REMOVE:

               changes = TRUE;

               index = SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETCURSEL, 0, 0L);

               SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETTEXT, index, (LPARAM)((LPSTR)item_name));

               SendDlgItemMessage(hWnd, IDC_LIST2, LB_DELETESTRING, index, 0L);

               strcpy(wad_name, "{__");
               strcat(wad_name, item_name);

               // find the correct index based on name...

               index = 0;
               while (index < MAX_MIPS)
               {
                  if (pMips[index])
                  {
                     if (strcmp(wad_name, pMips[index]->name) == 0)
                        break;
                  }

                  index++;
               }

               if (index == MAX_MIPS)
               {
                  strcpy(wad_name, "__");
                  strcat(wad_name, item_name);

                  // find the correct index based on name...

                  index = 0;
                  while (index < MAX_MIPS)
                  {
                     if (pMips[index])
                     {
                        if (strcmp(wad_name, pMips[index]->name) == 0)
                           break;
                     }

                     index++;
                  }
               }

               if (index == MAX_MIPS)
               {
                  MessageBox(hWnd, "Error finding mip!", "Error", MB_OK);
                  return FALSE;
               }

               LocalFree(pMips[index]);

               pMips[index] = NULL;


               hDC = GetDC(hWnd);

               if (hBitmap)
               {
                  if ((pbmi->bmiHeader.biHeight > 128) ||
                      (pbmi->bmiHeader.biWidth > 128))
                  {
                     GetClientRect(hWnd, &rect);
                     InvalidateRect(hWnd, &rect, TRUE);
                  }
               }

               if ((hBitmap) && (h_background))
               {
                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  FillRect(hDC, &rect, h_background);
                  InvalidateRect(hWnd, &rect, TRUE);
               }

               ReleaseDC(hWnd, hDC);

               if (hBitmap)
                  DeleteObject(hBitmap);

               UpdateWindow(hWnd);


               SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);
               SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);
               SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

               g_palette_color = 0;

               hItemWnd = GetDlgItem(hWnd, IDC_ADD);
               EnableWindow(hItemWnd, FALSE);

               hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
               EnableWindow(hItemWnd, FALSE);

               hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
               EnableWindow(hItemWnd, FALSE);

               return TRUE;

            case IDCLOSE:

               if (changes)
               {
                  if (MessageBox(hWnd, "Do you wish to save your changes?", "Warning", MB_YESNO) == IDYES)
                  {
                     // check if backup file is needed

                     strcpy(src_filename, szParentPath);
                     strcat(src_filename, "\\");
                     strcat(src_filename, g_szMODdir);
                     strcat(src_filename, "\\decals.wad");

                     strcpy(dest_filename, szParentPath);
                     strcat(dest_filename, "\\");
                     strcat(dest_filename, g_szMODdir);
                     strcat(dest_filename, "\\decals_old.wad");

                     if (CopyFile(src_filename, dest_filename, TRUE))
                        MessageBox(hWnd, "A backup copy of decals.wad was\ncreated called decals_old.wad", "Warning", MB_OK);

                     if (!WriteWADFile(src_filename))
                        MessageBox(hWnd, "An error occured writing decals.wad", "Error", MB_OK);
                  }
               }

               for (index = 0; index < MAX_MIPS; index++)
               {
                  if (pMips[index])
                     LocalFree(pMips[index]);
               }

               if (pbmi)
                  LocalFree(pbmi);

               if (pOriginalData)
                  LocalFree(pOriginalData);

               if (hBitmap)
                  DeleteObject(hBitmap);

               if (hPalette)
                  DeleteObject(hPalette);

               if (h_background)
                  DeleteObject(h_background);

               PostQuitMessage(0);
               return TRUE;
         }

         break;

      case WM_CLOSE:

         SendMessage(hWnd, WM_COMMAND, IDCLOSE, 0L);

         break;
   }

   return FALSE;
}
Beispiel #13
0
/*
 * SelectDynamicBitmap - Lets the user select the bitmap from the screen.
 */
BOOL SelectDynamicBitmap( img_node *node, int imgcount, char *filename )
{
    HDC         hdc;
    HDC         memdc;
    HBITMAP     oldbitmap;
    HWND        bitmappickwindow;
    MSG         msg;
    RECT        screen_coords;

    if (IsZoomed(HMainWindow)) {
        prevState = SW_SHOWMAXIMIZED;
    } else {
        prevState = SW_SHOWNORMAL;
    }
#ifdef __NT__
    RegisterSnapClass(Instance);
    ShowWindow(HMainWindow, SW_SHOWMINIMIZED);
    ShowWindow(HMainWindow, SW_HIDE);
    deskTopWindow = DisplayDesktop( HMainWindow );
#else
    ShowWindow( HMainWindow, SW_SHOWMINIMIZED );
    ShowWindow(HMainWindow, SW_HIDE);
#endif

    bitmappickwindow = CreateWindow(
        BitmapPickClass,    /* Window class name */
        "",                 /* Window caption */
        WS_CHILDWINDOW,     /* Window style */
        0,                  /* Initial X position */
        0,                  /* Initial Y position */
        0,                  /* Initial X size */
        0,                  /* Initial Y size */
        HMainWindow,        /* Parent window handle */
        (HMENU) NULL,       /* Window menu handle */
        Instance,           /* Program instance handle */
        NULL );             /* Create parameters */

    if( bitmappickwindow == NULL ) return FALSE;

    while(notDestroyed && GetMessage(&msg, bitmappickwindow, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    if (bmpRegion.right > bmpRegion.left) {
        screen_coords.left = bmpRegion.left;
        screen_coords.right = bmpRegion.right;
    } else {
        screen_coords.left = bmpRegion.right;
        screen_coords.right = bmpRegion.left;
    }
    if (bmpRegion.bottom > bmpRegion.top) {
        screen_coords.bottom = bmpRegion.bottom;
        screen_coords.top = bmpRegion.top;
    } else {
        screen_coords.bottom = bmpRegion.top;
        screen_coords.top = bmpRegion.bottom;
    }
    if ( (screen_coords.right - screen_coords.left == 0) ||
                        (screen_coords.bottom - screen_coords.top == 0) ) {
        ShowWindow( HMainWindow, prevState );
#ifdef __NT__
        DestroyWindow( deskTopWindow );
#endif
        IEDisplayErrorMsg( WIE_APPNAME, WIE_INVALIDREGIONSELECTED,
                           MB_OK | MB_ICONINFORMATION );
        notDestroyed = TRUE;
        return(FALSE);
    }

    node->imgtype = BITMAP_IMG;
    node->width = (short)(screen_coords.right-screen_coords.left);
    node->height = (short)(screen_coords.bottom-screen_coords.top);
    node->bitcount = 4;                 // ?????
    node->hotspot.x = 0;
    node->hotspot.y = 0;
    node->num_of_images = 1;
    node->nexticon = NULL;
    node->issaved = FALSE;
    node->next = NULL;
    if( filename != NULL ) {
        strcpy( node->fname, filename );
    } else {
        sprintf( node->fname, "%s (%d)", IEImageUntitled, imgcount );
    }

    MakeBitmap( node, TRUE );

    hdc = GetDC(NULL);
    memdc = CreateCompatibleDC( hdc );

    oldbitmap = SelectObject( memdc, node->handbitmap );
    PatBlt( memdc, 0, 0, node->width, node->height, BLACKNESS );

    SelectObject( memdc, node->hxorbitmap );
    BitBlt(memdc, 0, 0, node->width, node->height, hdc, screen_coords.left,
                                                screen_coords.top, SRCCOPY);
    ReleaseDC(NULL, hdc);
    SelectObject( memdc, oldbitmap );
    DeleteDC( memdc );

    ShowWindow( HMainWindow, prevState );
#ifdef __NT__
    DestroyWindow( deskTopWindow );
#endif
    notDestroyed = TRUE;
    return(TRUE);
} /* SelectDynamicBitmap */
Beispiel #14
0
/*
 * ChangeImageSize - changes the size of the current image being edited
 */
void ChangeImageSize( void )
{
    img_node        *node;
    WPI_DLGPROC     dlgproc;
    WPI_DLGRESULT   button_type;
    img_node        new_node;
    WPI_PRES        pres;
    HDC             srcdc;
    WPI_PRES        srcpres;
    HDC             destdc;
    WPI_PRES        destpres;
    HBITMAP         oldsrc;
    HBITMAP         olddest;
    int             retcode;
    WPI_PARAM2      lparam;
    WPI_RECT        rc;
    short           new_width;
    short           new_height;
    int             y_src;
    int             y_dest;
    char            *title;
    char            *text;

    node = GetCurrentNode();
    if( node == NULL ) {
        return;
    }

    if( node->imgtype != BITMAP_IMG ) {
        return;
    }

    imgHeight = node->height;
    imgWidth = node->width;

    dlgproc = _wpi_makedlgprocinstance( ChangeSizeDlgProc, Instance );
    button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, IMAGESIZE, 0L );
    _wpi_freedlgprocinstance( dlgproc );

    if( button_type == DLGID_CANCEL ) {
        return;
    }
    if( imgWidth == node->width && imgHeight == node->height ) {
        PrintHintTextByID( WIE_IMAGESIZEUNCHANGED, NULL );
        return;
    }
    title = IEAllocRCString( WIE_INFORMATIONTEXT );
    text = IEAllocRCString( WIE_RESETUNDOSTACKWARNING );
    retcode = _wpi_messagebox( HMainWindow, text, title, MB_YESNO | MB_ICONINFORMATION );
    if( text != NULL ) {
        IEFreeRCString( text );
    }
    if( title != NULL ) {
        IEFreeRCString( title );
    }

    if( retcode == WPI_IDNO ) {
        return;
    }

    new_node.width = (short)imgWidth;
    new_node.height = (short)imgHeight;
    new_node.bitcount = node->bitcount;
    new_node.imgtype = BITMAP_IMG;

    MakeBitmap( &new_node, TRUE );

    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    oldsrc = _wpi_selectbitmap( srcpres, node->hxorbitmap );
    olddest = _wpi_selectbitmap( destpres, new_node.hxorbitmap );

    if( stretchImage ) {
        _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight,
                         srcpres, 0, 0, node->width, node->height, SRCCOPY );
    } else {
#ifdef __OS2_PM__
        y_src = node->height - imgHeight;
        if( y_src < 0 ) {
            y_src = 0;
            y_dest = imgHeight - node->height;
        } else {
            y_dest = 0;
        }
#else
        y_src = 0;
        y_dest = 0;
#endif
        _wpi_bitblt( destpres, 0, y_dest, node->width, node->height,
                     srcpres, 0, y_src, SRCCOPY );
    }
    _wpi_getoldbitmap( srcpres, oldsrc );
    oldsrc = _wpi_selectbitmap( srcpres, node->handbitmap );
    _wpi_getoldbitmap( destpres, olddest );
    olddest = _wpi_selectbitmap( destpres, new_node.handbitmap );

    if( stretchImage ) {
        _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight,
                         srcpres, 0, 0, node->width, node->height, SRCCOPY );
    } else {
        _wpi_bitblt( destpres, 0, 0, node->width, node->height, srcpres, 0, 0, SRCCOPY );
    }

    _wpi_getoldbitmap( srcpres, oldsrc );
    _wpi_getoldbitmap( destpres, olddest );
    _wpi_deletebitmap( node->hxorbitmap );
    _wpi_deletebitmap( node->handbitmap );
    _wpi_deletecompatiblepres( srcpres, srcdc );
    _wpi_deletecompatiblepres( destpres, destdc );

    node->hxorbitmap = new_node.hxorbitmap;
    node->handbitmap = new_node.handbitmap;
    node->width = (short)imgWidth;
    node->height = (short)imgHeight;

    SetIsSaved( node->hwnd, FALSE );
    ResetUndoStack( node );

    RePositionViewWnd( node );

    _wpi_getclientrect( node->hwnd, &rc );
    new_width = (short)_wpi_getwidthrect( rc );
    new_height = (short)_wpi_getheightrect( rc );
    lparam = WPI_MAKEP2( new_width, new_height );

    ResizeChild( lparam, node->hwnd, false );
    DisplayImageText( node );
    WriteSetSizeText( WIE_NEWIMAGESIZE, imgWidth, imgHeight );

} /* ChangeImageSize */
Beispiel #15
0
	void _do_make_page_bitmap_and_metric(
		GLint page,
		unsigned char* bmp_data,
		float* metric
	) const
	{
		float scale = _tt_font.ScaleForPixelHeight(_font_resolution);

		const GLuint px = _font_resolution;
		const GLuint ts = _tex_side;
		const float inv_px = 1.0f/float(px);
		const float inv_ts = 1.0f/float(ts);

		std::vector<unsigned char> tmp[2];
		tmp[0].resize(px*px, 0x00);
		tmp[1].resize(px*px, 0x00);

		unsigned glyphs_per_page = BitmapGlyphGlyphsPerPage(_parent);

		int xoffs = 0, oldxoffs = 0;
		int yoffs = 0;
		int row_height = 0;
		int x0, y0, x1, y1, lb, width, asc, dsc, lg;
		for(unsigned g=0; g!=glyphs_per_page; ++g)
		{
			int code_point = glyphs_per_page*page+g;
			auto glyph = _tt_font.GetGlyph(code_point);

			if(std::isspace(code_point))
				tmp[g%2]=std::vector<unsigned char>(px*px,0x00);
			glyph.MakeBitmap(tmp[g%2].data(), px, px, px, scale);

			// if this glyph is not the same as the previous
			if((g == 0) || (tmp[0] != tmp[1]))
			{
				glyph.GetBitmapBox(x0, y0, x1, y1);
				glyph.GetVMetrics(asc, dsc, lg);
				glyph.GetHMetrics(lb, width);

				int advance = int((x1-x0)*scale)+2;
				int glyph_height = int((y1-y0)*scale)+2;

				if(row_height < glyph_height)
					row_height = glyph_height;

				if(xoffs+advance >= int(ts))
				{
					xoffs = 0;
					yoffs += row_height;
					row_height = 0;
				}

				if(bmp_data)
				{
					glyph.MakeBitmap(
						bmp_data+ts*yoffs+xoffs,
						advance,
						px,
						ts,
						scale
					);
				}
				oldxoffs = xoffs;
				xoffs += advance;
			}
			if(metric)
			{
				float* p = metric+12*g;
				// logical rectangle metrics
				p[ 0] = lb*scale*inv_px;
				p[ 1] = (lb+width)*scale*inv_px;
				p[ 2] = asc*scale*inv_px;
				p[ 3] = -dsc*scale*inv_px;
				// ink rectangle metrics
				p[ 4] = x0*scale*inv_px;
				p[ 5] = x1*scale*inv_px;
				p[ 6] =-y0*scale*inv_px;
				p[ 7] = y1*scale*inv_px;
				// texture-space rectangle
				p[ 8] = (oldxoffs)*inv_ts;
				p[ 9] = (yoffs-y0*scale)*inv_ts;
				p[10] = ((x1-x0)*scale+1)*inv_ts;
				p[11] = ((y0-y1)*scale+1)*inv_ts;
			}
		}
		// TODO: hint that only the upper part of the image is actually
		// used + InvalidateTexImage
		// or increase the px value to get better resolution
	}
Beispiel #16
0
// 渲染图形图像
HRESULT ImageRenderer::OnRender(UINT syn){
    HRESULT hr = S_OK;
    // 没有就创建
    if (!m_pd2dDeviceContext) {
        hr = this->CreateDeviceResources();
    }
    this->Lock();
    auto tnow_point = this->now_point;
    auto tpoints = this->points;
    this->Unlock();
    // 成功就渲染
    if (SUCCEEDED(hr)) {
        // 开始渲染
        m_pd2dDeviceContext->BeginDraw();
        // 重置转换
        m_pd2dDeviceContext->SetTransform(D2D1::Matrix3x2F::Identity());
        // 清屏
        m_pd2dDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::White));
        // 正式刻画.........
        if (tnow_point != tpoints) {
            auto i = tpoints;
            for (; i < tnow_point; ++i) {
                m_pd2dDeviceContext->DrawLine(i[0], i[1], m_pBlackBrush);
            }
            m_pd2dDeviceContext->DrawLine(*i, *tpoints, m_pBlackBrush);
        }
        if (!tnow_point) {
            // 检查是否存在路径几何
            if (!m_pNowPath) {
                MakePath();
                MakeBitmap();
            }
            D2D1_RECT_F rect = { 0.f };
            reinterpret_cast<D2D1_SIZE_F&>(rect.right) = m_pd2dDeviceContext->GetSize();
            auto rect2 = rect;
            rect.right *= 0.5f;
            rect2.left = rect.right;
            // 左边显示Direct2D
            m_pd2dDeviceContext->PushAxisAlignedClip(rect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
            if (m_pNowPath)   m_pd2dDeviceContext->FillGeometry(m_pNowPath, m_pBlackBrush);
            m_pd2dDeviceContext->PopAxisAlignedClip();
            // 右边显示边缘填充
            m_pd2dDeviceContext->PushAxisAlignedClip(rect2, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
            m_pd2dDeviceContext->DrawBitmap(m_pNowBitmap);
            m_pd2dDeviceContext->PopAxisAlignedClip();
            // 中间分界线
            m_pBlackBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Red));
            m_pd2dDeviceContext->DrawLine(
                D2D1::Point2F(rect2.left),
                D2D1::Point2F(rect2.left, rect2.bottom),
                m_pBlackBrush,
                2.f
                );
            m_pBlackBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black));
        }
        // 结束渲染
        m_pd2dDeviceContext->EndDraw();
        // 呈现目标
        hr = m_pSwapChain->Present(syn, 0);
    }
    // 设备丢失?
    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
        this->DiscardDeviceResources();
        hr = S_FALSE;
    }
    return hr;
}