All Projects → sonsongithub → Quartz Help Library

sonsongithub / Quartz Help Library

Licence: other
Quartz Help Library for iOS, for image processing on iOS.

Quartz Help Library=======sample imageThis library helps image processing programming on iOS. Currently, it includes a mutual converter CGImage <-> pixel array..You can convert them mutually without complicated codes. // original pixel data int originalWidth = 32; int originalHeight = 32; unsigned char* original = (unsigned char*)malloc(sizeof(unsigned char) * originalWidth * originalHeight); // make test pattern for (int y = 0; y < originalHeight; y++) { for (int x = 0; x < originalWidth; x++) { if (y <= originalHeight / 2 && x <= originalWidth / 2) { original[y * originalWidth + x] = 0; } if (y <= originalHeight / 2 && x > originalWidth / 2) { original[y * originalWidth + x] = 85; } if (y > originalHeight / 2 && x <= originalWidth / 2) { original[y * originalWidth + x] = 170; } if (y > originalHeight / 2 && x > originalWidth / 2) { original[y * originalWidth + x] = 255; } } } CGImageRef image = CGImageGrayColorCreateWithGrayPixelBuffer(original, originalWidth, originalHeight); UIImageView imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:image]]; [self addSubview:imageView]; [imageView release]; How to use======= * Import QuartzCVHelpLibrary.h/m into your project. License=======BSD License.UIImage Quartz Help Library Additions Reference======= - (NSData)PNGRepresentaion;###Return valueAn autoreleased NSData object containing the PNG data, or nil if there was a problem generating the data.###DiscussionYou can obtain PNG data as NSData from UIImage directly. - (NSData*)JPEGRepresentaion;###Return valueAn autoreleased NSData object containing the JPEG data, or nil if there was a problem generating the data. This method uses default JPG compression quiality.###DiscussionYou can obtain JPEG data as NSData from UIImage directly. - (NSData*)JPEGRepresentaionWithCompressionQuality:(float)compressionQuality;###Parameters###compressionQualityThe quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).###Return valueAn autoreleased NSData object containing the JPEG data, or nil if there was a problem generating the data. This method uses default JPG compression quiality.###DiscussionYou can obtain JPEG data as NSData from UIImage directly. - (UIImage*)getRotatedImage;###Return valueAn autoreleased bitmap image as UIImage.###DiscussionBitmap image is copied from UIImage which is rotated according to "imageOrienation" attribute. Therefore, the size of the image you obtain is not as same as the original UIImage's. - (UIImage*)getRotatedImageWithResizing:(float)scale;###Parameters###scaleThe scale factor to used when "imageRef" is resized.###Return valueAn autoreleased bitmap image as UIImage.###DiscussionResized bitmap image is copied from UIImage which is rotated according to "imageOrienation" attribute. Therefore, the size of the image you obtain is not as same as the original UIImage's. - (CGImageRef)createCGImageRotated;###Return valueA new Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.###DiscussionBitmap image is copied from UIImage which is rotated according to "imageOrienation" attribute. Therefore, the size of the image you obtain is not as same as the original UIImage's. - (CGImageRef)createCGImageRotatedWithResizing:(float)scale;###Parameters###scaleThe scale factor to used when "imageRef" is resized.###Return valueA new Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.###DiscussionResized bitmap image is copied from UIImage which is rotated according to "imageOrienation" attribute. Because createCGImageRotatedWithResizing simultaneously resizes image and adjusts rotation of UIImage with low memory usage, this method has to be used in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info.Quartz Help Library Reference======= CGImageRef CGImageCreateWithPNGorJPEGFilePath( CFStringRef filePath );###Parameters###filePathThe full or relative pathname of your image file, as CFStringRef(NSString).###Return valueA new Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.###DiscussionYou can obtain the Quartz bitmap image from the filepath of PNG or JPG file directly. void CGImageDumpImageInformation( CGImageRef imageRef );###Parameters###imageRefThe image to print its information.###DiscussionPrint information of the image to standard output (stdout).The information incudes width, height, bytes per pixel, alpha, byte order, and so on. void CGCreatePixelBufferWithImage( CGImageRef imageRef, unsigned char **pixel, int *width, int *height, int bytesPerPixel, QH_PIXEL_TYPE pType ); ###Parameters###imageRefThe image to be copied.###pixelReturn contains pixel buffer of the image. You are responsible for free this data.###widthReturn contains width of the image.###heightReturn contains pixel of the image.###bytesPerPixelReturn contains bytes per pixel of returned the pixel buffer.###pTypeYour favourite pixel type as specified QH_PIXEL_TYPE when copying pixel buffer.###DiscussionpType is very important. Specifying QH_PIXEL_GRAYSCALE, pixel contains gray scale pixel buffer of the image. And then if the image is RGB or RGBA color scale, it is converted to gray scale automatically. The converting algorithm is based on YUV-RGB(Alpha components are filled with default value as 255). On the contrary, specifying QH_PIXEL_COLOR or QH_PIXEL_ANYCOLOR when the image is gray scale, automatically pixels' each components are filled with each gray scale value except alpha. CGImageRef CGImageCreateWithPixelBuffer( unsigned char pixel, int width, int height, int bytesPerPixel, QH_PIXEL_TYPE target_pType );###Parameters###pixelThe pointer of the pixel buffer to be used to make a new CGImage.###widthWidth of the pixel buffer.###heightHeight of the pixel buffer.###bytesPerPixelBytes per pixel of the pixel buffer.###target_pTypePixel type of the image to be created with above parameters. Specified QH_PIXEL_TYPE.###Return valueA new Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.###DiscussionUpconverting or downconverting is to be done according to your spceifying bytesPerPixel and target_pType, like CGCreatePixelBufferWithImage. I doubt that CGImage supports the image whose format is 24 bit per pixel. So, CGImage this method returns is 8bit or 32bit bitmap. NSData CGImageGetPNGPresentation( CGImageRef imageRef );###Parameters###imageRefThe image to be converted to PNG data.###Return valueAn autoreleased NSData object containing the PNG data, or nil if there was a problem generating the data.###DiscussionTo be written. NSData CGImageGetJPEGPresentation( CGImageRef imageRef );###Parameters###imageRefThe image to be converted to JPG data.###Return valueAn autoreleased NSData object containing the JPG data, or nil if there was a problem generating the data.###DiscussionTo be written. CGImageRef CGImageCreateWithResizing( CGImageRef imageRef, float scale );###Parameters###imageRefThe image to be resized.###scaleThe scale factor to used when "imageRef" is resized.###Return valueA new and rotated Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.###DiscussionThis function has not been tested yet. Be careful of using this function :-) Constants=======###In/Out pixel type typedef enum { QH_PIXEL_GRAYSCALE = 0, QH_PIXEL_COLOR = 1 << 0, QH_PIXEL_ANYCOLOR = 1 << 1, }QH_PIXEL_TYPE; ###QH_PIXEL_GRAYSCALEGray scale pixel for the output/input image. Typically, bits per pixel is 8bits.###QH_PIXEL_COLORRGB color scale pixel for the output/input image. Typically, bits per pixel is 24bits.###QH_PIXEL_ANYCOLORThe appropriate color scale pixel for the output/input image. I believe that it does suit to output/input image format....###Bytes per pixel type typedef enum { QH_BYTES_PER_PIXEL_UNKNOWN = 0, QH_BYTES_PER_PIXEL_8BIT = 1, QH_BYTES_PER_PIXEL_16BIT = 2, QH_BYTES_PER_PIXEL_24BIT = 3, QH_BYTES_PER_PIXEL_32BIT = 4, }QH_BYTES_PER_PIXEL; ###QH_BYTES_PER_PIXEL_UNKNOWNTypically, error.###QH_BYTES_PER_PIXEL_8BITBytes per pixel is 1. In short, bits per pixel is 8 bit. Typically, index color or gray color image.###QH_BYTES_PER_PIXEL_16BITBytes per pixel is 2. In short, bits per pixel is 16 bit. Typically, index color or gray color image with alpha component.###QH_BYTES_PER_PIXEL_24BITBytes per pixel is 3. In short, bits per pixel is 24 bit. Typically, RGB color image.###QH_BYTES_PER_PIXEL_32BITBytes per pixel is 4. In short, bits per pixel is 32 bit. Typically, RGB color image with alpha component. Blog======= * [sonson.jp][]Sorry, Japanese only....Dependency======= * none [Quartz Help Library]: https://github.com/sonsongithub/Quartz-Help-Library[sonson.jp]: http://sonson.jp

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].