Example #1
0
static void *
draw_scanlines (void *data)
{
	thread_args_t *thread_args = (thread_args_t *)data;
	scene_t *scene = thread_args->scene;
	int i, end = thread_args->end;

	const unsigned int h_resolution = bp_scene_get_horizontal_resolution (scene);


	for (i = thread_args->start; i < end; i += 2) {
		int j;
		const unsigned int v_resolution = bp_scene_get_vertical_resolution (scene);
 		bp_report_render_progress (render_progress++ / v_resolution);
		for (j = 0; j < h_resolution; j+= 2) {
			ray4_t ray4;
			vector_t colors [4];

			bp_camera_get_ray2x2 (&scene->camera, i, j, &ray4);
			bp_ray_trace_packet (&ray4, colors, simd4i_minus_ones, 0, simd4_ones);

			gamma_correct (bp_framebuffer_get_color (&scene->fb, i, j), colors [0], gamma_inv);
			gamma_correct (bp_framebuffer_get_color (&scene->fb, i, (j + 1)), colors [1], gamma_inv);
			gamma_correct (bp_framebuffer_get_color (&scene->fb, (i + 1), j), colors [2], gamma_inv);
			gamma_correct (bp_framebuffer_get_color (&scene->fb, (i + 1), (j + 1)), colors [3], gamma_inv);
		}
	}
	pthread_exit (NULL);
	return NULL;
}
Example #2
0
static void
gamma_correct_rgb(const struct colorSystem * const cs,
                  double * const r,
                  double * const g,
                  double * const b) {
    gamma_correct(cs, r);
    gamma_correct(cs, g);
    gamma_correct(cs, b);
}
Example #3
0
  void write_image(const string& file, const SampleBuffer& buffer)
  {
    const float samples = static_cast<float>(buffer.samples());
    FIBITMAP* dib = FreeImage_Allocate(buffer.width(), buffer.height(),
        32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);

    const unsigned int BYTESPP =
      FreeImage_GetLine(dib) / FreeImage_GetWidth(dib);
    for (unsigned int y = 0; y < FreeImage_GetHeight(dib); ++y) {
      BYTE* bits = FreeImage_GetScanLine(dib, y);

      for (unsigned int x = 0; x < FreeImage_GetWidth(dib); ++x) {
        vec3 c = gamma_correct(buffer.get(x, y) / samples) * 255.0f;
        bits[FI_RGBA_RED]   = static_cast<BYTE>(c.r);
        bits[FI_RGBA_GREEN] = static_cast<BYTE>(c.g);
        bits[FI_RGBA_BLUE]  = static_cast<BYTE>(c.b);
        bits[FI_RGBA_ALPHA] = 255;

        bits += BYTESPP;
      }
    }

    if (!FreeImage_Save(FIF_PNG, dib, file.c_str(), 0)) {
      string err = "Failed to save screenshot to file '";
      err += file;
      err += '\'';
      throw err;
    }

    FreeImage_Unload(dib);
  }
Example #4
0
static void makeUcharImage( Image *image, double *re, int color )
{
	register int x,y;
	register unsigned char *data = *(image->data);
	int		cy, dy, cl = color, bpp = image->bitsPerPixel/8;
	double maxval = 0.0, scale = 1.0;
	
	if( bpp == 4 ) cl++;

	for( y=0; y<image->height; y++)
	{
		cy = y * image->bytesPerLine + cl;
		dy = y * image->width;
		for( x=0; x<image->width; x++)
		{
			if( re[ dy + x ]  > maxval) maxval = re[ dy + x ];
		}
	}

	if(maxval > (double)glu.ChannelSize || maxval < (double)glu.ChannelSize/3.0 )
		scale = (double)glu.ChannelSize / maxval;
		
	for( y=0; y<image->height; y++)
	{
		cy = y * image->bytesPerLine + cl;
		dy = y * image->width;
		for( x=0; x<image->width; x++)
		{
			data[ cy + bpp * x ] = (unsigned char)(gamma_correct( re[ dy + x ] * scale ));
		}
	}
	// Dangerous, but should be ok
	if( glu.DeGamma ) free( glu.DeGamma ); glu.DeGamma 	= NULL;
	if( glu.Gamma )	free( glu.Gamma );	glu.Gamma 	= NULL;
}
Example #5
0
vec3 gamma_corrected_clamp(color const &c)
{
    color gc = gamma_correct(c);
    return color(
        gc.x() > 1.0? 1.0 : gc.x(),
        gc.y() > 1.0? 1.0 : gc.y(),
        gc.z() > 1.0? 1.0 : gc.z()
    );
}
void prepare_output_line(COLOUR *Line)
{
  int i;

  for (i = 0; i <= Frame.Screen_Width ; i++)
  {
    Clip_Colour(Line[i], Line[i]);
    gamma_correct(Line[i]);
  }
}
Example #7
0
static void
sfid_render_cache_rt_write_simd8_bgra_unorm8_xmajor(struct thread *t,
        const struct sfid_render_cache_args *args)
{
    __m256i argb;
    const float scale = 255.0f;
    struct reg src[4];

    memcpy(src, &t->grf[args->src], sizeof(src));

    const int cpp = 4;
    const int slice_y = args->rt.minimum_array_element * args->rt.qpitch;
    const int x = t->grf[1].uw[4];
    const int y = t->grf[1].uw[5] + slice_y;
    void *base = xmajor_offset(args->rt.pixels, x, y, args->rt.stride, cpp);

    if (gt.blend.enable) {
        /* Load unorm8 */
        __m128i lo = _mm_load_si128(base);
        __m128i hi = _mm_load_si128(base + 512);
        __m256i dst_argb = _mm256_inserti128_si256(_mm256_castsi128_si256(lo), hi, 1);
        dst_argb = _mm256_permute4x64_epi64(dst_argb, SWIZZLE(0, 2, 1, 3));

        blend_unorm8_argb(src, dst_argb);
    }

    gamma_correct(args->rt.format, src);

    const __m256i r = to_unorm(src[0].reg, scale);
    const __m256i g = to_unorm(src[1].reg, scale);
    const __m256i b = to_unorm(src[2].reg, scale);
    const __m256i a = to_unorm(src[3].reg, scale);

    argb = _mm256_slli_epi32(a, 8);
    argb = _mm256_or_si256(argb, r);
    argb = _mm256_slli_epi32(argb, 8);
    argb = _mm256_or_si256(argb, g);
    argb = _mm256_slli_epi32(argb, 8);
    argb = _mm256_or_si256(argb, b);

    /* Swizzle two middle pixel pairs so that dword 0-3 and 4-7
     * form linear owords of pixels. */
    argb = _mm256_permute4x64_epi64(argb, SWIZZLE(0, 2, 1, 3));
    __m256i mask = _mm256_permute4x64_epi64(t->mask_q1, SWIZZLE(0, 2, 1, 3));

    _mm_maskstore_epi32(base,
                        _mm256_extractf128_si256(mask, 0),
                        _mm256_extractf128_si256(argb, 0));
    _mm_maskstore_epi32(base + 512,
                        _mm256_extractf128_si256(mask, 1),
                        _mm256_extractf128_si256(argb, 1));
}
void extract_colors(COLOUR Colour, unsigned char *Red, unsigned char  *Green, unsigned char  *Blue, unsigned char  *Alpha, DBL *grey)
{
  COLOUR ColourG;

  Clip_Colour(ColourG, Colour);
  gamma_correct(ColourG);

  if (opts.PaletteOption == GREY)
  {
    *grey = ColourG[pRED] * GREY_SCALE(ColourG);

    *Red = *Green = *Blue = (unsigned char)((*grey) * maxclr);
  }
  else
  {
    *Red   = (unsigned char)(ColourG[pRED]    * maxclr);
    *Green = (unsigned char)(ColourG[pGREEN]  * maxclr);
    *Blue  = (unsigned char)(ColourG[pBLUE]   * maxclr);
    *Alpha = (unsigned char)(ColourG[pTRANSM] * maxclr);
  }
}
Example #9
0
File: main.c Project: caomw/grass
static void write_row_float(png_bytep p)
{
    unsigned int x, c;
    channel *ch;

    for (x = 0; x < width; x++)
	for (c = 0; c < 6; c++)
	{
	    ch = &channels[c];
	    if (ch->active)
		ch->fbuf[x] = (FCELL) get_png_val(&p, bit_depth)
		    / ch->maxval;
	}

    if (t_gamma != 1.0)
	for (c = 0; c < 6; c++)
	{
	    ch = &channels[c];
	    if (c != C_A && ch->active)
		for (x = 0; x < width; x++)
		    ch->fbuf[x] = gamma_correct(ch->fbuf[x]);
	}

    if (channels[C_A].active && ialpha > 0)
	for (c = 0; c < 6; c++)
	{
	    ch = &channels[c];
	    if (c != C_A && ch->active)
		for (x = 0; x < width; x++)
		    if (channels[C_A].fbuf[x] <= alpha)
			Rast_set_f_null_value(&ch->fbuf[x], 1);
	}

    for (c = 0; c < 6; c++)
    {
	ch = &channels[c];
	if (ch->active)
	    Rast_put_f_row(ch->fd, ch->fbuf);
    }
}
Example #10
0
static void gamma_correct_rgb(const struct colourSystem *cs, double *r, double *g, double *b)
{
    gamma_correct(cs, r);
    gamma_correct(cs, g);
    gamma_correct(cs, b);
}
Example #11
0
void menu_handler(event &ev, input_manager *inm)
{
  switch (ev.type)
  {
    case EV_MESSAGE :
    {
      switch (ev.message.id)
      {
				case ID_LIGHT_OFF :
				if (!volume_window)
				{
                                  screen->clear();
				  eh->flush_screen(); 
				  gamma_correct(pal,1);
				  fade_in(cash.img(title_screen),8);
                                  inm->redraw();
				  eh->flush_screen(); 
				} break;
				case ID_RETURN :
				if (!volume_window)
				{
				  the_game->set_state(RUN_STATE);
				} break;
				case ID_START_GAME :
				if (!volume_window)
				{        
				  the_game->load_level(level_file);
				  the_game->set_state(RUN_STATE);
				  view *v;
				  for (v=player_list;v;v=v->next)
				    if (v->focus)
				      v->reset_player();
				   
				} break;

   
        case ID_LOAD_PLAYER_GAME :
				if (!volume_window)
				{
				  int got_level=load_game(0,symbol_str("LOAD"));
				  the_game->reset_keymap();
				  if (got_level)
				  {
				    char name[50];
				    sprintf(name,"save%04d.spe",got_level);
				    the_game->load_level(name);
				    the_game->set_state(RUN_STATE);	    
				  }
				} break;
			
			
				case ID_VOLUME : 
				if (!volume_window)
				{ create_volume_window(); } break;
			
				case ID_MEDIUM :
				{
				  set_symbol_value(l_difficulty,l_medium);
				  save_difficulty();
				} break;
				case ID_HARD :
				{
				  set_symbol_value(l_difficulty,l_hard);
				  save_difficulty();
				} break;
				case ID_EXTREME :
				{
				  set_symbol_value(l_difficulty,l_extreme);
				  save_difficulty();
				} break;
				case ID_EASY :
				{
				  set_symbol_value(l_difficulty,l_easy);
				  save_difficulty();
				} break;
			
				case ID_NETWORKING :
				{
				  if (!volume_window)
				  {
				    net_configuration *cfg=new net_configuration;
				    if (cfg->input())
				    {
				      if (main_net_cfg) delete main_net_cfg;
				      main_net_cfg=cfg;
				    } else delete cfg;
				    the_game->draw(0);
				    inm->redraw();
				  }
				} break;
					      
				case ID_SHOW_SELL :
				if (!volume_window)
				{ 
				  show_sell(1); 
				  screen->clear();
				  if (title_screen>=0)
				  {
				    image *tit=cash.img(title_screen);
				      tit->put_image(screen,screen->width()/2-tit->width()/2,
								      screen->height()/2-tit->height()/2);
				  }
				  inm->redraw();
				  fade_in(NULL,8);
				  eh->flush_screen(); 
			
				} break;
					      
				case ID_MACKEYS :
                                  do_key_config(eh);

                                  /*
					fade_out(8);
					RestoreMac();
					MacKeyConfigMenu();

					UnRestoreMac(); */

                                    fade_in(cash.img(title_screen),8);
                                    inm->redraw();
                                    eh->flush_screen(); 
					break;

				case ID_MACCONF :
                                  do_monitor_config(eh);

				  fade_in(cash.img(title_screen),8);
                                  inm->redraw();
                                  eh->flush_screen(); 
                                  break;
      } break;
    } break;
    case EV_CLOSE_WINDOW :
    {
      if (ev.window==volume_window)
      { eh->close_window(volume_window); volume_window=NULL; }
    } break;
  }
}
Example #12
0
File: main.c Project: caomw/grass
static int intensity(double k)
{
    return (int) (gamma_correct(k) * 255 + 0.5);
}
Example #13
0
static gboolean
screen_saver_floater_do_draw (ScreenSaver        *screen_saver,
                              ScreenSaverFloater *floater,
                              cairo_t            *context)
{
    gint size;
    CachedSource *source;

    size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->scale),
                  FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

    source = g_hash_table_lookup (screen_saver->cached_sources, GINT_TO_POINTER (size));

    if (source == NULL)
    {
        GdkPixbuf *pixbuf;
        GError *error;

        pixbuf = NULL;
        error = NULL;

        pixbuf = gdk_pixbuf_new_from_file_at_size (screen_saver->filename, size, -1,
                 &error);
        if (pixbuf == NULL)
        {
            g_assert (error != NULL);
            g_printerr ("%s", _(error->message));
            g_error_free (error);
            return FALSE;
        }

        if (gdk_pixbuf_get_has_alpha (pixbuf))
            gamma_correct (pixbuf);

        gdk_cairo_set_source_pixbuf (context, pixbuf, 0.0, 0.0);

        source = cached_source_new (cairo_get_source (context),
                                    gdk_pixbuf_get_width (pixbuf),
                                    gdk_pixbuf_get_height (pixbuf));
        g_object_unref (pixbuf);
        g_hash_table_insert (screen_saver->cached_sources, GINT_TO_POINTER (size),
                             source);
    }

    cairo_save (context);

    if (screen_saver->should_do_rotations && (abs (floater->angle) > G_MINDOUBLE))
    {
        floater->bounds.width = G_SQRT2 * source->width + 2;
        floater->bounds.height = G_SQRT2 * source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * G_SQRT2 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * G_SQRT2 * source->height) - 1;

        cairo_translate (context,
                         trunc (floater->position.x),
                         trunc (floater->position.y));
        cairo_rotate (context, floater->angle);
        cairo_translate (context,
                         -trunc (floater->position.x),
                         -trunc (floater->position.y));
    }
    else
    {
        floater->bounds.width = source->width + 2;
        floater->bounds.height = source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * source->height) - 1;
    }

    cairo_translate (context,
                     trunc (floater->position.x - .5 * source->width),
                     trunc (floater->position.y - .5 * source->height));

    cairo_set_source (context, source->pattern);

    cairo_rectangle (context,
                     trunc (.5 * (source->width - floater->bounds.width)),
                     trunc (.5 * (source->height - floater->bounds.height)),
                     floater->bounds.width, floater->bounds.height);

    cairo_clip (context);
    cairo_paint_with_alpha (context, floater->opacity);
    cairo_restore (context);

    if (screen_saver->should_show_paths && (floater->path != NULL))
    {
        gdouble dash_pattern[] = { 5.0 };
        gint size;

        size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->path_start_scale),
                      FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

        cairo_save (context);
        cairo_set_source_rgba (context, 1.0, 1.0, 1.0, .2 * floater->opacity);
        cairo_move_to (context,
                       floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_curve_to (context,
                        floater->path->start_control_point.x,
                        floater->path->start_control_point.y,
                        floater->path->end_control_point.x,
                        floater->path->end_control_point.y,
                        floater->path->end_point.x,
                        floater->path->end_point.y);
        cairo_set_line_cap (context, CAIRO_LINE_CAP_ROUND);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 1.0, 0.0, 0.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->start_point.x - 3,
                         floater->path->start_point.y - 3,
                         6, 6);
        cairo_fill (context);
        cairo_set_source_rgba (context, 0.0, 0.5, 0.0, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->start_control_point.x,
                   floater->path->start_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.5, 0.0, 0.5, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->end_control_point.x,
                   floater->path->end_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.0, 0.0, 1.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->end_point.x - 3,
                         floater->path->end_point.y - 3,
                         6, 6);
        cairo_fill (context);

        cairo_set_dash (context, dash_pattern, G_N_ELEMENTS (dash_pattern), 0);
        cairo_set_source_rgba (context, .5, .5, .5, .2 * floater->scale);
        cairo_move_to (context, floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_line_to (context, floater->path->start_control_point.x,
                       floater->path->start_control_point.y);
        cairo_stroke (context);

        cairo_move_to (context, floater->path->end_point.x,
                       floater->path->end_point.y);
        cairo_line_to (context, floater->path->end_control_point.x,
                       floater->path->end_control_point.y);
        cairo_stroke (context);

        cairo_restore (context);
    }

    return TRUE;
}
Example #14
0
//http://www.fourmilab.ch/documents/specrend/
void gamma_correct_RGB(	double gamma,  double *r, double *g, double *b)
{
	gamma_correct(gamma, r);
	gamma_correct(gamma, g);
	gamma_correct(gamma, b);
}
Example #15
0
void menu_handler(event &ev, jwindow *ico_win)
{
  switch (ev.type)
  {
    case EV_MESSAGE :
    {
      switch (ev.message.id)
      {
	case ID_LIGHT_OFF :
	{
	  gamma_correct(pal,1);
	} break;
	case ID_START_GAME :
	{        
	  the_game->load_level(level_file);
	  the_game->set_state(RUN_STATE);
	} break;

	case ID_VOLUME : 
	{ create_volume_window(); } break;
      	case ID_SFX_UP :
	{ if (volume_window) 
	  {
	    sfx_volume+=16;
	    if (sfx_volume>127) sfx_volume=127;
	    draw_sfx_vol();
	  }
	} break;
      	case ID_SFX_DOWN :
	{ if (volume_window) 
	  {
	    sfx_volume-=16;
	    if (sfx_volume<0) sfx_volume=0;
	    draw_sfx_vol();
	  }
	} break;

      	case ID_MUSIC_UP :
	{ if (volume_window) 
	  {
	    music_volume+=16;
	    if (music_volume>127) music_volume=127;
	    draw_music_vol();
	  }
	} break;
      	case ID_MUSIC_DOWN :
	{ if (volume_window) 
	  {
	    music_volume-=16;
	    if (music_volume<0) music_volume=0;
	    draw_music_vol();
	  }
	} break;
	case ID_MEDIUM :
	{
	  set_symbol_value(l_difficulty,l_medium);
	  save_difficulty();
	} break;
	case ID_HARD :
	{
	  set_symbol_value(l_difficulty,l_hard);
	  save_difficulty();
	} break;
	case ID_EXTREME :
	{
	  set_symbol_value(l_difficulty,l_extreme);
	  save_difficulty();
	} break;
	case ID_EASY :
	{
	  set_symbol_value(l_difficulty,l_easy);
	  save_difficulty();
	} break;
		      
			 
      } break;
    } break;
    case EV_CLOSE_WINDOW :
    {
      if (ev.window==volume_window)
      { eh->close_window(volume_window); volume_window=NULL; }
    } break;
  }
}
Example #16
0
void gamma_correct_rgb(const struct colourSystem *cs, float *r, float *g, float *b)
{
    gamma_correct(cs, r);
    gamma_correct(cs, g);
    gamma_correct(cs, b);
}