There is a simple library or a function for scale a image?
EDIT:
I've found yet a library ( Easy_Accelerated_Image_lib_0.2 ) that can scale a image!
I've another problem, i've try to modify the Easy_Accelerated_Image_lib_0.2
for load a image included in the Eboot with Bin2o!
But the compiler give me too many errors!!!!
I've do this work with graphic.c but if i copy and try to adapt the code with the graphic2d.c i've got many errors
Code: Select all
Image* loadImage(const unsigned char* data, int size)
{
memory_png file;
png_structp pngPtr;
png_infop infoPtr;
unsigned int sigRead = 0;
png_uint_32 width, height;
int bitDepth, colorType, interlaceType, x, y;
u32* line;
Image* image = (Image*) malloc(sizeof(Image));
if (!image) return NULL;
file.file = (char*)data;
file.pos = 0;
file.size = size;
pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (pngPtr == NULL)
{
free(image);
return NULL;
}
png_set_error_fn(pngPtr, (png_voidp) NULL, (png_error_ptr) NULL, NULL);
png_set_read_fn(pngPtr, (png_voidp)&file, user_read_fn);
infoPtr = png_create_info_struct(pngPtr);
if (infoPtr == NULL)
{
free(image);
png_destroy_read_struct(&pngPtr, png_infopp_NULL, png_infopp_NULL);
return NULL;
}
png_init_io(pngPtr, (FILE*)&file);
png_set_sig_bytes(pngPtr, sigRead);
png_read_info(pngPtr, infoPtr);
png_get_IHDR(pngPtr, infoPtr, &width, &height, &bitDepth, &colorType, &interlaceType, int_p_NULL, int_p_NULL);
// can't allow images with width or height greater than 512 or it will crash
// the system.
//
if (width > 512 || height > 512)
{
free(image);
png_destroy_read_struct(&pngPtr, png_infopp_NULL, png_infopp_NULL);
return NULL;
}
// attempt to allocate memory for new image
//
img = (Image*)malloc(sizeof(Image));
if( img == NULL )
return NULL;
img->swizzled = 0;
img->width = width;
img->height = height;
img->origWidth = width;
img->origHeight = height;
img->texWidth = nextPowOf2(width);
img->texHeight = nextPowOf2(height);
png_set_strip_16(pngPtr);
png_set_packing(pngPtr);
if (colorType == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(pngPtr);
if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8)
png_set_gray_1_2_4_to_8(pngPtr);
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(pngPtr);
png_set_filler(pngPtr, 0xff, PNG_FILLER_AFTER);
//img->data = malloc(width * height * sizeof(u32));
img->data = (unsigned char*)malloc( img->texWidth * img->height * sizeof(u32));
if (!img->data)
{
png_destroy_read_struct(&pngPtr, png_infopp_NULL, png_infopp_NULL);
free(img);
return NULL;
}
line = (u32*) malloc(width * 4);
if (!line)
{
free(img);
free(img->data);
png_destroy_read_struct(&pngPtr, png_infopp_NULL, png_infopp_NULL);
return NULL;
}
u32* data = (u32*)img->data;
for (y = 0; y < height; y++)
{
png_read_row(pngPtr, (u8*) line, png_bytep_NULL);
for (x = 0; x < width; x++)
{
u32 color = line[x];
data[x + y * img->texWidth] = color;
}
}
// Png's are 32-bit color? so...
//
img->colorMode = 32 / 8; // i'm not sure about this
free(line);
png_read_end(pngPtr, infoPtr);
png_destroy_read_struct(&pngPtr, &infoPtr, png_infopp_NULL);
if( (img->height % 8) == 0 )
swizzleImage(img);
createImageVerts(img);
return img;
}
Code: Select all
Image* loadImage(const unsigned char* data, int size)
Code: Select all
main.c: In function 'loadImage':
main.c:7: error: expected declaration specifiers before 'asm'
main.c:7: error: storage class specified for parameter '__lib_ent_top'
main.c:7: error: storage class specified for parameter '__lib_ent_bottom'
main.c:7: error: storage class specified for parameter '__lib_stub_top'
main.c:7: error: storage class specified for parameter '__lib_stub_bottom'
main.c:7: error: parameter 'module_info' is initialized
main.c:7: error: section attribute not allowed for 'module_info'
main.c:7: error: alignment may not be specified for 'module_info'
main.c:20: error: storage class specified for parameter 'sfondo_start'
main.c:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
main.c:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
main.c:41: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
main.c:53: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
main.c:68: error: old-style parameter declarations in prototyped function definition
main.c:68: error: expected '{' at end of input
make.exe: *** [main.o] Error 1
Code: Select all
int main()
{
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
Image* backgroundImg;
backgroundImg = loadImage(sfondo_start, 0);
startDrawing();
drawImage(backgroundImg,0,0,0.0f);
endDrawing();
flipScreen();
endGraphics();
freeImage(backgroundImg);
sceKernelSleepThread();
return 0;
}
Code: Select all
TARGET = main
OBJS = main.o graphics2d.o sfondo.o
CFLAGS = -O2 -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS = -lmad -lpspaudiolib -lpspaudio -lpsppower -lpspgum -lpspgu -lpng -lz -lm
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = File Select
include $(PSPSDK)/lib/build.mak
sfondo.o: sfondo.png
bin2o -i sfondo.png sfondo.o sfondo