Re: [AD] SF.net SVN: alleg:[12930] allegro/branches/4.9/addons/image

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I'm going to see if this works on OS X too.
When last I looked at this I couldn't figure out how to get the data in any other format than an NSImage, which seemed a bit useless.

On 19 Feb 2010, at 11:48 , elias@xxxxxxxxxx wrote:

> Revision: 12930
>          http://alleg.svn.sourceforge.net/alleg/?rev=12930&view=rev
> Author:   elias
> Date:     2010-02-19 16:48:54 +0000 (Fri, 19 Feb 2010)
> 
> Log Message:
> -----------
> Add support for tif, jpg, gif, png, BMPf, ico, cur, xbm formats to the image addon under IPhone. This means we can now load jpg and png like all the other platforms even though we don't have libpng and libjpeg... and since the iphone natively supports also those other formats I registered their extensions as well.
> 
> Modified Paths:
> --------------
>    allegro/branches/4.9/addons/image/iio.c
> 
> Added Paths:
> -----------
>    allegro/branches/4.9/addons/image/allegro5/internal/aintern_image.h
>    allegro/branches/4.9/addons/image/iphone.m
> 
> Added: allegro/branches/4.9/addons/image/allegro5/internal/aintern_image.h
> ===================================================================
> --- allegro/branches/4.9/addons/image/allegro5/internal/aintern_image.h	                        (rev 0)
> +++ allegro/branches/4.9/addons/image/allegro5/internal/aintern_image.h	2010-02-19 16:48:54 UTC (rev 12930)
> @@ -0,0 +1,4 @@
> +#ifdef ALLEGRO_IPHONE
> +ALLEGRO_IIO_FUNC(ALLEGRO_BITMAP *, _al_iphone_load_image, (const char *filename));
> +ALLEGRO_IIO_FUNC(ALLEGRO_BITMAP *, _al_iphone_load_image_f, (ALLEGRO_FILE *f));
> +#endif
> \ No newline at end of file
> 
> Modified: allegro/branches/4.9/addons/image/iio.c
> ===================================================================
> --- allegro/branches/4.9/addons/image/iio.c	2010-02-18 22:28:11 UTC (rev 12929)
> +++ allegro/branches/4.9/addons/image/iio.c	2010-02-19 16:48:54 UTC (rev 12930)
> @@ -3,6 +3,7 @@
> 
> #include "allegro5/allegro5.h"
> #include "allegro5/allegro_image.h"
> +#include "allegro5/internal/aintern_image.h"
> #include "allegro5/internal/aintern.h"
> #include "allegro5/internal/aintern_vector.h"
> 
> @@ -72,6 +73,15 @@
>    success |= al_register_bitmap_saver_f(".jpeg", al_save_jpg_f);
> #endif
> 
> +#ifdef ALLEGRO_IPHONE
> +   char const *extensions[] = {".tif", ".tiff", ".jpg", ".jpeg", ".gif",
> +      ".png", ".BMPf", ".ico", ".cur", ".xbm", NULL};
> +   for (int i = 0; extensions[i]; i++) {
> +      success |= al_register_bitmap_loader(extensions[i], _al_iphone_load_image);
> +      success |= al_register_bitmap_loader_f(extensions[i], _al_iphone_load_image_f);
> +   }
> +#endif
> +
>    if (success)
>       iio_inited = true;
> 
> 
> Added: allegro/branches/4.9/addons/image/iphone.m
> ===================================================================
> --- allegro/branches/4.9/addons/image/iphone.m	                        (rev 0)
> +++ allegro/branches/4.9/addons/image/iphone.m	2010-02-19 16:48:54 UTC (rev 12930)
> @@ -0,0 +1,93 @@
> +#import <Foundation/Foundation.h>
> +#import <UIKit/UIKit.h>
> +
> +#include "allegro5/allegro5.h"
> +#include "allegro5/fshook.h"
> +#include "allegro5/allegro_image.h"
> +#include "allegro5/internal/aintern_memory.h"
> +#include "allegro5/internal/aintern_image.h"
> +
> +#include "iio.h"
> +
> +
> +/* really_load_png:
> + *  Worker routine, used by load_png and load_memory_png.
> + */
> +static ALLEGRO_BITMAP *really_load_image(char *buffer, int size)
> +{
> +   ALLEGRO_BITMAP *bmp = NULL;
> +   void *pixels = NULL;
> +   /* Note: buffer is now owned (and later freed) by the data object. */
> +   NSData *nsdata = [NSData dataWithBytesNoCopy:buffer length:size];
> +   UIImage *uiimage = [UIImage imageWithData:nsdata];
> +   int w = uiimage.size.width;
> +   int h = uiimage.size.height;
> +
> +   /* Now we need to draw the image into a memory buffer. */
> +   pixels = _AL_MALLOC(w * h * 4);
> +   CGContextRef context = CGBitmapContextCreate(pixels, w, h, 8, w * 4,
> +      CGImageGetColorSpace(uiimage.CGImage),
> +      kCGImageAlphaPremultipliedLast);
> +   CGContextDrawImage(context, CGRectMake(0.0, 0.0, (CGFloat)w, (CGFloat)h),
> +      uiimage.CGImage);
> +   CGContextRelease(context);
> +
> +   /* Then create a bitmap out of the memory buffer. */
> +   bmp = al_create_bitmap(w, h);
> +   if (!bmp) goto done;
> +   ALLEGRO_LOCKED_REGION *lock = al_lock_bitmap(bmp,
> +      ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_WRITEONLY);
> +   for (int i = 0; i < h; i++) {
> +      memcpy(lock->data + lock->pitch * i, pixels + w * 4 * i, w * 4);
> +   }
> +   al_unlock_bitmap(bmp);
> +done:
> +   _AL_FREE(pixels);
> +   return bmp;
> +}
> +
> +
> +/* Function: al_load_png_f
> + *  Load a PNG file from disk, doing colour coversion if required.
> + */
> +ALLEGRO_BITMAP *_al_iphone_load_image_f(ALLEGRO_FILE *f)
> +{
> +   ALLEGRO_BITMAP *bmp;
> +   ASSERT(fp);
> +    
> +   int64_t size = al_fsize(f);
> +   if (size <= 0) {
> +      // TODO: Read from stream until we have the whole image
> +      return NULL;
> +   }
> +   /* Note: This *MUST* be the Apple malloc and not any wrapper, as the
> +    * buffer will be owned and freed by the NSData object not us.
> +    */
> +   void *buffer = malloc(size);
> +   al_fread(f, buffer, size);
> +
> +   /* Really load the image now. */
> +   bmp = really_load_image(buffer, size);
> +   return bmp;
> +}
> +
> +
> +/* Function: al_load_png
> + */
> +ALLEGRO_BITMAP *_al_iphone_load_image(const char *filename)
> +{
> +   ALLEGRO_FILE *fp;
> +   ALLEGRO_BITMAP *bmp;
> +
> +   ASSERT(filename);
> +
> +   fp = al_fopen(filename, "rb");
> +   if (!fp)
> +      return NULL;
> +
> +   bmp = _al_iphone_load_image_f(fp);
> +
> +   al_fclose(fp);
> +
> +   return bmp;
> +}
> 
> 
> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
> 
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Alleg-commits mailing list
> Alleg-commits@xxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/alleg-commits

-- 
Evert Glebbeek
e-mail: eglebbk@xxxxxxxxxx, evertg@xxxxxxxxxx
skype: evertglebbeek
ICQ: 48210348  msn: eglebbk@xxxxxxxxxx
www: http://www.eglebbk.dds.nl/








Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/