Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

109 Zeilen
3.5 KiB

  1. /*
  2. * libpipi Pathetic image processing interface library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software. It comes without any warranty, to
  10. * the extent permitted by applicable law. You can redistribute it
  11. * and/or modify it under the terms of the Do What The Fuck You Want
  12. * To Public License, Version 2, as published by Sam Hocevar. See
  13. * http://sam.zoy.org/wtfpl/COPYING for more details.
  14. */
  15. /*
  16. * coreimage.m: CoreImage (OSX) I/O functions
  17. */
  18. #import "coreimage.h"
  19. #ifdef USE_COCOA
  20. #import <CIImage.h>
  21. static int pipi_free_coreimage(pipi_image_t *img);
  22. pipi_image_t *pipi_load_coreimage(const char *name)
  23. {
  24. NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
  25. NSString *n = [NSString stringWithCString: name];
  26. CIImage *source;
  27. NSURL *url = [NSURL fileURLWithPath:n];
  28. source = [CIImage imageWithContentsOfURL:url];
  29. if(source == NULL) return NULL;
  30. CGRect extent = [source extent];
  31. size_t w = (size_t)extent.size.width;
  32. size_t h = (size_t)extent.size.height;
  33. NSBitmapImageRep * myImage;
  34. myImage = [[NSBitmapImageRep alloc] initWithCIImage:source];
  35. pipi_image_t *img;
  36. img = pipi_new(w, h);
  37. img->p[PIPI_PIXELS_RGBA_C].pixels = [myImage bitmapData];
  38. img->p[PIPI_PIXELS_RGBA_C].w = w;
  39. img->p[PIPI_PIXELS_RGBA_C].h = h;
  40. img->p[PIPI_PIXELS_RGBA_C].pitch = ([myImage bytesPerRow]/8) * img->w;
  41. img->p[PIPI_PIXELS_RGBA_C].bpp = [myImage bitsPerPixel];
  42. img->p[PIPI_PIXELS_RGBA_C].bytes = ([myImage bitsPerPixel]/8) * img->w * img->h;
  43. img->last_modified = PIPI_PIXELS_RGBA_C;
  44. img->codec_priv = (struct pipi_codec_coreimage *) malloc(sizeof(struct pipi_codec_coreimage *));
  45. struct pipi_codec_coreimage *infos = (struct pipi_codec_coreimage *) img->codec_priv;
  46. infos->format = [myImage bitmapFormat];
  47. pipi_pixels_t *p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C);
  48. img->codec_free = pipi_free_coreimage;
  49. [autoreleasepool release];
  50. return img;
  51. }
  52. int pipi_save_coreimage(pipi_image_t *img, const char *name)
  53. {
  54. NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
  55. printf("%d\n", img->last_modified);
  56. pipi_pixels_t *p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C);
  57. NSString *n = [NSString stringWithCString: name];
  58. NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
  59. initWithBitmapDataPlanes:NULL
  60. pixelsWide:p->w
  61. pixelsHigh:p->h
  62. bitsPerSample:8
  63. samplesPerPixel:4
  64. hasAlpha:YES
  65. isPlanar:NO
  66. colorSpaceName:NSCalibratedRGBColorSpace
  67. bitmapFormat: 0//(NSBitmapFormat)img->codec_priv
  68. bytesPerRow:p->w*4
  69. bitsPerPixel:32
  70. ];
  71. if(bitmap == nil) return -1;
  72. memcpy([bitmap bitmapData], p->pixels, p->w*p->h*4);
  73. [[bitmap representationUsingType:NSPNGFileType properties:nil] writeToFile:n atomically:YES];
  74. [autoreleasepool release];
  75. return 1;
  76. }
  77. /*
  78. * XXX: The following functions are local.
  79. */
  80. static int pipi_free_coreimage(pipi_image_t *img)
  81. {
  82. return 0;
  83. }
  84. #endif