You are not logged in.

#1 2008-07-01 04:43:48

Crayon
Bad Mother Fucker

Screenshot function for GRRLIB 3.0

Because of Redshade's help I was able to make a screenshot function for GRRLIB 3.0.

First you need to include this:

Code:

#include <fat.h>

Add this function to GRRLIB.c:

Code:

/**
 * Make a PNG screenshot on the SD card.
 * @param File Name of the file to write.
 * @return True if every thing worked, false otherwise.
 */
bool GRRLIB_ScrShot(const char* File)
{
    IMGCTX pngContext;
    int ErrorCode = -1;

    if(fatInitDefault() && (pngContext = PNGU_SelectImageFromDevice(File)))
    {
        ErrorCode = PNGU_EncodeFromYCbYCr(pngContext, 640, 480, xfb[fb], 0);
        PNGU_ReleaseImageContext(pngContext);

        if(!fatUnmount(PI_INTERNAL_SD))
        {    // I can only hope it's better than nothing
            fatUnsafeUnmount(PI_INTERNAL_SD);
        }
    }
    return !ErrorCode;
}

Add the definition to GRRLIB.h:

Code:

bool GRRLIB_ScrShot(const char*);

Called it like that in your program:

Code:

    if(GRRLIB_ScrShot("Screenshot.png"))
        strcpy(text, "A screenshot was taken!!!");
    else
        strcpy(text, "Screenshot did not work!!!");

Offline

 

#2 2008-07-01 14:20:08

JustWoody
Member

Re: Screenshot function for GRRLIB 3.0

Nice one Crayon I was just about to look at this so you saved me a job, cheers!smile

Offline

 

#3 2008-07-01 18:43:07

RedShade
Member

Re: Screenshot function for GRRLIB 3.0

You are mounting and unmounting fat throughout the application?

Offline

 

#4 2008-07-01 23:27:47

Crayon
Bad Mother Fucker

Re: Screenshot function for GRRLIB 3.0

RedShade wrote:

You are mounting and unmounting fat throughout the application?

That's part of the code by feesh on this page:
http://wiibrew.org/wiki/Talk:Developmen … Shot.28.29

Because without the fatUnmount I think you can't make multiple screenshot, it only work once.

The solution would be to initialize fat outside GRRLIB. Anyway GGRLIB is a video library.

Offline

 

#5 2008-09-07 00:24:19

CashMan
Member

Re: Screenshot function for GRRLIB 3.0

this is a very good function Crayon, thanks !! smile

Offline

 

#6 2008-09-10 09:29:51

JustWoody
Member

Re: Screenshot function for GRRLIB 3.0

what about making this compatible with PAL by using the rmode to get the size of the screen rather than hard coding it to 640x480?

Offline

 

#7 2008-12-11 06:53:52

Crayon
Bad Mother Fucker

Re: Screenshot function for GRRLIB 3.0

With the new version of libfat the unmount command is not necessary anymore (I think), so the function should look like this:

Code:

/**
 * Make a PNG screenshot on the SD card.
 * @param File Name of the file to write.
 * @return True if every thing worked, false otherwise.
 */
bool GRRLIB_ScrShot(const char* File)
{
    IMGCTX pngContext;
    int ErrorCode = -1;

    if(fatInitDefault() && (pngContext = PNGU_SelectImageFromDevice(File)))
    {
        ErrorCode = PNGU_EncodeFromYCbYCr(pngContext, 640, 480, xfb[fb], 0);
        PNGU_ReleaseImageContext(pngContext);
    }
    return !ErrorCode;
}

The new unmount function is:

Code:

/*
Unmount the partition specified by name.
If there are open files, it will attempt to synchronise them to disc.
*/
extern void fatUnmount (const char* name);

Last edited by Crayon (2008-12-11 07:05:53)

Offline

 

#8 2009-01-12 16:56:48

CashMan
Member

Re: Screenshot function for GRRLIB 3.0

Thanks ! It's work !

Offline

 

Board footer

Powered by FluxBB