<commit_before>/*
 *  Rubygame binding to SDL Surface class.
 *--
 *  Rubygame -- Ruby code and bindings to SDL to facilitate game creation
 *  Copyright (C) 2004-2007  <NAME>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *++
 */

#include "rubygame_shared.h"
#include "rubygame_surface.h"

void Rubygame_Init_Surface();

VALUE rbgm_surface_new(int, VALUE*, VALUE);

VALUE rbgm_surface_get_w(VALUE);
VALUE rbgm_surface_get_h(VALUE);
VALUE rbgm_surface_get_size(VALUE);

VALUE rbgm_surface_get_depth(VALUE);
VALUE rbgm_surface_get_flags(VALUE);
VALUE rbgm_surface_get_masks(VALUE);

VALUE rbgm_surface_get_alpha(VALUE);
VALUE rbgm_surface_set_alpha(int, VALUE*, VALUE);

VALUE rbgm_surface_get_colorkey(VALUE);
VALUE rbgm_surface_set_colorkey(int, VALUE*, VALUE);

VALUE rbgm_surface_blit(int, VALUE*, VALUE);

VALUE rbgm_surface_fill(int, VALUE*, VALUE);

VALUE rbgm_surface_getat(int, VALUE*, VALUE);

VALUE rbgm_surface_pixels(VALUE);

VALUE rbgm_surface_get_cliprect(VALUE);
VALUE rbgm_surface_set_cliprect(VALUE, VALUE);

VALUE rbgm_surface_convert(int, VALUE*, VALUE);
VALUE rbgm_surface_displayformat(VALUE);
VALUE rbgm_surface_displayformatalpha(VALUE);

VALUE rbgm_image_savebmp(VALUE, VALUE);

VALUE rbgm_transform_flip(VALUE, VALUE, VALUE);

/* 
 *  call-seq:
 *     new(size, depth=0, flags=0)  ->  Surface
 *
 *  Create and initialize a new Surface object. 
 *
 *  A Surface is a grid of image data which you blit (i.e. copy) onto other
 *  Surfaces. Since the Rubygame display is also a Surface (see the Screen 
 *  class), Surfaces can be blit to the screen; this is the most common way
 *  to display images on the screen.
 *
 *  Currently, you must create a display window (see Screen#set_mode) before
 *  creating a new Surface.
 *
 *  This function takes these arguments:
 *  size::  requested surface size; an array of the form [width, height].
 *  depth:: requested color depth (in bits per pixel). If depth is 0 (default),
 *          use the color depth of the current Screen mode.
 *--
 *          automatically choose a color depth: either the depth of the Screen
 *          mode (if one has been set), or the greatest color depth available
 *          on the system.
 *++
 *  flags:: an Array or Bitwise-OR'd list of zero or more of the following 
 *          flags (located in the Rubygame module, e.g. Rubygame::SWSURFACE).
 *          This argument may be omitted, in which case the Surface 
 *          will be a normal software surface (this is not necessarily a bad
 *          thing).
 *          SWSURFACE::   (default) request a software surface.
 *          HWSURFACE::   request a hardware-accelerated surface (using a 
 *                        graphics card), if available. Creates a software
 *                        surface if hardware surfaces are not available.
 *          SRCCOLORKEY:: request a colorkeyed surface. #set_colorkey will
 *                        also enable colorkey as needed. For a description
 *                        of colorkeys, see #set_colorkey.
 *          SRCALPHA::    request an alpha channel. #set_alpha will
 *                        also enable alpha. as needed. For a description
 *                        of alpha, see #alpha.
 */
VALUE rbgm_surface_new(int argc, VALUE *argv, VALUE class)
{
	VALUE self;
	SDL_Surface *self_surf;
	SDL_PixelFormat* pixformat;
	Uint32 flags, Rmask, Gmask, Bmask, Amask;
	int w, h, depth;
	VALUE vsize, vdepth, vflags;

	rb_scan_args(argc, argv, "12", &vsize, &vdepth, &vflags);

	if( SDL_GetVideoSurface() )
	{
		/* Pixel format is retrieved from the video surface. */
		pixformat = (SDL_GetVideoSurface())->format;
	}
	else
	{
		rb_raise(eSDLError,"Cannot create Surface before the Screen mode is set!");
		/* The following code causes an inexplicable segfault? :(  -j */
		/* pixformat = SDL_GetVideoInfo()->vfmt; */ 
	}
<commit_msg>New Surfaces can be created before a Screen mode has been set.<commit_after>/*
 *  Rubygame binding to SDL Surface class.
 *--
 *  Rubygame -- Ruby code and bindings to SDL to facilitate game creation
 *  Copyright (C) 2004-2007  <NAME>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *++
 */

#include "rubygame_shared.h"
#include "rubygame_surface.h"

void Rubygame_Init_Surface();

VALUE rbgm_surface_new(int, VALUE*, VALUE);

VALUE rbgm_surface_get_w(VALUE);
VALUE rbgm_surface_get_h(VALUE);
VALUE rbgm_surface_get_size(VALUE);

VALUE rbgm_surface_get_depth(VALUE);
VALUE rbgm_surface_get_flags(VALUE);
VALUE rbgm_surface_get_masks(VALUE);

VALUE rbgm_surface_get_alpha(VALUE);
VALUE rbgm_surface_set_alpha(int, VALUE*, VALUE);

VALUE rbgm_surface_get_colorkey(VALUE);
VALUE rbgm_surface_set_colorkey(int, VALUE*, VALUE);

VALUE rbgm_surface_blit(int, VALUE*, VALUE);

VALUE rbgm_surface_fill(int, VALUE*, VALUE);

VALUE rbgm_surface_getat(int, VALUE*, VALUE);

VALUE rbgm_surface_pixels(VALUE);

VALUE rbgm_surface_get_cliprect(VALUE);
VALUE rbgm_surface_set_cliprect(VALUE, VALUE);

VALUE rbgm_surface_convert(int, VALUE*, VALUE);
VALUE rbgm_surface_displayformat(VALUE);
VALUE rbgm_surface_displayformatalpha(VALUE);

VALUE rbgm_image_savebmp(VALUE, VALUE);

VALUE rbgm_transform_flip(VALUE, VALUE, VALUE);

/* 
 *  call-seq:
 *     new(size, depth=0, flags=0)  ->  Surface
 *
 *  Create and initialize a new Surface object. 
 *
 *  A Surface is a grid of image data which you blit (i.e. copy) onto other
 *  Surfaces. Since the Rubygame display is also a Surface (see the Screen 
 *  class), Surfaces can be blit to the screen; this is the most common way
 *  to display images on the screen.
 *
 *  This method may raise SDLError if the SDL video subsystem could
 *  not be initialized for some reason.
 *
 *  This function takes these arguments:
 *  size::  requested surface size; an array of the form [width, height].
 *  depth:: requested color depth (in bits per pixel). If depth is 0 (default),
 *          automatically choose a color depth: either the depth of the Screen
 *          mode (if one has been set), or the greatest color depth available
 *          on the system.
 *  flags:: an Array or Bitwise-OR'd list of zero or more of the following 
 *          flags (located in the Rubygame module, e.g. Rubygame::SWSURFACE).
 *          This argument may be omitted, in which case the Surface 
 *          will be a normal software surface (this is not necessarily a bad
 *          thing).
 *          SWSURFACE::   (default) request a software surface.
 *          HWSURFACE::   request a hardware-accelerated surface (using a 
 *                        graphics card), if available. Creates a software
 *                        surface if hardware surfaces are not available.
 *          SRCCOLORKEY:: request a colorkeyed surface. #set_colorkey will
 *                        also enable colorkey as needed. For a description
 *                        of colorkeys, see #set_colorkey.
 *          SRCALPHA::    request an alpha channel. #set_alpha will
 *                        also enable alpha. as needed. For a description
 *                        of alpha, see #alpha.
 */
VALUE rbgm_surface_new(int argc, VALUE *argv, VALUE class)
{
	VALUE self;
	SDL_Surface *self_surf;
	SDL_PixelFormat* pixformat;
	Uint32 flags, Rmask, Gmask, Bmask, Amask;
	int w, h, depth;
	VALUE vsize, vdepth, vflags;

	rb_scan_args(argc, argv, "12", &vsize, &vdepth, &vflags);

	if( SDL_GetVideoSurface() )
	{
		/* Pixel format is retrieved from the video surface. */
		pixformat = (SDL_GetVideoSurface())->format;
	}
	else
	{
		/* We can only get the system color depth when the video system
		 * has been initialized. */
		if( init_video_system() == 0 )
		{
			pixformat = SDL_GetVideoInfo()->vfmt;
		}
		else
		{
			rb_raise(eSDLError,"Could not initialize SDL video subsystem.");
			return Qnil;
		}
	}

{'fraction_non_alphanumeric': 0.08245173955720363, 'fraction_numerical': 0.006870978296433635, 'mean_word_length': 3.329556185080264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6177865', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2768, 'n_words': 1049}