int
__glXDisp_GetColorTable(__GLXclientState * cl, GLbyte * pc)
{
    const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);

    return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
}
int
__glXDispSwap_GetColorTableSGI(__GLXclientState * cl, GLbyte * pc)
{
    const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);

    return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
}
Esempio n. 3
0
/////////////////////////////////////////////////////////////////////////////
//
// Draw DIB on caller's DC. Does stretching from source to destination
// rectangles.  Generally, it's OK to let the following default to zero:
//
//    bUseDrawDib = whether to use use DrawDib, default TRUE
//    pPalette    = palette, default = 0, (use DIB's palette)
//    bForeground = realize in foreground (default FALSE)
//
// If handling palette messages, use bForeground = FALSE, since the
// foreground palette will be realized in WM_QUERYNEWPALETTE.
//
/////////////////////////////////////////////////////////////////////////////
zBOOL
ZDib::Draw( CDC& dc, const CRect *rectTgt, const CRect *rectSrc,
            zBOOL bUseDrawDib, CPalette *pPalette, zBOOL bForeground )
{
   if ( m_hObject == 0 )
      return( FALSE );

   // Select, realize palette.
   if ( pPalette == 0 )              // no palette specified:
      pPalette = GetPalette( );      // use default

   CPalette *pOldPal = dc.SelectPalette( pPalette, !bForeground );
   dc.RealizePalette( );

   zBOOL bRC = FALSE;
   if ( bUseDrawDib )
   {
      // Compute rectangles where 0 specified.
      CRect rect( 0, 0, -1, -1 );  // default for ::DrawDibDraw
      if ( rectSrc == 0 )
         rectSrc = ▭

      if ( rectTgt == 0 )
         rectTgt = rectSrc;

      if ( m_hdd == 0 )
         VERIFY( (m_hdd = ::DrawDibOpen( )) != 0 );

      // Get BITMAPINFOHEADER/color table.  Copy into stack object each time.
      // This doesn't seem to slow things down visibly.
      DIBSECTION ds;
      VERIFY( GetObject( sizeof( ds ), &ds ) == sizeof( ds ) );
      char buf[ sizeof( BITMAPINFOHEADER ) + MAXPALCOLORS * sizeof( RGBQUAD ) ];
      BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER *) buf;
      RGBQUAD *colors = (RGBQUAD *) (&bmih + 1);
      zmemcpy( &bmih, &ds.dsBmih, sizeof( bmih ) );
      GetColorTable( colors, MAXPALCOLORS );

      // Let DrawDib do the work!
      bRC = ::DrawDibDraw( m_hdd, dc,
                           rectTgt->left, rectTgt->top,
                           rectTgt->Width( ), rectTgt->Height( ),
                           &bmih,        // ptr to BITMAPINFOHEADER + colors
                           m_bitmap.bmBits, // bits in memory
                           rectSrc->left, rectSrc->top,
                           rectSrc->Width( ), rectSrc->Height( ),
                           bForeground ? 0 : DDF_BACKGROUNDPAL );

   }
   else
   {
      // Use normal draw function.
      bRC = DrawBitmap( dc, this, rectTgt, rectSrc );
   }

   if ( pOldPal )
      dc.SelectPalette( pOldPal, TRUE );

   return( bRC );
}
Esempio n. 4
0
UINT CDIB::GetColorTableEntries(HDC hdc, HBITMAP hBitmap)
{
    if (!m_iColorTableSize)
        return 0;

    // Fill the color table with the colors from the bitmap's color table
    LPRGBQUAD pColorTable = GetColorTable();
    
    // Get the color table from the HBITMAP and copy them over.
    UINT nCount;
    RGBQUAD* pRGB = new RGBQUAD[m_iColorTableSize];
    if (pRGB)
    {
        HBITMAP hOldBitmap = (HBITMAP) SelectObject(hdc, hBitmap);
        nCount = CEGetDIBColorTable(hdc, 0, m_iColorTableSize, pRGB);
        SelectObject(hdc, hOldBitmap);
        if (nCount)
        {
            // m_iColorTableSize = nCount;
            memcpy(pColorTable, pRGB, nCount*sizeof(RGBQUAD));
        }
    }
    delete [] pRGB;

    // Didn't work - so synthesize one.
    if (!nCount)
    {       
        nCount = min( m_iColorTableSize, sizeof(ms_StdColors) / sizeof(ms_StdColors[0]) );
        memcpy(pColorTable, ms_StdColors, nCount*sizeof(RGBQUAD));
    }

    return nCount;
}
Esempio n. 5
0
BOOL CDIB::FillDIBColorTable(UINT nNumColors, RGBQUAD *pRGB)
{
    if (!pRGB || !nNumColors || !m_iColorTableSize || nNumColors > 256)
        return FALSE;

    // get the number of colors to return per BITMAPINFOHEADER docs
    UINT nColors;
    LPBITMAPINFOHEADER pBmih = GetBitmapInfoHeader();
    if (pBmih->biClrUsed)
        nColors = pBmih->biClrUsed;
    else
        nColors = 1 << (pBmih->biBitCount*pBmih->biPlanes);

    // Initialize the loop variables
    nColors = min(nNumColors, nColors);

    LPRGBQUAD pColorTable = GetColorTable();
    for (UINT iColor = 0; iColor < nColors; iColor++)
    {
        pColorTable[iColor].rgbReserved = 0;
        pColorTable[iColor].rgbBlue     = pRGB[iColor].rgbBlue;
        pColorTable[iColor].rgbRed      = pRGB[iColor].rgbRed;
        pColorTable[iColor].rgbGreen    = pRGB[iColor].rgbGreen;
    }

    return TRUE;
}
Esempio n. 6
0
int
__glXDispSwap_GetColorTableSGI(__GLXclientState * cl, GLbyte * pc)
{
    const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
    ClientPtr client = cl->client;

    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
    return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
}
Esempio n. 7
0
int
__glXDispSwap_GetColorTable(__GLXclientState * cl, GLbyte * pc)
{
    const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
    ClientPtr client = cl->client;

    REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
    return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
}
Esempio n. 8
0
static int assembleColmapStr(const int num, const int intType, int &samples,
                             std::string &ret)
{
  GmshColorTable * ct = GetColorTable(num); // i
  ret.assign("\\pgfplotsset{\ncolormap={gmshcolormap}{%% note: "
             "Only needed once if colorbars do not change\n");

  samples = (int) opt_view_nb_iso(num, GMSH_GET, 0);
  double step = 0.;
  switch (intType){
    case 2: samples=64; break; // continuous is approximated by 64 samples
    case 3: break; // filled (sampled colorbar)
    case 1: break; // iso lines
    case 4:  // numericals
    default:
      return 1;
  }
  step = (double) (1.*ct->size)/(samples-1.);
  int r, g, b, a;
  unsigned int idx;
  char tmp[265];
  for (unsigned int j=0; j < (unsigned int) samples-1; j++ /*j+=4*/) {
    idx = (unsigned int)j*step;
    //printf("j=%d, idx=%d step=%f\n", j, idx, step);
    r = CTX::instance()->unpackRed(ct->table[idx]);
    g = CTX::instance()->unpackGreen(ct->table[idx]);
    b = CTX::instance()->unpackBlue(ct->table[idx]);
    a = CTX::instance()->unpackAlpha(ct->table[idx]);
    if (a != 255)
      Msg::Warning("PGF export does not handle transparent colormaps");

    sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b);
    ret.append(tmp);

    if (intType != 2) // sampled
      // reinsert, because then the end color is interpreted correctly
      // for shader=flat mean
      ret.append(tmp);
  }
  //endpoint
  r = CTX::instance()->unpackRed(ct->table[ct->size-1]);
  g = CTX::instance()->unpackGreen(ct->table[ct->size-1]);
  b = CTX::instance()->unpackBlue(ct->table[ct->size-1]);
  sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b);
  ret.append(tmp);
  if (intType != 2) // sampled
    // reinsert, because then the end color is interpreted correctly
    // for shader=flat mean
    ret.append(tmp);

  ret.append("}\n}%%\n");

  return 0;
}
Esempio n. 9
0
void RenderPolyPlane::SetLightLevel(PolyRenderThread *thread, PolyDrawArgs &args, const PolyTransferHeights &fakeflat, bool ceiling)
{
	bool foggy = level.fadeto || fakeflat.FrontSector->Colormap.FadeColor || (level.flags & LEVEL_HASFADETABLE);

	int lightlevel = ceiling ? fakeflat.CeilingLightLevel : fakeflat.FloorLightLevel;
	int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
	lightlevel = clamp(lightlevel + actualextralight, 0, 255);

	PolyCameraLight *cameraLight = PolyCameraLight::Instance();
	FDynamicColormap *basecolormap = GetColorTable(fakeflat.FrontSector->Colormap, fakeflat.FrontSector->SpecialColors[ceiling ? sector_t::ceiling : sector_t::floor]);
	if (cameraLight->FixedLightLevel() < 0 && fakeflat.FrontSector->e && fakeflat.FrontSector->e->XFloor.lightlist.Size())
	{
		lightlist_t *light = P_GetPlaneLight(fakeflat.FrontSector, ceiling ? &fakeflat.FrontSector->ceilingplane : &fakeflat.FrontSector->floorplane, false);
		basecolormap = GetColorTable(light->extra_colormap, fakeflat.FrontSector->SpecialColors[ceiling ? sector_t::ceiling : sector_t::floor]);
		if (light->p_lightlevel != &fakeflat.FrontSector->lightlevel) // If this is the real ceiling, don't discard plane lighting R_FakeFlat() accounted for.
		{
			lightlevel = *light->p_lightlevel;
		}
	}

	args.SetLight(basecolormap, lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
}
////////////////////////////////////////////////////////////////
// Draw DIB on caller's DC. Does stretching from source to destination
// rectangles. Generally, you can let the following default to zero/NULL:
//
//		bUseDrawDib = whether to use use DrawDib, default TRUE
//		pPal	      = palette, default=NULL, (use DIB's palette)
//		bForeground = realize in foreground (default FALSE)
//
// If you are handling palette messages, you should use bForeground=FALSE,
// since you will realize the foreground palette in WM_QUERYNEWPALETTE.
//
BOOL CDib::Draw(CDC& dc, const CRect* rcDst, const CRect* rcSrc,
	BOOL bUseDrawDib, CPalette* pPal, BOOL bForeground)
{
	if (!m_hObject)
		return FALSE;

	// Select, realize palette
	if (pPal==NULL)				// no palette specified:
		pPal = GetPalette();		// use default
	CPalette* pOldPal = dc.SelectPalette(pPal, !bForeground);
	dc.RealizePalette();

	BOOL bRet = FALSE;
	if (bUseDrawDib) {
		// Compute rectangles where NULL specified
		//
		CRect rc(0,0,-1,-1);	// default for DrawDibDraw
		if (!rcSrc)
			rcSrc = &rc;
		if (!rcDst)
			rcDst=rcSrc;
		if (!m_hdd)
			VERIFY(m_hdd = DrawDibOpen());

		// Get BITMAPINFOHEADER/color table. I copy into stack object each time.
		// This doesn't seem to slow things down visibly.
		//
		DIBSECTION ds;
		VERIFY(GetObject(sizeof(ds), &ds)==sizeof(ds));
		char buf[sizeof(BITMAPINFOHEADER) + MAXPALCOLORS*sizeof(RGBQUAD)];
		BITMAPINFOHEADER& bmih = *(BITMAPINFOHEADER*)buf;
		RGBQUAD* colors = (RGBQUAD*)(&bmih+1);
		memcpy(&bmih, &ds.dsBmih, sizeof(bmih));
		GetColorTable(colors, MAXPALCOLORS);

		// Let DrawDib do the work!
		bRet = DrawDibDraw(m_hdd, dc,
			rcDst->left, rcDst->top, rcDst->Width(), rcDst->Height(),
			&bmih,			// ptr to BITMAPINFOHEADER + colors
			m_bm.bmBits,	// bits in memory
			rcSrc->left, rcSrc->top, rcSrc->Width(), rcSrc->Height(),
			bForeground ? 0 : DDF_BACKGROUNDPAL);

	} else {
		// use normal draw function
		bRet = PLDrawBitmap(dc, this, rcDst, rcSrc);
	}
	if (pOldPal)
		dc.SelectPalette(pOldPal, TRUE);
	return bRet;
}
Esempio n. 11
0
BOOL CDIB::SetColorTable(UINT nNumColors, RGBQUAD *pColors)
{
    if (!m_hBitmap ||!pColors || !nNumColors || m_iColorTableSize == 0 || nNumColors > 256)
        return FALSE;

    LPRGBQUAD pColorTable = GetColorTable();
    ASSERT(pColorTable);

    int nCount = min(m_iColorTableSize, nNumColors);
    ::memset(pColorTable, 0, m_iColorTableSize*sizeof(RGBQUAD));
    ::memcpy(pColorTable, pColors, nCount*sizeof(RGBQUAD));

    return TRUE;
}
Esempio n. 12
0
/////////////////////////////////////////////////////////////////////////////
//
// Create the palette.  Use halftone palette for hi-color bitmaps.
//
/////////////////////////////////////////////////////////////////////////////
zBOOL
ZDib::CreatePalette( CPalette& pal )
{
   // Should not already have palette
   ASSERT( pal.m_hObject == 0 );

   zBOOL bRC = FALSE;
   RGBQUAD *colors = new RGBQUAD[ MAXPALCOLORS ];
   UINT nColors = GetColorTable( colors, MAXPALCOLORS );
   if ( nColors > 0 )
   {
      // Allocate memory for logical palette.
      int nLth = sizeof( LOGPALETTE ) + sizeof( PALETTEENTRY ) * nColors;
      LOGPALETTE *pLogPal = (LOGPALETTE *) new char[ nLth ];
      if ( pLogPal == 0 )
         return( 0 );

      // Set version and number of palette entries.
      pLogPal->palVersion = PALVERSION;
      pLogPal->palNumEntries = nColors;

      // Copy color entries.
      for ( UINT k = 0; k < nColors; k++ )
      {
         pLogPal->palPalEntry[ k ].peRed   = colors[ k ].rgbRed;
         pLogPal->palPalEntry[ k ].peGreen = colors[ k ].rgbGreen;
         pLogPal->palPalEntry[ k ].peBlue  = colors[ k ].rgbBlue;
         pLogPal->palPalEntry[ k ].peFlags = 0;
      }

      // Create the palette and destroy LOGPAL.
      bRC = pal.CreatePalette( pLogPal );
      delete [] (zPCHAR) pLogPal;
   }
   else
   {
      CWindowDC dcScreen( 0 );
      bRC = pal.CreateHalftonePalette( &dcScreen );
   }

   delete [] colors;
   return( bRC );
}
BOOL CDib::GetPalette(CPalette& palette)const
{
	if( (HPALETTE)palette)
		palette.DeleteObject();

	/*HDC hDC = GetDC();
	CPalette* pPalette = CPalette::FromHandle( (HPALETTE)GetCurrentObject(hDC, OBJ_PAL));
	int iColors = 0;
	if (!pPalette->GetObject(sizeof(int), &iColors)) 
	{
		TRACE("Failed to get num palette colors");
		return FALSE;
	}
	ReleaseDC();
	*/

	int iColors = GetMaxColorTableEntries();
    if(iColors==0)
		return FALSE;

	RGBQUAD quad[256] = {0};
    //LPRGBQUAD pctThis = (LPRGBQUAD) &quad;
	GetColorTable(0, iColors, &quad[0]);

	LPLOGPALETTE pLogPal = (LPLOGPALETTE) new char[2 * sizeof(WORD) +
		iColors * sizeof(PALETTEENTRY)];
	pLogPal->palVersion = 0x300;
	pLogPal->palNumEntries = iColors;
	
	for (int i = 0; i < iColors; i++) 
    {
        pLogPal->palPalEntry[i].peRed = quad[i].rgbRed;
        pLogPal->palPalEntry[i].peGreen = quad[i].rgbGreen;
        pLogPal->palPalEntry[i].peBlue = quad[i].rgbBlue;
    }

	palette.CreatePalette(pLogPal);
	delete pLogPal;

	return true;
}
Esempio n. 14
0
int CImageEx::ImageType()
{
	RGBQUAD ColorTab[256];  
	int     k;  

	if (IsNull()) return(0);  

	switch(GetBPP())  
	{  
	case 1:  k=0;   break;   
	case 4:  k=1;   break;   
	case 8:  k=3;   break;   
	default: k=4;   break;   
	}  

	if (k==3)                    
	{  
		GetColorTable(0,256,ColorTab);  
		k=PaletteType(ColorTab);  
	}  
	return(k);  
}
Esempio n. 15
0
void PolyModelRenderer::DrawElements(int numIndices, size_t offset)
{
	const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;

	bool foggy = false;
	int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
	sector_t *sector = ModelActor->Sector;

	bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
	int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;

	PolyDrawArgs args;
	args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
	args.SetLights(Lights, NumLights);
	args.SetStencilTestValue(StencilValue);
	args.SetClipPlane(0, PolyClipPlane());
	args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite);
	args.SetDepthTest(true);
	args.SetWriteDepth(true);
	args.SetWriteStencil(false);
	PolyTriangleDrawer::DrawElements(Thread->DrawQueue, args, VertexBuffer, IndexBuffer + offset / sizeof(unsigned int), numIndices);
}
//////////////////
// Create the palette. Use halftone palette for hi-color bitmaps.
//
BOOL CDib::CreatePalette(CPalette& pal)
{ 
	// should not already have palette
	ASSERT(pal.m_hObject==NULL);

	BOOL bRet = FALSE;
	RGBQUAD* colors = new RGBQUAD[MAXPALCOLORS];
	UINT nColors = GetColorTable(colors, MAXPALCOLORS);
	if (nColors > 0) {
		// Allocate memory for logical palette 
		int len = sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nColors;
		LOGPALETTE* pLogPal = (LOGPALETTE*)new char[len];
		if (!pLogPal)
			return NULL;

		// set version and number of palette entries
		pLogPal->palVersion = PALVERSION;
		pLogPal->palNumEntries = nColors;

		// copy color entries 
		for (UINT i = 0; i < nColors; i++) {
			pLogPal->palPalEntry[i].peRed   = colors[i].rgbRed;
			pLogPal->palPalEntry[i].peGreen = colors[i].rgbGreen;
			pLogPal->palPalEntry[i].peBlue  = colors[i].rgbBlue;
			pLogPal->palPalEntry[i].peFlags = 0;
		}

		// create the palette and destroy LOGPAL
		bRet = pal.CreatePalette(pLogPal);
		delete [] (char*)pLogPal;
	} else {
		CWindowDC dcScreen(NULL);
		bRet = pal.CreateHalftonePalette(&dcScreen);
	}
	delete colors;
	return bRet;
}
Esempio n. 17
0
BOOL KDIBSection::CreateDIBSection(HDC hDC, CONST BITMAPINFO * pBMI, UINT iUsage, HANDLE hSection, DWORD dwOffset)
{
	PVOID pBits = NULL;
	
	HBITMAP hBmp = ::CreateDIBSection(hDC, pBMI, iUsage, & pBits, hSection, dwOffset);

	int typ = GetObjectType(hBmp);
	int size = GetObject(hBmp, 0, NULL);

	if ( hBmp )
	{
		ReleaseDDB();	// free the previous object
		ReleaseDIB();	
		
		m_hBitmap = hBmp;	// Use DDB handle to store DIB Section Handle

//		MEMORY_BASIC_INFORMATION mbi;
//		VirtualQuery(pBits, & mbi, sizeof(mbi));

		int nColor = GetDIBColorCount(pBMI->bmiHeader);
		int nSize  = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * nColor;
		
		BITMAPINFO * pDIB = (BITMAPINFO *) new BYTE[nSize];

		if ( pDIB==NULL )
			return FALSE;

		memcpy(pDIB, pBMI, nSize);	// copy header and color table

		AttachDIB(pDIB, (PBYTE) pBits, DIB_BMI_NEEDFREE);
		GetColorTable();
		return TRUE;
	}
	else
		return FALSE;
}
Esempio n. 18
0
void Render3DFloorPlane::Render(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane)
{
	FTextureID picnum = ceiling ? *fakeFloor->bottom.texture : *fakeFloor->top.texture;
	FTexture *tex = TexMan(picnum);
	if (tex->UseType == FTexture::TEX_Null)
		return;

	PolyCameraLight *cameraLight = PolyCameraLight::Instance();

	int lightlevel = 255;
	bool foggy = false;
	if (cameraLight->FixedLightLevel() < 0 && sub->sector->e->XFloor.lightlist.Size())
	{
		lightlist_t *light = P_GetPlaneLight(sub->sector, &sub->sector->ceilingplane, false);
		//basecolormap = light->extra_colormap;
		lightlevel = *light->p_lightlevel;
	}

	int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
	lightlevel = clamp(lightlevel + actualextralight, 0, 255);

	PolyPlaneUVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex);

	TriVertex *vertices = thread->FrameMemory->AllocMemory<TriVertex>(sub->numlines);
	if (ceiling)
	{
		for (uint32_t i = 0; i < sub->numlines; i++)
		{
			seg_t *line = &sub->firstline[i];
			vertices[sub->numlines - 1 - i] = xform.GetVertex(line->v1, fakeFloor->bottom.plane->ZatPoint(line->v1));
		}
	}
	else
	{
		for (uint32_t i = 0; i < sub->numlines; i++)
		{
			seg_t *line = &sub->firstline[i];
			vertices[i] = xform.GetVertex(line->v1, fakeFloor->top.plane->ZatPoint(line->v1));
		}
	}

	PolyDrawArgs args;
	args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
	args.SetTransform(&worldToClip);
	if (!Masked)
	{
		args.SetStyle(TriBlendMode::TextureOpaque);
	}
	else
	{
		double srcalpha = MIN(Alpha, 1.0);
		double destalpha = Additive ? 1.0 : 1.0 - srcalpha;
		args.SetStyle(TriBlendMode::TextureAdd, srcalpha, destalpha);
		args.SetDepthTest(true);
		args.SetWriteDepth(true);
		args.SetWriteStencil(false);
	}
	args.SetFaceCullCCW(true);
	args.SetStencilTestValue(stencilValue);
	args.SetWriteStencil(true, stencilValue + 1);
	args.SetTexture(tex);
	args.SetClipPlane(0, clipPlane);
	args.DrawArray(thread, vertices, sub->numlines, PolyDrawMode::TriangleFan);
}
Esempio n. 19
0
void RenderPolySprite::Render(PolyRenderThread *thread, AActor *thing, subsector_t *sub, uint32_t stencilValue, float t1, float t2)
{
	if (r_modelscene)
	{
		const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
		int spritenum = thing->sprite;
		bool isPicnumOverride = thing->picnum.isValid();
		FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED));
		if (modelframe && (thing->Pos() - viewpoint.Pos).LengthSquared() < model_distance_cull)
		{
			DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
			PolyRenderModel(thread, PolyRenderer::Instance()->Scene.CurrentViewpoint->WorldToClip, stencilValue, (float)pos.X, (float)pos.Y, (float)pos.Z, modelframe, thing);
			return;
		}
	}

	DVector2 line[2];
	if (!GetLine(thing, line[0], line[1]))
		return;
	
	const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
	DVector3 thingpos = thing->InterpolatedPosition(viewpoint.TicFrac);

	double posZ = thingpos.Z;

	uint32_t spritetype = (thing->renderflags & RF_SPRITETYPEMASK);

	if (spritetype == RF_FACESPRITE)
		posZ -= thing->Floorclip;

	if (thing->flags2 & MF2_FLOATBOB)
		posZ += thing->GetBobOffset(viewpoint.TicFrac);

	bool flipTextureX = false;
	FTexture *tex = GetSpriteTexture(thing, flipTextureX);
	if (tex == nullptr || tex->UseType == ETextureType::Null)
		return;

	double thingyscalemul = thing->Scale.Y / tex->Scale.Y;
	double spriteHeight = thingyscalemul * tex->GetHeight();

	posZ -= (tex->GetHeight() - tex->GetTopOffsetPo()) * thingyscalemul;
	posZ = PerformSpriteClipAdjustment(thing, thingpos, spriteHeight, posZ);

	//double depth = 1.0;
	//visstyle_t visstyle = GetSpriteVisStyle(thing, depth);
	// Rumor has it that AlterWeaponSprite needs to be called with visstyle passed in somewhere around here..
	//R_SetColorMapLight(visstyle.BaseColormap, 0, visstyle.ColormapNum << FRACBITS);

	TriVertex *vertices = thread->FrameMemory->AllocMemory<TriVertex>(4);

	bool foggy = false;
	int actualextralight = foggy ? 0 : viewpoint.extralight << 4;

	std::pair<float, float> offsets[4] =
	{
		{ t1,  1.0f },
		{ t2,  1.0f },
		{ t2,  0.0f },
		{ t1,  0.0f },
	};

	DVector2 points[2] =
	{
		line[0] * (1.0 - t1) + line[1] * t1,
		line[0] * (1.0 - t2) + line[1] * t2
	};

	for (int i = 0; i < 4; i++)
	{
		auto &p = (i == 0 || i == 3) ? points[0] : points[1];

		vertices[i].x = (float)p.X;
		vertices[i].y = (float)p.Y;
		vertices[i].z = (float)(posZ + spriteHeight * offsets[i].second);
		vertices[i].w = 1.0f;
		vertices[i].u = (float)(offsets[i].first * tex->Scale.X);
		vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
		if (flipTextureX)
			vertices[i].u = 1.0f - vertices[i].u;
	}

	bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
	int lightlevel = fullbrightSprite ? 255 : thing->Sector->lightlevel + actualextralight;

	PolyDrawArgs args;
	SetDynlight(thing, args);
	args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
	args.SetStencilTestValue(stencilValue);
	if ((thing->renderflags & RF_ZDOOMTRANS) && r_UseVanillaTransparency)
		args.SetStyle(LegacyRenderStyles[STYLE_Normal], 1.0f, thing->fillcolor, thing->Translation, tex, fullbrightSprite);
	else
		args.SetStyle(thing->RenderStyle, thing->Alpha, thing->fillcolor, thing->Translation, tex, fullbrightSprite);
	args.SetDepthTest(true);
	args.SetWriteDepth(false);
	args.SetWriteStencil(false);
	PolyTriangleDrawer::DrawArray(thread->DrawQueue, args, vertices, 4, PolyDrawMode::TriangleFan);
}
Esempio n. 20
0
void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue)
{
	if (RenderPolySprite::IsThingCulled(thing))
		return;

	const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
	DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
	pos.Z += thing->GetBobOffset(viewpoint.TicFrac);

	bool flipTextureX = false;
	FTexture *tex = RenderPolySprite::GetSpriteTexture(thing, flipTextureX);
	if (tex == nullptr || tex->UseType == FTexture::TEX_Null)
		return;

	DVector2 spriteScale = thing->Scale;
	double thingxscalemul = spriteScale.X / tex->Scale.X;
	double thingyscalemul = spriteScale.Y / tex->Scale.Y;
	double spriteHeight = thingyscalemul * tex->GetHeight();

	DAngle ang = thing->Angles.Yaw + 90;
	double angcos = ang.Cos();
	double angsin = ang.Sin();

	// Determine left and right edges of sprite. The sprite's angle is its normal,
	// so the edges are 90 degrees each side of it.
	double x2 = tex->GetScaledWidth() * spriteScale.X;
	double x1 = tex->GetScaledLeftOffset() * spriteScale.X;
	DVector2 left, right;
	left.X = pos.X - x1 * angcos;
	left.Y = pos.Y - x1 * angsin;
	right.X = left.X + x2 * angcos;
	right.Y = left.Y + x2 * angsin;

	//int scaled_to = tex->GetScaledTopOffset();
	//int scaled_bo = scaled_to - tex->GetScaledHeight();
	//gzt = pos.Z + scale.Y * scaled_to;
	//gzb = pos.Z + scale.Y * scaled_bo;

	DVector2 points[2] = { left, right };

	TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(4);

	bool foggy = false;
	int actualextralight = foggy ? 0 : viewpoint.extralight << 4;

	std::pair<float, float> offsets[4] =
	{
		{ 0.0f,  1.0f },
		{ 1.0f,  1.0f },
		{ 1.0f,  0.0f },
		{ 0.0f,  0.0f },
	};

	for (int i = 0; i < 4; i++)
	{
		auto &p = (i == 0 || i == 3) ? points[0] : points[1];

		vertices[i].x = (float)p.X;
		vertices[i].y = (float)p.Y;
		vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second);
		vertices[i].w = 1.0f;
		vertices[i].u = (float)(offsets[i].first * tex->Scale.X);
		vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
		if (flipTextureX)
			vertices[i].u = 1.0f - vertices[i].u;
	}

	bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
	int lightlevel = fullbrightSprite ? 255 : thing->Sector->lightlevel + actualextralight;

	PolyDrawArgs args;
	args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), fullbrightSprite);
	args.SetTransform(&worldToClip);
	args.SetFaceCullCCW(true);
	args.SetStencilTestValue(stencilValue);
	args.SetTexture(tex);
	args.SetClipPlane(clipPlane);
	args.SetSubsectorDepthTest(true);
	args.SetWriteSubsectorDepth(false);
	args.SetWriteStencil(false);
	args.SetStyle(TriBlendMode::TextureMasked);
	args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
}
bool OsmAnd::HeightmapTileProvider_P::obtainData(
    const TileId tileId,
    const ZoomLevel zoom,
    std::shared_ptr<MapTiledData>& outTiledData,
    const IQueryController* const queryController)
{
    // Obtain raw data from DB
    QByteArray data;
    bool ok = _tileDb.obtainTileData(tileId, zoom, data);
    if (!ok || data.length() == 0)
    {
        // There was no data at all, to avoid further requests, mark this tile as empty
        outTiledData.reset();
        return true;
    }

    // We have the data, use GDAL to decode this GeoTIFF
    const auto tileSize = getTileSize();
    bool success = false;
    QString vmemFilename;
    vmemFilename.sprintf("/vsimem/heightmapTile@%p", data.data());
    VSIFileFromMemBuffer(qPrintable(vmemFilename), reinterpret_cast<GByte*>(data.data()), data.length(), FALSE);
    auto dataset = reinterpret_cast<GDALDataset*>(GDALOpen(qPrintable(vmemFilename), GA_ReadOnly));
    if (dataset != nullptr)
    {
        bool bad = false;
        bad = bad || dataset->GetRasterCount() != 1;
        bad = bad || dataset->GetRasterXSize() != tileSize;
        bad = bad || dataset->GetRasterYSize() != tileSize;
        if (bad)
        {
            if (dataset->GetRasterCount() != 1)
                LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %d bands instead of 1", tileId.x, tileId.y, zoom, dataset->GetRasterCount());
            if (dataset->GetRasterXSize() != tileSize || dataset->GetRasterYSize() != tileSize)
            {
                LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %dx%x size instead of %d", tileId.x, tileId.y, zoom,
                    dataset->GetRasterXSize(), dataset->GetRasterYSize(), tileSize);
            }
        }
        else
        {
            auto band = dataset->GetRasterBand(1);

            bad = bad || band->GetColorTable() != nullptr;
            bad = bad || band->GetRasterDataType() != GDT_Int16;

            if (bad)
            {
                if (band->GetColorTable() != nullptr)
                    LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has color table", tileId.x, tileId.y, zoom);
                if (band->GetRasterDataType() != GDT_Int16)
                    LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %s data type in band 1", tileId.x, tileId.y, zoom, GDALGetDataTypeName(band->GetRasterDataType()));
            }
            else
            {
                auto buffer = new float[tileSize*tileSize];

                auto res = dataset->RasterIO(GF_Read, 0, 0, tileSize, tileSize, buffer, tileSize, tileSize, GDT_Float32, 1, nullptr, 0, 0, 0);
                if (res != CE_None)
                {
                    delete[] buffer;
                    LogPrintf(LogSeverityLevel::Error, "Failed to decode height tile %dx%d@%d: %s", tileId.x, tileId.y, zoom, CPLGetLastErrorMsg());
                }
                else
                {
                    outTiledData.reset(new ElevationDataTile(buffer, sizeof(float)*tileSize, tileSize, tileId, zoom));
                    success = true;
                }
            }
        }

        GDALClose(dataset);
    }
    VSIUnlink(qPrintable(vmemFilename));

    return success;
}
HGLOBAL CDib::CreateGlobalDIB()const
{
	int nColorTableEntries = this->GetColorTableEntries();
	DWORD dwLenHead = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * nColorTableEntries;
	int dwSizeImage = ((GetWidth() * GetBPP()+31) & ~31) /8 * GetHeight(); 
    
    HGLOBAL hCopy = ::GlobalAlloc(GHND, dwLenHead + dwSizeImage); 
    LPBYTE pData = (LPBYTE)::GlobalLock(hCopy); 

    BITMAP bmp; 
    PBITMAPINFO pbmi = (PBITMAPINFO )pData; 
    WORD    cClrBits; 

    // Retrieve the bitmap color format, width, and height. 
//    if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)) 
  //      return false;
	CBitmap* pBitmap = CBitmap::FromHandle( (HBITMAP)(*this));
	pBitmap->GetBitmap(&bmp);

    // Convert the color format to a count of bits. 
    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); 
    if (cClrBits == 1) 
        cClrBits = 1; 
    else if (cClrBits <= 4) 
        cClrBits = 4; 
    else if (cClrBits <= 8) 
        cClrBits = 8; 
    else if (cClrBits <= 16) 
        cClrBits = 16; 
    else if (cClrBits <= 24) 
        cClrBits = 24; 
    else cClrBits = 32; 

	ASSERT( cClrBits == GetBPP() );
    // Allocate memory for the BITMAPINFO structure. (This structure 
    // contains a BITMAPINFOHEADER structure and an array of RGBQUAD 
    // data structures.) 

     //if (cClrBits != 24) 
	/*if (cClrBits != 24) 
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR, 
                    sizeof(BITMAPINFOHEADER) + 
                    sizeof(RGBQUAD) * (1<< cClrBits)); 

     // There is no RGBQUAD array for the 24-bit-per-pixel format. 

     else 
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR, 
                    sizeof(BITMAPINFOHEADER)); 
*/
    // Initialize the fields in the BITMAPINFO structure. 

    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
    pbmi->bmiHeader.biWidth = bmp.bmWidth; 
    pbmi->bmiHeader.biHeight = bmp.bmHeight; 
    pbmi->bmiHeader.biPlanes = bmp.bmPlanes; 
    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel; 
    if (cClrBits < 24) 
        pbmi->bmiHeader.biClrUsed = (1<<cClrBits); 

    // If the bitmap is not compressed, set the BI_RGB flag. 
    pbmi->bmiHeader.biCompression = BI_RGB; 

    // Compute the number of bytes in the array of color 
    // indices and store the result in biSizeImage. 
    // For Windows NT, the width must be DWORD aligned unless 
    // the bitmap is RLE compressed. This example shows this. 
    // For Windows 95/98/Me, the width must be WORD aligned unless the 
    // bitmap is RLE compressed.
    pbmi->bmiHeader.biSizeImage = dwSizeImage;//((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
                                  //* pbmi->bmiHeader.biHeight; 
    // Set biClrImportant to 0, indicating that all of the 
    // device colors are important. 
     pbmi->bmiHeader.biClrImportant = 0; 
     
	 if( IsIndexed() )
	 {
		 GetColorTable(0, nColorTableEntries, pbmi->bmiColors);
	 }

	 pData += dwLenHead;
	 if( GetPitch() > 0 )
		memcpy( pData, GetPixelAddress(0,0), dwSizeImage);
	 else memcpy( pData, GetPixelAddress(0,GetHeight()-1), dwSizeImage);
     ::GlobalUnlock(hCopy); 


	 return hCopy;
 } 
Esempio n. 23
0
CPLErr GDALPamRasterBand::CloneInfo( GDALRasterBand *poSrcBand, 
                                     int nCloneFlags )

{
    int bOnlyIfMissing = nCloneFlags & GCIF_ONLY_IF_MISSING;
    int bSuccess;
    int nSavedMOFlags = GetMOFlags();

    PamInitialize();

/* -------------------------------------------------------------------- */
/*      Supress NotImplemented error messages - mainly needed if PAM    */
/*      disabled.                                                       */
/* -------------------------------------------------------------------- */
    SetMOFlags( nSavedMOFlags | GMO_IGNORE_UNIMPLEMENTED );

/* -------------------------------------------------------------------- */
/*      Metadata                                                        */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_BAND_METADATA )
    {
        if( poSrcBand->GetMetadata() != NULL )
        {
            if( !bOnlyIfMissing 
             || CSLCount(GetMetadata()) != CSLCount(poSrcBand->GetMetadata()) )
            {
                SetMetadata( poSrcBand->GetMetadata() );
            }
        }
    }

/* -------------------------------------------------------------------- */
/*      Band description.                                               */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_BAND_DESCRIPTION )
    {
        if( strlen(poSrcBand->GetDescription()) > 0 )
        {
            if( !bOnlyIfMissing || strlen(GetDescription()) == 0 )
                GDALPamRasterBand::SetDescription( poSrcBand->GetDescription());
        }
    }

/* -------------------------------------------------------------------- */
/*      NODATA                                                          */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_NODATA )
    {
        double dfNoData = poSrcBand->GetNoDataValue( &bSuccess );
        
        if( bSuccess )
        {
            if( !bOnlyIfMissing 
                || GetNoDataValue( &bSuccess ) != dfNoData 
                || !bSuccess )
                GDALPamRasterBand::SetNoDataValue( dfNoData );
        }
    }

/* -------------------------------------------------------------------- */
/*      Offset/scale                                                    */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_SCALEOFFSET )
    {
        double dfOffset = poSrcBand->GetOffset( &bSuccess );
        
        if( bSuccess )
        {
            if( !bOnlyIfMissing || GetOffset() != dfOffset )
                GDALPamRasterBand::SetOffset( dfOffset );
        }

        double dfScale = poSrcBand->GetScale( &bSuccess );
        
        if( bSuccess )
        {
            if( !bOnlyIfMissing || GetScale() != dfScale )
                GDALPamRasterBand::SetScale( dfScale );
        }
    }

/* -------------------------------------------------------------------- */
/*      Unittype.                                                       */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_UNITTYPE )
    {
        if( strlen(poSrcBand->GetUnitType()) > 0 )
        {
            if( !bOnlyIfMissing 
                || !EQUAL(GetUnitType(),poSrcBand->GetUnitType()) )
            {
                GDALPamRasterBand::SetUnitType( poSrcBand->GetUnitType() );
            }
        }
    }

/* -------------------------------------------------------------------- */
/*      ColorInterp                                                     */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_COLORINTERP )
    {
        if( poSrcBand->GetColorInterpretation() != GCI_Undefined )
        {
            if( !bOnlyIfMissing
                || poSrcBand->GetColorInterpretation() 
                != GetColorInterpretation() )
                GDALPamRasterBand::SetColorInterpretation( 
                    poSrcBand->GetColorInterpretation() );
        }
    }

/* -------------------------------------------------------------------- */
/*      color table.                                                    */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_COLORTABLE )
    {
        if( poSrcBand->GetColorTable() != NULL )
        {
            if( !bOnlyIfMissing || GetColorTable() == NULL )
            {
                GDALPamRasterBand::SetColorTable( 
                    poSrcBand->GetColorTable() );
            }
        }
    }

/* -------------------------------------------------------------------- */
/*      Raster Attribute Table.                                         */
/* -------------------------------------------------------------------- */
    if( nCloneFlags & GCIF_RAT )
    {
        const GDALRasterAttributeTable *poRAT = poSrcBand->GetDefaultRAT();

        if( poRAT != NULL )
        {
            if( !bOnlyIfMissing || GetDefaultRAT() == NULL )
            {
                GDALPamRasterBand::SetDefaultRAT( poRAT );
            }
        }
    }

/* -------------------------------------------------------------------- */
/*      Restore MO flags.                                               */
/* -------------------------------------------------------------------- */
    SetMOFlags( nSavedMOFlags );

    return CE_None;
}