Graphics-Raylib

 view release on metacpan or  search on metacpan

XS/XS.xs  view on Meta::CPAN

void
UpdateCamera(camera)
	Camera3D *	camera

void
UpdateMusicStream(music)
	Music	music

void
UpdateSound(sound, data, samplesCount)
	Sound	sound
	const void *	data
	int	samplesCount

void
UpdateTexture(texture, pixels)
	Texture2D	texture
	const void *	pixels

void
UpdateVrTracking(camera)
	Camera3D *	camera

Wave
WaveCopy(wave)
	Wave	wave

void
WaveCrop(wave, initSample, finalSample)
	Wave *	wave
	int	initSample
	int	finalSample

void
WaveFormat(wave, sampleRate, sampleSize, channels)
	Wave *	wave
	int	sampleRate
	int	sampleSize
	int	channels

bool
WindowShouldClose()

Image
LoadImageFromAV(array_ref, color_cb)
    SV *array_ref
    SV *color_cb
  ALIAS:
    LoadImageFromAV_uninitialized_mem = 1
    LoadImageFromAV_transposed = 2
    LoadImageFromAV_transposed_uninitialized_mem = 3
  INIT:
    int i;
    AV *av;
    Color *pixels;
    Image img;
    int literal_color = 0;
    int currwidth = 0;
    IntRectangle where = { 0, 0, 0, 0 };
    ImageSet_t *my_ImageSet = ImageSet;
  PPCODE:
    if (!SvROK(array_ref) || SvTYPE(SvRV(array_ref)) != SVt_PVAV)
        croak("expected ARRAY ref as first argument");
    literal_color = !SvOK(color_cb);
    if (!literal_color && (!SvROK(color_cb) || SvTYPE(SvRV(color_cb)) != SVt_PVCV))
        croak("expected CODE ref as second argument");

    av = (AV*)SvRV(array_ref);
    where.height = av_len(av) + 1;
    for (i = 0; i < where.height; i++) {
        SV** row_sv = av_fetch(av, i, 0);
        if (!row_sv || !SvROK(*row_sv) || SvTYPE(SvRV(*row_sv)) != SVt_PVAV)
            croak("expected ARRAY ref as rows");
        currwidth = av_len((AV*)SvRV(*row_sv)) + 1;
        if (currwidth > where.width)
            where.width = currwidth;
    }
    if (ix & 1) /* Looks cool, try it! */
        Newx(pixels, where.height * where.width, Color);
    else
        Newxz(pixels, where.height * where.width, Color);

    if (ix & 2)
        my_ImageSet = TransposedImageSet;

    EXTEND(SP, 3);
    for (i = 0; i < where.height; i++) {
        AV* row = (AV*)SvRV(*av_fetch(av, i, 0));

        for (int j = 0; j < where.width; j++) {
            SV *ret;
            SV** pixel = av_fetch(row, j, 0);
            if (!pixel) {
                /* do something ? */
            }

            Color color = BLANK;
            if (literal_color && pixel) {
                // No check! stay safe
                color = *(Color *)SvPV_nolen(SvRV(*pixel));
            } else {
                PUSHMARK(SP);
                PUSHs(pixel ? *pixel : &PL_sv_undef);
                PUSHs(sv_2mortal(newSViv(j)));
                PUSHs(sv_2mortal(newSViv(i)));
                PUTBACK;

                call_sv(color_cb, G_SCALAR);
                SPAGAIN;
                SV *ret = POPs;
                if (sv_isa(ret, "Graphics::Raylib::XS::Color"))
                    color = *(Color *)SvPV_nolen(SvRV(ret));
            }

            where = my_ImageSet(pixels, where, color, 1, 1);

        }
    }
    RETVAL = LoadImageEx(pixels, where.width, where.height);
    Safefree(pixels);
    {



( run in 0.314 second using v1.01-cache-2.11-cpan-5511b514fd6 )