Beispiel #1
0
static void copy_one_tile(struct TileSet *set, int is_text,
    const unsigned char *image_dat, int sx, int sy, int s_stride,
    unsigned char *tex_dat, int ex, int ey, int e_stride,
    unsigned char *has_alpha)
{
  int dx, dy;
  int alpha_flag = 0;

  int tw = set->tile_w;
  int th = set->tile_h;

  for (dy = 0; dy < th; dy++)
  for (dx = 0; dx < tw; dx++)
  {
    const unsigned char *src = image_dat +
        (sy+dy) * s_stride + (sx+dx) * 4;

    unsigned char *dst = tex_dat + 
        (ey+th+TILE_PAD-1-(dy+1)) * e_stride + (ex+(dx+1)) * 4;

    /* copy RGBA colors, handling alpha */
    if (src[3] < 128)
    {
      dst[0] = dst[1] = dst[2] = 0;
      dst[3] = 0;

      alpha_flag = 1;
    }
    else
    {
      dst[0] = GAMMA(src[0]);
      dst[1] = GAMMA(src[1]);
      dst[2] = GAMMA(src[2]);
      dst[3] = 255;
    }
  }

  /* for text tiles, we simply leave the padding blank.
   * for graphical tiles, we copy the border pixels to the padding.
   */
  if (! is_text)
  {
    for (dy=0; dy <= (th + 1); dy += (th + 1))
    for (dx=0; dx < (tw + TILE_PAD); dx++)
    {
      copy_border_pix(tex_dat, dx, dy, ex, ey, e_stride, tw, th);
    }

    for (dx=0; dx <= (tw + 1); dx += (tw + 1))
    for (dy=1; dy < (th + TILE_PAD - 1); dy++)
    {
      copy_border_pix(tex_dat, dx, dy, ex, ey, e_stride, tw, th);
    }
  }

  (*has_alpha) = (unsigned char) alpha_flag;
}
double lngamma (double x)
{
	double tmp,ser;

	if (x<=50) 
	{ 
		return log(GAMMA(x)); 
	}
	tmp= x+4.5;
	tmp-= (x-0.5)*log(tmp);
	ser= 1.0 + 76.18009173/x - 86.50532033/(x+1.) + 24.01409822/(x+2.) -
		1.231739516/(x+3.) + 0.120858003e-2/(x+4.) - 0.536382e-5/(x+5.);

	return -tmp+log(2.50662827465*ser);
}
Beispiel #3
0
/* Calculate all the coefficients as specified in the bands[] array */
void calc_coeffs()
{
  int i, n;
  double f1, f2;
  double x0;

  n = 0;
  for (; bands[n].cfs; n++) {
    double *freqs = (double *)bands[n].cfs;
    for (i=0; i<bands[n].band_count; i++)
    {

      /* Find -3dB frequencies for the center freq */
      find_f1_and_f2(freqs[i], bands[n].octave, &f1, &f2);
      /* Find Beta */
      if ( find_root(
            BETA2(TETA(freqs[i]), TETA(f1)), 
            BETA1(TETA(freqs[i]), TETA(f1)), 
            BETA0(TETA(freqs[i]), TETA(f1)), 
            &x0) == 0)
      {
        /* Got a solution, now calculate the rest of the factors */
        /* Take the smallest root always (find_root returns the smallest one)
         *
         * NOTE: The IIR equation is
         *	y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2])
         *  Now the 2 factor has been distributed in the coefficients
         */
        /* Now store the coefficients */
        bands[n].coeffs[i].beta = 2.0 * x0;
        bands[n].coeffs[i].alpha = 2.0 * ALPHA(x0);
        bands[n].coeffs[i].gamma = 2.0 * GAMMA(x0, TETA(freqs[i]));
#ifdef DEBUG
        printf("Freq[%d]: %f. Beta: %.10e Alpha: %.10e Gamma %.10e\n",
            i, freqs[i], bands[n].coeffs[i].beta,
            bands[n].coeffs[i].alpha, bands[n].coeffs[i].gamma);
#endif
      } else {
        /* Shouldn't happen */
        bands[n].coeffs[i].beta = 0.;
        bands[n].coeffs[i].alpha = 0.;
        bands[n].coeffs[i].gamma = 0.;
        printf("  **** Where are the roots?\n");
      }
    }// for i
  }//for n
}
Beispiel #4
0
single XGAMMA( single *arg ) {
//============================

    return( GAMMA( *arg ) );
}
Beispiel #5
0
int DecodeGif(const u8 *userData, u8 ScreenBuff[160][240], u16* Palette)
#endif
{
    int	i, j, Row, Col, Width, Height, ExtCode, Count;
    GifRecordType RecordType;
    GifByteType *Extension;
    GifFileType *GifFile;
    ColorMapObject *ColorMap;
    
    if ((GifFile = DGifOpen(userData, readFunc)) == NULL) {
	PrintGifError();
	return EXIT_FAILURE;
    }
    
    for (i = 0; i < GifFile->SWidth; i++)  /* Set its color to BackGround. */
	ScreenBuff[0][i] = GifFile->SBackGroundColor;
    for (i = 1; i < GifFile->SHeight; i++) {
	memcpy(ScreenBuff[i], ScreenBuff[0], GifFile->SWidth);
    }
    
    /* Scan the content of the GIF file and load the image(s) in: */
    do {
	if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR) {
	    PrintGifError();
	    return EXIT_FAILURE;
	}
	switch (RecordType) {
	case IMAGE_DESC_RECORD_TYPE:
	    if (DGifGetImageDesc(GifFile) == GIF_ERROR) {
		PrintGifError();
		return EXIT_FAILURE;
	    }
	    Row = GifFile->Image.Top; /* Image Position relative to Screen. */
	    Col = GifFile->Image.Left;
	    Width = GifFile->Image.Width;
	    Height = GifFile->Image.Height;
	    
	    // Update Color map
	    ColorMap = (GifFile->Image.ColorMap
		? GifFile->Image.ColorMap
		: GifFile->SColorMap);
	    
#ifdef _WIN32
	    ZeroMemory(pBMI, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
	    pBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	    pBMI->bmiHeader.biWidth = Width;
	    pBMI->bmiHeader.biHeight = -Height;     // negative for top-down bitmap
	    pBMI->bmiHeader.biPlanes = 1;
	    pBMI->bmiHeader.biBitCount = 8;
	    pBMI->bmiHeader.biClrUsed = 256;
	    pBMI->bmiHeader.biClrImportant = 256;
	    i = ColorMap->ColorCount;
	    while (--i >= 0)
	    {
		RGBQUAD rgb;
		GifColorType* color = &ColorMap->Colors[i];
		rgb.rgbRed = color->Red;
		rgb.rgbGreen = color->Green;
		rgb.rgbBlue = color->Blue;
		rgb.rgbReserved = 0;
		pBMI->bmiColors[i] = rgb;
	    }
#else
	    i = ColorMap->ColorCount;
	    while (--i >= 0)
	    {
		GifColorType* pColor = &ColorMap->Colors[i];
		Palette[i] = RGB8(GAMMA(pColor->Red), GAMMA(pColor->Green), GAMMA(pColor->Blue));
	    }
#endif
	    if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth ||
		GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight) {
		return EXIT_FAILURE;
	    }
	    if (GifFile->Image.Interlace) {
		/* Need to perform 4 passes on the images: */
		for (Count = i = 0; i < 4; i++)
		    for (j = Row + InterlacedOffset[i]; j < Row + Height;
		    j += InterlacedJumps[i]) {
			if (DGifGetLineByte(GifFile, &ScreenBuff[j][Col],
			    Width) == GIF_ERROR) {
			    PrintGifError();
			    return EXIT_FAILURE;
			}
		    }
	    }
	    else {
		for (i = 0; i < Height; i++) {
		    if (DGifGetLineByte(GifFile, &ScreenBuff[Row++][Col],
			Width) == GIF_ERROR) {
			PrintGifError();
			return EXIT_FAILURE;
		    }
		}
	    }
	    break;
	case EXTENSION_RECORD_TYPE:
	    /* Skip any extension blocks in file: */
	    if (DGifGetExtension(GifFile, &ExtCode, &Extension) == GIF_ERROR) {
		PrintGifError();
		return EXIT_FAILURE;
	    }
	    while (Extension != NULL) {
		if (DGifGetExtensionNext(GifFile, &Extension) == GIF_ERROR) {
		    PrintGifError();
		    return EXIT_FAILURE;
		}
	    }
	    break;
	case TERMINATE_RECORD_TYPE:
	    break;
	default:		    /* Should be traps by DGifGetRecordType. */
	    break;
	}
    }
    while (RecordType != TERMINATE_RECORD_TYPE);
    
    /* Close file when done */
    if (DGifCloseFile(GifFile) == GIF_ERROR) {
	PrintGifError();
	return EXIT_FAILURE;
    }
    
    return 0;
}
Beispiel #6
0
void RenderTask::operator()(const unsigned int depth, RenderProgressCallback* callback)
{
	double pixelWidth = 1.0/m_frameBuffer->getWidth();
	double pixelHeight = 1.0/m_frameBuffer->getHeight();

	Raytracer* rt = new Raytracer(m_scene);

	mutexBuckets.lock();
		Bucket bucket = m_order->getNextBucket();
	mutexBuckets.unlock();

	while (bucket != Bucket::INVALID)
	{
		if (callback)
		{
			mutexCallback.lock();
				callback->onBucketStart(bucket);
			mutexCallback.unlock();
		}

		for (unsigned int y=bucket.y0; y<=bucket.yd; y++)
		{
		for (unsigned int x=bucket.x0; x<=bucket.xd; x++)
		{
			Color rawColor(0,0,0);

			Camera* camera = m_scene->getCameraMount()->getCamera();
			double normX = XScreenToViewPlane(x);
			double normY = YScreenToViewPlane(y);

			unsigned int haltonSeq = 0/*Random::Instance().generate(256)*/;
			for (unsigned int i=1; i<=m_aaSamples; i++)
			{
				haltonSeq++;
				std::vector<Ray> rays = camera->makeSampleRays(
					normX+Random::Instance().haltonSeq(haltonSeq,2)*pixelWidth-pixelWidth*0.5,
					normY+Random::Instance().haltonSeq(haltonSeq,3)*pixelHeight-pixelHeight*0.5);
				for (unsigned int r=0; r<rays.size(); r++)
				{
					//m_primaryRaysCount++;
					rays[r] = m_scene->getCameraMount()->T(rays[r]);	// Local to World
					double distance;
					rawColor += rt->traceRay(rays[r], depth, distance) * (1.0/(double)rays.size());
				}
			}
			rawColor.r /= (double)m_aaSamples;
			rawColor.g /= (double)m_aaSamples;
			rawColor.b /= (double)m_aaSamples;

			rawColor.r = GAMMA(rawColor.r, 2.2);
			rawColor.g = GAMMA(rawColor.g, 2.2);
			rawColor.b = GAMMA(rawColor.b, 2.2);
			m_frameBuffer->setColorAt(x,y, rawColor);
		}
		}

		if (callback)
		{
			mutexCallback.lock();
				callback->onBucketEnd(bucket);
			mutexCallback.unlock();
		}

		mutexBuckets.lock();
			bucket = m_order->getNextBucket();
		mutexBuckets.unlock();
	}

	delete rt;
}