Exemplo n.º 1
0
static Errcode write_colormap(Tiff_file *tf, long *mapoffset)
/*****************************************************************************
 * write the PJ color palette as a TIFF color map, return oset of map in file.
 *
 * Strangeness dept:
 *	The tiff 5.0 spec says that values in the color map range from 0-65535 to
 *	indicate relative intensity of the color.  That seems cut-and-dried to me:
 *	since our values range from 0-255, we need to shift our values up by 8
 *	bits to scale them to tiff's range.  However, it appears that most tiff
 *	readers don't downscale the values when they read the color map and load
 *	the VGA palettes.  In fact, most readers wig out totally if any of the
 *	values are > 255.  So <major sigh> we just write the values out in the
 *	0-255 range, and hope for tiff readers that incorporate the sort of
 *	smarts our read side has in coping with either 255 level or 64k level
 *	color values.
 *
 *	(An aside:	I attempted to fix this by replicating the color byte into
 *	both words of the output value; color 0x23 would be written as 0x2323,
 *	and so on.	Seemed like a fine idea:  a reader would either downscale,
 *	getting 0x23, or would ignore the upper byte, getting 0x23.  Didn't work.)
 *
 * 09/24/92 -
 *	Well, the TIFF 6.0 spec is out now, and it's much clearer on this issue:
 *	the values have to be scaled into a 0-64k range.  ("Black is represented
 *	by 0,0,0; white by 65535,65535,65535.")  For us, scaling is easy, we just
 *	shift our 0-255 range value up 8 bits when we store it.  On the read side,
 *	we still handle both types of color palette data, since it's so easy to
 *	do, and there're definitely programs out there writing unscaled palettes.
 ****************************************************************************/
{
	USHORT	curcolor;
	USHORT	colormap[3][256];
	UBYTE	(*ctab)[3] = (void *)tf->screen_rcel->cmap->ctab;
	int 	plane;
	int 	index;

	for (plane = 0; plane < 3; ++plane)
		for (index = 0; index < 256; ++index)
			{
			curcolor = ctab[index][plane];
			colormap[plane][index] = curcolor << 8;
			}

	if (0 >= (*mapoffset = ftell(tf->file)))
		return pj_errno_errcode();

	if (1 != fwrite(colormap, sizeof(colormap), 1, tf->file))
		return Err_truncated;

	return Success;
}
Exemplo n.º 2
0
// emit one block xor-ed between new and old file
void EmitXor_t(SLONG slOffsetOld, SLONG slSizeOld, SLONG slOffsetNew, SLONG slSizeNew)
{
  // xor it
  SLONG slSizeXor = Min(slSizeOld, slSizeNew);
  UBYTE *pub0 = _pubOld+slOffsetOld;
  UBYTE *pub1 = _pubNew+slOffsetNew;
  for (INDEX i=0; i<slSizeXor; i++) {
    *pub1++ ^= *pub0++;
  }

  // emit it
  (*_pstrmOut)<<UBYTE(DIFF_XOR);
  (*_pstrmOut)<<slOffsetOld;
  (*_pstrmOut)<<slSizeOld;
  (*_pstrmOut)<<slSizeNew;
  (*_pstrmOut).Write_t(_pubNew+slOffsetNew, slSizeNew);
}
void CDlgCreateSpecularTexture::CreateTexture( CTFileName fnTexture, FLOAT fExp)
{
  CImageInfo II;
  CTFileStream fsFile;
  CTextureData TD;

  INDEX iSelectedSize = m_comboSizeInPixels.GetCurSel();
  ASSERT( iSelectedSize != CB_ERR);
  PIX pixSize = 1UL<<iSelectedSize;
  PIX pixSizeI = pixSize;
  PIX pixSizeJ = pixSize;
  UBYTE *pubImage = (UBYTE *)AllocMemory(pixSize*pixSize*3);
  II.Attach(pubImage, pixSize, pixSize, 24);
  for (PIX pixI=0; pixI<pixSizeI; pixI++) {
    for (PIX pixJ=0; pixJ<pixSizeJ; pixJ++) {
      FLOAT fS = pixI*2.0f/pixSizeI-1;
      FLOAT fT = pixJ*2.0f/pixSizeJ-1;
      FLOAT fZ = Sqrt(1-2*fS*fS-2*fT*fT);
      fZ = Clamp(fZ, 0.0f, 1.0f);
      FLOAT fZN = FLOAT(pow(fZ, fExp));
      ASSERT(fZN>=0 && fZN<=1);
      UBYTE ub = UBYTE(fZN*255);
      pubImage[(pixJ*pixSize+pixI)*3+0] = ub;
      pubImage[(pixJ*pixSize+pixI)*3+1] = ub;
      pubImage[(pixJ*pixSize+pixI)*3+2] = ub;
    }
  }

  try
  {
    TD.Create_t( &II, pixSize, 1, FALSE);
    fsFile.Create_t( fnTexture);
    TD.Write_t( &fsFile);
    fsFile.Close();
  }
  // if failed
  catch (char *strError)
  {
    // report error
    AfxMessageBox(CString(strError));
  }
  II.Detach();
  FreeMemory(pubImage);
}
Exemplo n.º 4
0
void CColoredButton::OnMouseMove(UINT nFlags, CPoint point) 
{
  if( (m_iColorIndex != -1) && (nFlags & MK_LBUTTON) && _bMouseMoveEnabled)
  {
    SetOverButtonInfo( point);
    EnableToolTips( TRUE);
  
    theApp.m_cttToolTips.ManualUpdate();

    CPoint ptCurrent;
    GetCursorPos( &ptCurrent);

    ColorToComponents();
    SLONG slResult = m_ubComponents[ m_iColorIndex][m_iComponentIndex];
    slResult += ptCurrent.x-m_ptCenter.x;
    slResult = Min(Max(slResult,0L), 255L);
    m_ubComponents[ m_iColorIndex][m_iComponentIndex] = UBYTE( slResult);

    COLOR colResult;
    if( m_iColorIndex == 0) {
      colResult = HSVToColor( m_ubComponents[0][0], m_ubComponents[0][1], m_ubComponents[0][2]);
      ColorToRGB(colResult, m_ubComponents[1][0], m_ubComponents[1][1], m_ubComponents[1][2]);
    } else {
      colResult = RGBToColor( m_ubComponents[1][0], m_ubComponents[1][1], m_ubComponents[1][2]);
      ColorToHSV(colResult, m_ubComponents[0][0], m_ubComponents[0][1], m_ubComponents[0][2]);
    }
    // add alpha
    colResult |= m_ubComponents[0][3];
    m_colColor = colResult;
    m_colLastColor = colResult;
    m_bMixedColor = FALSE;
    Invalidate( FALSE);
    SendMessage( WM_PAINT);
    // invalidate parent dialog
    if( m_pwndParentDialog != NULL) m_pwndParentDialog->UpdateData( TRUE);
    if(ptCurrent != m_ptCenter)
    {
      SetCursorPos( m_ptCenter.x, m_ptCenter.y);
    }
  }

  CButton::OnMouseMove(nFlags, point);
}
void CDlgCPPDynamicStateProperty::OnBtnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(SAVETOOBJECT);
	
	UINT addedPos = 0;
	switch((TC_NAME)m_tcStateComponent.GetCurSel())
	{
	case TC_COLOR:	addedPos = m_ppdstate.AddColor( m_fAddTime, m_btnColor.GetColor() );							break;
	case TC_ALPHA:	addedPos = m_ppdstate.AddAlpha( m_fAddTime, Clamp(UBYTE(m_fValue1), UBYTE(0), UBYTE(255)) );	break;
	case TC_SIZE:	addedPos = m_ppdstate.AddSize( m_fAddTime, m_fValue2, m_fValue1 );								break;
	case TC_MASS:	addedPos = m_ppdstate.AddMass( m_fAddTime, m_fValue1 );											break;
	case TC_TEXPOS:	addedPos = m_ppdstate.AddTexPos( m_fAddTime, Clamp(UBYTE(m_fValue2), UBYTE(0), UBYTE(255)),
																 Clamp(UBYTE(m_fValue1), UBYTE(0), UBYTE(255)) );	break;
	case TC_DELTAPOS:	addedPos = m_ppdstate.AddDeltaPos( m_fAddTime, FLOAT3D(m_fValue3, m_fValue2, m_fValue1) );	break;
	case TC_ANGLE:		addedPos = m_ppdstate.AddAngle( m_fAddTime, ANGLE3D(m_fValue3, m_fValue2, m_fValue1) );		break;
	}
	Refresh((TC_NAME)m_tcStateComponent.GetCurSel());
	m_lbAddedState.SetCurSel( (int)addedPos );
}
Exemplo n.º 6
0
BOOL CShockWaveEffect::Process(FLOAT time)
{
	FLOAT fDeltaTime, fProcessedTime;
	BOOL bRet, bRender;
	if(!PreProcess(time, bRet, bRender, fDeltaTime, fProcessedTime))
	{
		if(!bRender) SetNotRenderAtThisFrame();
		return bRet;
	}

	//color 정보
	FLOAT fadeVal = this->GetFadeValue(fProcessedTime);
	if(fadeVal == 1.0f && m_bColorWhite)
	{
		//nothing
	}
	else
	{
		m_vectorGFXColor.clear();
		m_vectorGFXColor.reserve(m_iSplitCount*2);
		UBYTE ubColElement = UBYTE(255.0f * fadeVal);
		GFXColor col;
		if( m_eBlendType == PBT_BLEND || m_eBlendType == PBT_ADDALPHA )
		{
			col = 0xFFFFFF00 | ubColElement; //fade by alpha
		}
		else if( m_eBlendType == PBT_ADD )
		{
			col = (ubColElement << 24) | (ubColElement << 16) | (ubColElement << 8) | 0x000000FF; //fade by color
		}
		else col = 0xFFFFFFFF;	//fade 의미 없음.
		for(INDEX i=0; i<m_iSplitCount; ++i)
		{
			m_vectorGFXColor.push_back(col);
			m_vectorGFXColor.push_back(col);
		}
	}

	//wave 정보
	m_ssHeight.Prepare();
	FLOAT3D height(0, m_ssHeight.Value(fProcessedTime), 0);
	FLOAT radiusInner = 0, radiusOuter = 0;
	m_ssRadius.Prepare();
	m_ssWidth.Prepare();
	if(m_bInnerBasis)
	{
		radiusInner = m_ssRadius.Value(fProcessedTime);
		radiusOuter = radiusInner + m_ssWidth.Value(fProcessedTime);
	}
	else
	{
		radiusOuter = m_ssRadius.Value(fProcessedTime);
		radiusInner = radiusOuter - m_ssWidth.Value(fProcessedTime);
	}

	//tag의 정보
	if(m_ePosition == EOTT_ALWAYS) m_vTagPos = m_ptrAttachTag->CurrentTagInfo().m_vPos;
	if(m_eRotation == EOTT_ALWAYS) m_qTagRot = m_ptrAttachTag->CurrentTagInfo().m_qRot;

	//gfx vertex fill, every frame
	GFXVertex vtx;
	FLOAT3D pos;
	const FLOAT angleUnit = 2 * PI / m_iSplitCount;
	FLOAT angle = 0;
	INDEX index = 0;
	m_vectorGFXVertex.clear();
	m_vectorGFXColor.reserve(m_iSplitCount*2);
	for(INDEX i=0; i<m_iSplitCount; ++i)
	{
		index = 2*i+0;
		pos = m_vectorMoveVector[index] * radiusOuter + height;
		RotateVector(pos, m_qTagRot);
		pos += m_vTagPos;
		vtx.x = pos(1);	vtx.y = pos(2);	vtx.z = pos(3);
		m_vectorGFXVertex.push_back(vtx);

		++index;
		pos = m_vectorMoveVector[index] * radiusInner;
		RotateVector(pos, m_qTagRot);
		pos += m_vTagPos;
		vtx.x = pos(1);	vtx.y = pos(2);	vtx.z = pos(3);
		m_vectorGFXVertex.push_back(vtx);
		angle += angleUnit;
	}

	PostProcess();
	return TRUE;
}
Exemplo n.º 7
0
// emit one block copied from new file
void EmitNew_t(SLONG slOffsetNew, SLONG slSizeNew)
{
  (*_pstrmOut)<<UBYTE(DIFF_NEW);
  (*_pstrmOut)<<slSizeNew;
  (*_pstrmOut).Write_t(_pubNew+slOffsetNew, slSizeNew);
}
Exemplo n.º 8
0
// emit one block copied from old file
void EmitOld_t(SLONG slOffsetOld, SLONG slSizeOld)
{
  (*_pstrmOut)<<UBYTE(DIFF_OLD);
  (*_pstrmOut)<<slOffsetOld;
  (*_pstrmOut)<<slSizeOld;
}
/// Downsampler::Downsample
void Downsampler::Downsample(UBYTE **&data,class ImageLayout *src)
{
  UWORD i;
  // Delete the old image components. Does not release the
  // memory we hold.
  delete[] m_pComponent;
  m_pComponent  = NULL;
  ReleaseComponents(data);
  //
  if (m_bChromaOnly) {
    m_ulWidth     = src->WidthOf();
    m_ulHeight    = src->HeightOf();
  } else { 
    m_ulWidth     = (src->WidthOf()  + m_ucScaleX - 1) / m_ucScaleX;
    m_ulHeight    = (src->HeightOf() + m_ucScaleY - 1) / m_ucScaleY;
  }
  //
  m_usDepth     = src->DepthOf();
  m_pComponent  = new struct ComponentLayout[m_usDepth];
  //
  // Initialize component dimensions.
  for(i = 0; i < m_usDepth; i++) {
    if (m_bChromaOnly == false || i > 0) { 
      m_pComponent[i].m_ulWidth  = (src->WidthOf(i)  + m_ucScaleX - 1) / m_ucScaleX;
      m_pComponent[i].m_ulHeight = (src->HeightOf(i) + m_ucScaleY - 1) / m_ucScaleY;
    } else {
      m_pComponent[i].m_ulWidth  = src->WidthOf(i);
      m_pComponent[i].m_ulHeight = src->HeightOf(i);
    }
    m_pComponent[i].m_ucBits   = src->BitsOf(i);
    m_pComponent[i].m_bSigned  = src->isSigned(i);
    m_pComponent[i].m_bFloat   = src->isFloat(i);
    if (m_bChromaOnly && i > 0) { 
      m_pComponent[i].m_ucSubX   = src->SubXOf(i) * m_ucScaleX;
      m_pComponent[i].m_ucSubY   = src->SubYOf(i) * m_ucScaleY;
    } else {
      m_pComponent[i].m_ucSubX   = src->SubXOf(i);
      m_pComponent[i].m_ucSubY   = src->SubYOf(i);
    }
  }
  //
  data = new UBYTE *[m_usDepth];
  memset(data,0,sizeof(UBYTE *) * m_usDepth);
  //
  for(i = 0;i < m_usDepth;i++) {
    UBYTE bps = (m_pComponent[i].m_ucBits + 7) >> 3;
    if (m_pComponent[i].m_bFloat && m_pComponent[i].m_ucBits == 16)
      bps = sizeof(FLOAT); // stored as float
    //
    data[i]                           = new UBYTE[m_pComponent[i].m_ulWidth * m_pComponent[i].m_ulHeight * bps];
    m_pComponent[i].m_ulBytesPerPixel = bps;
    m_pComponent[i].m_ulBytesPerRow   = bps * m_pComponent[i].m_ulWidth;
    m_pComponent[i].m_pPtr            = data[i];
  }
  //
  for(i = 0;i < m_usDepth;i++) {
    UBYTE sx,sy;
    //
    if (m_bChromaOnly == false || i > 0) { 
      sx = m_ucScaleX;
      sy = m_ucScaleY;
    } else {
      sx = 1;
      sy = 1;
    }
    //
    if (isSigned(i)) {
      if (BitsOf(i) <= 8) {
	BoxFilter<BYTE>((BYTE *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(BYTE *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			src->WidthOf(i),src->HeightOf(i),
			BYTE(-1UL << (BitsOf(i) - 1)),BYTE((1UL << (BitsOf(i) - 1)) - 1),
			sx,sy);
      } else if (!isFloat(i) && BitsOf(i) <= 16) {
	BoxFilter<WORD>((WORD *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(WORD *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			src->WidthOf(i),src->HeightOf(i),
			WORD(-1UL << (BitsOf(i) - 1)),WORD((1UL << (BitsOf(i) - 1)) - 1),
			sx,sy);
      } else if (!isFloat(i) && BitsOf(i) <= 32) {
	BoxFilter<LONG>((LONG *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(LONG *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			src->WidthOf(i),src->HeightOf(i),
			LONG(-1UL << (BitsOf(i) - 1)),LONG((1UL << (BitsOf(i) - 1)) - 1),
			sx,sy);
      } else if (isFloat(i) && BitsOf(i) <= 32) {
	BoxFilter<FLOAT>((FLOAT *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(FLOAT *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			 src->WidthOf(i),src->HeightOf(i),
			 -HUGE_VAL,HUGE_VAL,
			 sx,sy);
      } else if (isFloat(i) && BitsOf(i) == 64) {
	BoxFilter<DOUBLE>((DOUBLE *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			  (DOUBLE *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			  src->WidthOf(i),src->HeightOf(i),
			  -HUGE_VAL,HUGE_VAL,
			  sx,sy);
      } else {
	throw "unsupported data type";
      }
    } else {
      if (BitsOf(i) <= 8) {
	BoxFilter<UBYTE>((UBYTE *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(UBYTE *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			 src->WidthOf(i),src->HeightOf(i),
			 0,UBYTE((1UL << BitsOf(i)) - 1),
			 sx,sy);
      } else if (!isFloat(i) && BitsOf(i) <= 16) {
	BoxFilter<UWORD>((UWORD *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			 (UWORD *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			 src->WidthOf(i),src->HeightOf(i),
			 0,UWORD((1UL << BitsOf(i)) - 1),
			 sx,sy);
      } else if (!isFloat(i) && BitsOf(i) <= 32) {
	BoxFilter<ULONG>((ULONG *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			 (ULONG *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			 src->WidthOf(i),src->HeightOf(i),
			 0,LONG((1UL << BitsOf(i)) - 1),
			 sx,sy);
      } else if (isFloat(i) && BitsOf(i) <= 32) {
	BoxFilter<FLOAT>((FLOAT *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			(FLOAT *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			 src->WidthOf(i),src->HeightOf(i),
			 0.0,HUGE_VAL,
			 sx,sy);
      } else if (isFloat(i) && BitsOf(i) == 64) {
	BoxFilter<DOUBLE>((DOUBLE *)src->DataOf(i),src->BytesPerPixel(i),src->BytesPerRow(i),
			  (DOUBLE *)DataOf(i),BytesPerPixel(i),BytesPerRow(i),
			  src->WidthOf(i),src->HeightOf(i),
			  0.0,HUGE_VAL,
			  sx,sy);
      } else {
	throw "unsupported data type";
      }
    }
  }
  //
  Swap(*src);
}