<commit_before>/**
 * Automated SDL_Surface test.
 *
 * Written by <NAME> "bobbens"
 *
 * Released under Public Domain.
 */


#include "SDL.h"
#include "SDL_at.h"

#include "common/common.h"


/*
 * Pull in images for testcases.
 */
#include "common/images.h"


#define SCREEN_W     80
#define SCREEN_H     60

#define FACE_W       img_face.width
#define FACE_H       img_face.height


/*
 * Prototypes.
 */
static int render_compare( const char *msg, const SurfaceImage_t *s );
static int render_isSupported( int code );
static int render_hasDrawColor (void);
static int render_hasBlendModes (void);
static int render_hasTexColor (void);
static int render_hasTexAlpha (void);
static int render_clearScreen (void);
/* Testcases. */
static int render_testPrimitives (void);
static int render_testPrimitivesBlend (void);
static int render_testBlit (void);
static int render_testBlitColour (void);
static int render_testBlitAlpha (void);
static int render_testBlitBlendMode( SDL_TextureID tface, int mode );
static int render_testBlitBlend (void);


/**
 * @brief Compares screen pixels with image pixels.
 *
 *    @param msg Message on failure.
 *    @param s Image to compare against.
 *    @return 0 on success.
 */
static int render_compare( const char *msg, const SurfaceImage_t *s )
{
   (void) msg;
   (void) s;
   int ret;
   void *pix;
   SDL_Surface *testsur;

   /* Allocate pixel space. */
   pix = malloc( 4*80*60 );
   if (SDL_ATassert( "malloc", pix!=NULL ))
      return 1;

   /* Read pixels. */
#if 0
   ret = SDL_RenderReadPixels( NULL, pix, 80*4 );
   if (SDL_ATassert( "SDL_RenderReadPixels", ret==0) )
      return 1;
#else
   int i, j;
   Uint8 *buf = pix;
   const Uint8 *read_pix;
   Uint8 *write_pix;
   for (j=0; j<s->height; j++) {
      for (i=0; i<s->width; i++) {
         read_pix  = &s->pixel_data[ (j*80 + i) * s->bytes_per_pixel ];
         write_pix = &buf[ (j*80 + i) * 4 ];
         write_pix[0] = read_pix[0];
         write_pix[1] = read_pix[1];
         write_pix[2] = read_pix[2];
         write_pix[3] = SDL_ALPHA_OPAQUE;
      }
   }
#endif

   /* Create surface. */
   testsur = SDL_CreateRGBSurfaceFrom( pix, 80, 60, 32, 80*4,
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", testsur!=NULL ))<commit_msg>Work in progress: SDL_RenderReadPixels() should be implemented soon.<commit_after>/**
 * Automated SDL_Surface test.
 *
 * Written by <NAME> "bobbens"
 *
 * Released under Public Domain.
 */


#include "SDL.h"
#include "SDL_at.h"

#include "common/common.h"


/*
 * Pull in images for testcases.
 */
#include "common/images.h"


#define SCREEN_W     80
#define SCREEN_H     60

#define FACE_W       img_face.width
#define FACE_H       img_face.height


/*
 * Prototypes.
 */
static int render_compare( const char *msg, const SurfaceImage_t *s );
static int render_isSupported( int code );
static int render_hasDrawColor (void);
static int render_hasBlendModes (void);
static int render_hasTexColor (void);
static int render_hasTexAlpha (void);
static int render_clearScreen (void);
/* Testcases. */
static int render_testPrimitives (void);
static int render_testPrimitivesBlend (void);
static int render_testBlit (void);
static int render_testBlitColour (void);
static int render_testBlitAlpha (void);
static int render_testBlitBlendMode( SDL_TextureID tface, int mode );
static int render_testBlitBlend (void);


/**
 * @brief Compares screen pixels with image pixels.
 *
 *    @param msg Message on failure.
 *    @param s Image to compare against.
 *    @return 0 on success.
 */
static int render_compare( const char *msg, const SurfaceImage_t *s )
{
   (void) msg;
   (void) s;
   int ret;
   void *pix;
   SDL_Surface *testsur;

   /* Allocate pixel space. */
   pix = malloc( 4*80*60 );
   if (SDL_ATassert( "malloc", pix!=NULL ))
      return 1;

   /* Read pixels. */
   ret = SDL_RenderReadPixels( NULL, pix, 80*4 );
   if (SDL_ATassert( "SDL_RenderReadPixels", ret==0) )
      return 1;

   /* Create surface. */
   testsur = SDL_CreateRGBSurfaceFrom( pix, 80, 60, 32, 80*4,
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", testsur!=NULL ))
{'fraction_non_alphanumeric': 0.12164750957854406, 'fraction_numerical': 0.016283524904214558, 'mean_word_length': 3.5010775862068964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2862054', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1438, 'n_words': 422}