Example #1
0
static void
convert_from_rgba (guchar *pixels,
                   gint    width)
{
  guint32 *cairo_data = (guint32 *) pixels;
  guchar  *p;
  gint     i;

  for (i = 0, p = pixels; i < width; i++)
    {
      guint32 r = *p++;
      guint32 g = *p++;
      guint32 b = *p++;
      guint32 a = *p++;

      if (a != 255)
        {
          guint32 tmp;

          /* composite on a white background */

          r = INT_BLEND (r, 255, a, tmp);
          g = INT_BLEND (g, 255, a, tmp);
          b = INT_BLEND (b, 255, a, tmp);
        }

      cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
    }
}
Example #2
0
/*****************************************************
* Create the cache bitmaps for drawing
* This is needed on resize, start and recoloring
*****************************************************/
bool IndexView::CalculateCache(BRect rect)
{
	if (!OffScreen){
		return false;
	}

	acquire_sem(indexSem);
	BRect r = Bounds();

	int32 size = INDEXVIEW_HEIGHT+1, temp;
	rgb_color a[size], b[size], c[size], d[size];

	rgb_color back2s = Prefs.index_back_color;
	rgb_color back1s = Prefs.index_back_color2;
	rgb_color back2 = Prefs.index_back_selected_color;
	rgb_color back1 = Prefs.index_back_selected_color2;
	rgb_color fore2s = Prefs.index_left_selected_color;
	rgb_color fore1s = Prefs.index_left_selected_color2;
	rgb_color fore2 = Prefs.index_left_color;
	rgb_color fore1 = Prefs.index_left_color2;

	for(int32 y=0; y<size; y++)
	{
		uint8 alpha = (uint8)(y*255/size);

		a[y].red = INT_BLEND(back1.red, back2.red, alpha, temp);
		a[y].green = INT_BLEND(back1.green, back2.green, alpha, temp);
		a[y].blue = INT_BLEND(back1.blue, back2.blue, alpha, temp);
		
		b[y].red = INT_BLEND(back1s.red, back2s.red, alpha, temp);
		b[y].green = INT_BLEND(back1s.green, back2s.green, alpha, temp);
		b[y].blue = INT_BLEND(back1s.blue, back2s.blue, alpha, temp);

		c[y].red = INT_BLEND(fore1.red, fore2.red, alpha, temp);
		c[y].green = INT_BLEND(fore1.green, fore2.green, alpha, temp);
		c[y].blue = INT_BLEND(fore1.blue, fore2.blue, alpha, temp);
			
		d[y].red = INT_BLEND(fore1s.red, fore2s.red, alpha, temp);
		d[y].green = INT_BLEND(fore1s.green, fore2s.green, alpha, temp);
		d[y].blue = INT_BLEND(fore1s.blue, fore2s.blue, alpha, temp);
	}


	int32 left = (int32)r.right+1;
	int32 right = -1;
		
	BitmapDrawer draw(OffScreen);

	// the background
	float w = r.Width();
	if ((Pool.r_pointer - Pool.l_pointer) == Pool.size || Pool.sample_type == NONE){
		for (int32 y = (int32)r.top; y < (int32)r.bottom; y++)
			for (int32 x = (int32)r.left; x <= (int32)r.right; x++)
				draw.PlotRGB( x, y, b[y] );

		left = (int32)r.left;
		right = (int32)r.right;
	}else{
		if (Pool.l_pointer>0){
			r.right = Pool.l_pointer * w / Pool.size;
			for (int32 y = (int32)r.top; y < (int32)r.bottom; y++)
				for (int32 x = (int32)r.left; x <= (int32)r.right; x++)
					draw.PlotRGB( x, y, a[y] );

			r.left = r.right;
		}
		r.right = Pool.r_pointer * w / Pool.size;
		for (int32 y = (int32)r.top; y < (int32)r.bottom; y++)
			for (int32 x = (int32)r.left; x <= (int32)r.right; x++)
				draw.PlotRGB( x, y, b[y] );

		left = (int32)r.left;
		right = (int32)r.right;

		if (Pool.r_pointer != Pool.size){
			r.left = r.right+1.0f;
			r.right = Bounds().right;
			for (int32 y = (int32)r.top; y < (int32)r.bottom; y++)
				for (int32 x = (int32)r.left; x <= (int32)r.right; x++)
					draw.PlotRGB( x, y, a[y] );

		}
	}

	int32 mid = int32((r.bottom+r.top)/2);
//	for (int32 x = (int32)r.left; x <= (int32)r.right; x++)
//		draw.PlotRGB( x, mid, Prefs.index_mid_color );

	if (Pool.sample_type != NONE){
		// get the new index view data
		if (Pool.sample_type == MONO)
			Peak.MonoBuffer(index_memory_left, 0, Pool.size, Bounds().IntegerWidth()+1);
		else if (Pool.sample_type == STEREO){
			Peak.StereoBuffer(index_memory_left, index_memory_right, 0, Pool.size, Bounds().IntegerWidth()+1);
			for (int32 i=0; i<r.right*2; i++){
				index_memory_left[i] = (index_memory_left[i] + index_memory_right[i])/2.0;
			}
		}

		// Draw the data
		int32 amp = int32(r.Height()/2.0);
		int32 index = 0, from, to;
		for (int32 x=0; x<r.right; x++){
			to =  mid -  int32(index_memory_left[ index ]*amp);
			from = mid -  int32(index_memory_left[ index+1 ]*amp);

			if ( from == to && from != mid)
				draw.PlotRGB( x, mid, Prefs.index_mid_color );
			else if (x>=left && x<=right)
			{
				for (int32 y = from; y <= to; y++)
					draw.PlotRGB( x, y, c[y] );
			}
			else
			{
				for (int32 y = from; y <= to; y++)
					draw.PlotRGB( x, y, d[y] );
			}

			index += 2;
		}


		// draw pointer
		if (Pool.selection == NONE){
			int32 x = (int32)(Pool.pointer * w / Pool.size);
			for (int32 y = (int32)r.top; y < (int32)r.bottom; y+=2)
				draw.PlotRGB( x, y, Prefs.index_pointer_color );
		}else{
			r.top ++;	r.bottom --;
			r.left = Pool.pointer * w / Pool.size;
			r.right = Pool.r_sel_pointer * w / Pool.size;
			for (int32 y = (int32)r.top; y < (int32)r.bottom; y+=2)
			{
				draw.PlotRGB( (int32)r.left, y, Prefs.index_pointer_color );
				draw.PlotRGB( (int32)r.right, y, Prefs.index_pointer_color );
			}
			int32 top = (int32)r.top;
			int32 bottom = (int32)r.bottom;
			for (int32 x = (int32)r.left; x < (int32)r.right; x+=2)
			{
				draw.PlotRGB( x, top, Prefs.index_pointer_color );
				draw.PlotRGB( x, bottom, Prefs.index_pointer_color );
			}

		}
	}
	Pool.update_index = false;
	release_sem(indexSem);
	return true;
}