forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scale a image

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Sat Mar 29, 2008 9:02 pm    Post subject: Scale a image Reply with quote

I've try to modify the graphic.c lib for scale a image to a custom value but the PSP crash when the image is load!
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:

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;

}


And this is the line in graphics2d.h

Code:


Image* loadImage(const unsigned char* data, int size)



I've read this code a lot of times! But I haven't find the errors

Code:

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


And here is the main function
Code:

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;
}

Makefile:
Code:

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group