Good morning!
I studied how to get a pixel data information from a image.
But I couldn't understand most it, because it's difficulty complication and difficulty.
actually, I don't need this skill. But I need it when I extend my application "YubiFude".
In other words, I can' t extend if I solved it.
I tried solve a this code↓↓↓(included my comment)
"Returns a read-only pointer to the bytes of a CFData object."
I'll confer together
***********************************************************************************
- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingImage:(UIImage*)image
editingInfo:(NSDictionary*)editingInfo
{
NSLog(@"editingInfo:%@",editingInfo);
// UIImagePickerControllerCropRect = NSRect: {{0, 0}, {640, 425}};
// UIImagePickerControllerOriginalImage = ;
statusButton.hidden = NO;
colorButton.hidden = NO;
fillColorButton.hidden = NO;
doneButton.hidden = NO;
allClearButton.hidden = NO;
layer1ClearButton.hidden = NO;
layer2ClearButton.hidden = NO;
layer3ClearButton.hidden = NO;
saveButton.hidden = NO;
loadButton.hidden = NO;
// イメージピッカーを隠す
[self dismissModalViewControllerAnimated:YES];
// オリジナル画像を取得する
UIImage* originalImage;
originalImage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
// グラフィックスコンテキストを作る、小さくすると無理に引き延ばすのでモザイクがかかる
CGSize size = { 320, 480 };
UIGraphicsBeginImageContext(size);
//Creates a bitmap-based graphics context and makes it the current context.
// 表示する画像のサイズ
CGRect rect;
rect.origin = CGPointZero;//(0, 0)
rect.size = size;
[originalImage drawInRect:rect];
// 描画した画像を取得する
shrinkedImage = UIGraphicsGetImageFromCurrentImageContext();
//Returns an image based on the contents of the current bitmap-based graphics context.
UIGraphicsEndImageContext();
//Removes the current bitmap-based graphics context from the top of the stack.
// CGImageを取得する
CGImageRef cgImage;
cgImage = shrinkedImage.CGImage;
// 画像情報を取得する
//typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */
//typedef __darwin_size_t size_t;
size_t width;//320
size_t height;//480
size_t bitsPerComponent;//8
size_t bitsPerPixel;//32
size_t bytesPerRow;//1280 = 4byte*320
CGColorSpaceRef colorSpace;
CGBitmapInfo bitmapInfo;//8193
bool shouldInterpolate;//true
CGColorRenderingIntent intent;//14081600
width = CGImageGetWidth(cgImage);
height = CGImageGetHeight(cgImage);
bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
bytesPerRow = CGImageGetBytesPerRow(cgImage);
colorSpace = CGImageGetColorSpace(cgImage);
bitmapInfo = CGImageGetBitmapInfo(cgImage);
shouldInterpolate = CGImageGetShouldInterpolate(cgImage);//Returns the interpolation setting for a bitmap image.
intent = CGImageGetRenderingIntent(cgImage);//Returns the rendering intent setting for a bitmap image.
/*kCGRenderingIntentDefault,
kCGRenderingIntentAbsoluteColorimetric,
kCGRenderingIntentRelativeColorimetric,
kCGRenderingIntentPerceptual,
kCGRenderingIntentSaturation*/
// データプロバイダを取得する
CGDataProviderRef dataProvider;// which you use to move data into and out of Quartz.
// CGDataProviderRef allow you to supply Quartz functions with data.
dataProvider = CGImageGetDataProvider(cgImage);//Returns the data provider for a bitmap image.
// ビットマップデータを取得する
CFDataRef data;
//A reference to an immutable CFData object.
UInt8* buffer;
//typedef unsigned char UInt8;
data = CGDataProviderCopyData(dataProvider);//data = 614400byte = 153600(320*480)*4
//Returns a copy of the provider’s data.
buffer = (UInt8*)CFDataGetBytePtr(data);
//Returns a read-only pointer to the bytes of a CFData object.
// ビットマップに効果を与える
NSUInteger i, j;
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
// ピクセルのポインタを取得する
UInt8* tmp;
tmp = buffer + j * bytesPerRow + i * 4;
//
//NSLog(@"tmp:%d",tmp);
// NSLog(@"buffer : %d",buffer);
//NSLog(@"buffer : %d",&buffer);
// RGBの値を取得する
UInt8 r, g, b;
r = *(tmp + 3);//b
g = *(tmp + 2);//g
b = *(tmp + 1);//r
// NSLog(@"\nr:%d\ng;%d\nb:%d",r,g,b);
// 輝度値を計算する
UInt8 y;
y = (77 * r + 28 * g + 151 * b) / 256;//重み付きの平均値
/* この重み付きの平均値 gray は輝度と呼ばれるもので、カラーテレビの信号処理
に使われます。輝度は色の明るさを表します。
重みを付けて平均を取るのは、人の視覚は赤・緑・青に対してそれぞれ感度が異
なるためで、
青 < 赤 < 緑
の順に感度が高くなります。最も感度の高い色に重みを持たせています。
http://www.asahi-net.or.jp/~uc3k-ymd/Glib32/loadbmp.html*/
// 輝度の値をRGB値として設定する
*(tmp + 1) = y;//b
*(tmp + 2) = y;//g
*(tmp + 3) = y;//r
}
}
// 効果を与えたデータを作成する
CFDataRef effectedData;
effectedData = CFDataCreate(NULL, buffer, CFDataGetLength(data));
// 効果を与えたデータプロバイダを作成する
CGDataProviderRef effectedDataProvider;
effectedDataProvider = CGDataProviderCreateWithCFData(effectedData);
// 画像を作成する
// UIImage* effectedImage;
effectedCgImage = CGImageCreate(
width, height,
bitsPerComponent, bitsPerPixel, bytesPerRow,
colorSpace, bitmapInfo, effectedDataProvider,
NULL, shouldInterpolate, intent);
//Creates a bitmap image from data supplied by a data provider.
/*size_t width,
size_t height,
size_t bitsPerComponent,
size_t bitsPerPixel,
size_t bytesPerRow,
CGColorSpaceRef colorspace,
CGBitmapInfo bitmapInfo,
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent
);*/
// effectedImage = [[UIImage alloc] initWithCGImage:effectedCgImage];
// [effectedImage autorelease];
// 画像を表示する
// _imageView.image = effectedImage;
[PaintingView loadImage];
// 作成したデータを解放する
CGImageRelease(effectedCgImage);
CFRelease(effectedDataProvider);
CFRelease(effectedData);
CFRelease(data);
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden = YES;
}
***********************************************************************************
This code is invoked when pushed UIImagePickerController's choose button.
I could understand theacceptation most of code.But I didn't understand this code
buffer = (UInt8*)CFDataGetBytePtr(data);
,,,,,,what isCFDataGetBytePtr??
According to reference,,,
"Returns a read-only pointer to the bytes of a CFData object."
I'll talk to my togeher about this code at tomorrow.
And I don't complete the concept the "pointer".
I'll talk to teacher about it too.
I'd like to complete it tommorow.
***********************************************************************
"We have only more 12 days to go before the deadline."
***********************************************************************