コード例 #1
0
HRESULT ParaEngine::CCCSFaceLoader::ComposeWithGDIPlus()
{
	HRESULT hr = S_OK;
#ifdef USE_DIRECTX_RENDERER
	// DO the texture composition here
	CGDIEngine* pEngine = CAsyncLoader::GetSingleton().GetGDIEngine();
	if (pEngine == NULL)
		return E_FAIL;
	pEngine->SetRenderTarget(pEngine->CreateGetRenderTargetBySize(CCharCustomizeSysSetting::FaceTexSize));
	pEngine->Begin();

	for (int i = 0; i<CFS_TOTAL_NUM; ++i)
	{
		const CharRegionCoords &coords = CCharCustomizeSysSetting::regions[CR_FACE_BASE + i];
		const FaceTextureComponent& component = m_layers[i];

		// load the component texture
		if (component.name.empty())
			continue;
		string componentfilename = component.name;

		AssetFileEntry* pEntry = CAssetManifest::GetSingleton().GetFile(componentfilename);
		if (pEntry)
			componentfilename = pEntry->GetLocalFileName();

		// compute the transform matrix
		Gdiplus::Matrix transformMatrix;
		// scale around the center
		float fScale = component.GetScaling();
		if (fabs(fScale)>0.01f)
		{
			transformMatrix.Scale(fScale + 1.f, fScale + 1.f);
		}

		// rotate around the center
		float fRotation = component.GetRotation();
		if (fabs(fRotation) > 0.01f)
		{
			transformMatrix.Rotate(fRotation);
		}

		// translation
		int x, y;
		component.GetPosition(&x, &y);
		transformMatrix.Translate(coords.xpos + (float)x, coords.ypos + (float)y);
		pEngine->SetTransform(&transformMatrix);

		Color color = component.GetColor();
		pEngine->DrawImage(pEngine->LoadTexture(componentfilename, component.name), (float)(-coords.xsize / 2), (float)(-coords.ysize / 2), (float)coords.xsize, (float)coords.ysize, color);

		// for eye and eye bow, there should be a mirrored image, around the center of the render target
		if (i == CFS_EYE || i == CFS_EYEBROW)
		{
			Gdiplus::Matrix reflectMat(-1.f, 0.f, 0.f, 1.f, CCharCustomizeSysSetting::FaceTexSize - (coords.xpos + (float)x) * 2, 0.f);
			transformMatrix.Multiply(&reflectMat);
			pEngine->SetTransform(&transformMatrix);
			pEngine->DrawImage(pEngine->LoadTexture(componentfilename, component.name), (float)(-coords.xsize / 2), (float)(-coords.ysize / 2), (float)coords.xsize, (float)coords.ysize);
		}
	}
	CParaFile::CreateDirectory(m_sFileName.c_str());
	hr = (pEngine->SaveRenderTarget(m_sFileName, CCharCustomizeSysSetting::FaceTexSize, CCharCustomizeSysSetting::FaceTexSize, false, 0)) ? S_OK : E_FAIL;
	pEngine->End();
#endif
	return hr;
}
コード例 #2
0
ファイル: EditTiffUnit.cpp プロジェクト: ands904/SEnum
void __fastcall TTiffBook::FlipCurPage(int n) {
//-------------------------------------------------------------------------------
//               Переворачивает текущую страницу вверх ногами                   |
// n - номер страницы, который надо нанести. <= 0 - только убрать ном стр       |
//-------------------------------------------------------------------------------
    stop++;
    Gdiplus::Graphics *g32;
    TTiffImage *img = GetImagePage(GetPage());
    Gdiplus::Bitmap *fbm = img->fbm;
    Gdiplus::Rect r;
    int w = fbm->GetWidth(), h = fbm->GetHeight();

    // g = new Gdiplus::Graphics(fbm);

    Gdiplus::Bitmap *b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB);
    g32 = new Gdiplus::Graphics(b32);

    Gdiplus::Matrix matr;
    matr.Rotate(180.0f);                // поворачиваем его на 270 градусов
    g32->SetTransform(&matr);

    //r.X = 0;
    //r.Y = 0;
    //r.Width = w;
    //r.Height = h;

    //r.X = -SaveBitmapH;
    //r.Y = -30;
    //r.Width = SaveBitmapH - 30;
    //r.Height = SaveBitmapW - 30;

    r.X = -w;
    r.Y = -h;
    r.Width = w;
    r.Height = h;

    sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    matr.Reset();
    g32->SetTransform(&matr);

    // Удаляем черные полосы сверху и снизу
    Gdiplus::Pen whitePen2(Gdiplus::Color(255, 255, 255, 255), 2);
    g32->DrawLine(&whitePen2, 0, 0, w, 0);
    g32->DrawLine(&whitePen2, 0, h-1, w, h-1);

    // Удаляем старый номер страницы - он теперь внизу
    // Gdiplus::Pen whitePen40(Gdiplus::Color(255, 0, 0, 0), 45);   // ??? Пока черный - для отладки!
    Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
    g32->DrawLine(&whitePen40, 0, h - 50, 200, h - 50);

    if (n > 0) {                        // Здесь выводим номер страницы
        AnsiString snum;
        wchar_t wnum[20];
        snum.printf("%d", n);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(w - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        g32->DrawLine(&whitePen40, w - 200, 50, w, 50);
        sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    }

    //if (npage > 0) {            // Здесь выводим номер страницы
    //    AnsiString snum;
    //    wchar_t wnum[20];
    //    snum.printf("%d", npage);
    //    snum.WideChar(wnum, 20);
    //    Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
    //    Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f);
    //    Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
    //    SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    //}

    // ------- строим SaveBitmap2TiffBitmap1
    UINT *pix;
    unsigned char byte, bit, *pix1;

    Gdiplus::Bitmap *b1 = new Gdiplus::Bitmap(w, h, PixelFormat1bppIndexed);
    Gdiplus::Rect BitsRect(0, 0, w, h);
    Gdiplus::BitmapData *bits = new Gdiplus::BitmapData;
    Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData;
    sres = b32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits);
    sres = b1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1);

    for (int y = 0; y < h; y++) {
        pix = (UINT *)((int)bits->Scan0 + bits->Stride * y);
        pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y);
        byte = 0;
        for (int x = 0; x < w; x++, pix++) {
            if ((*pix & 0xFF) > 0xD8) {
                bit = 1;
            }
            else bit = 0;
            byte <<= 1; byte |= bit;
            if ((x & 7) == 7) {
                *pix1++ = byte;
                byte = 0;
            }
        }
    }

    b32->UnlockBits(bits); delete bits;
    b1->UnlockBits(bits1); delete bits1;

    delete g32;
    delete b32;

    TTiffPageInfo *pi = GetPageInfo(GetPage());
    if (img->Filn.Length() == 0) {                  // Это уже временный файл!
        delete img->fbm;
        img->fbm = b1;
    } else {                                        // Надо будет заменить страницу на временный файл
        img = new TTiffImage(b1);
        pi->ImageIndex = AppendImage(img);
        pi->PageIndex = 0;
    }

    changed = true;
}