2009年5月31日日曜日

Good morning!
I could study bitmap and prepare for the WWDC2009.

when I get and change an information of pixel, I used pointer to access the pixel.
information of pixel is 4 components.
but I use 3components, there are red, green, blue.
I didn't know another component.
I studied it.
I accessed the componets and change value(0~255).
this is a result.

probably, some of pixel data is bloken.
but I don't know it what identity yet.

Because of I‘m lacking skill of drawing emvironment, I'll study it by reference(quarz2d drawing guide).
I spent plenty of time analysys code.
I have to get knowledge about 2D Drawing.

****************************************************************
with only 8 days left until the WWDC2009 started!!
****************************************************************

2009年5月30日土曜日

I studied about a bit map at yesterday.
I understood a algorithm about the bitmap.
See code and explanation below.

*****************************************************************************
//This method is invoked when choose button clicked
- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingImage:(UIImage*)image
editingInfo:(NSDictionary*)editingInfo
{
//Restore the buttons
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;

//Hide an ImagePickerView
[self dismissModalViewControllerAnimated:YES];

//Create a new UIImage object(originalImage) and substitude originalImage for choose Image.
UIImage* originalImage;
originalImage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];

//Create a new CGSize object(size) and initize it.it size is full screen size.
CGSize size = { 320, 480 };
//Creates a bitmap-based graphics context and makes it the current context.
UIGraphicsBeginImageContext(size);

//create a CGRect object for use drawInRect
CGRect rect;
rect.origin = CGPointZero;//(0, 0)
rect.size = size;
[originalImage drawInRect:rect];

//Get an image by use UIGraphicsGetImageFromCurrentImageContext method. //this method is Returns an image based on the contents of the current bitmap-based graphics context.
shrinkedImage = UIGraphicsGetImageFromCurrentImageContext();

//Removes the current bitmap-based graphics context from the top of the stack.
UIGraphicsEndImageContext();



//create the CGIMageRef(cgImage) object and institute cgImage for shrinkedImage.CGImage. //CGImage is UIImage class property. CGImageRef cgImage;
cgImage = shrinkedImage.CGImage;

// get an information about image //__SIZE_TYPE__ is macro and iqual to unsigned int //typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ //typedef __darwin_size_t size_t; unsigned int 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*/
// Create a dataProvider object and get a data provider
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.




//get an information about bit map datas
CFDataRef data;
data = CGDataProviderCopyData(dataProvider);//data = 614400byte = 153600(320*480)*4 //Returns a copy of the provider’s data.

//A reference to an immutable CFData object.
UInt8* buffer;//buffer is a pointer to UItnt8 //typedef unsigned char UInt8;

buffer = (UInt8*)CFDataGetBytePtr(data);
//Returns a read-only pointer to the bytes of a CFData object.

// give the effect of change color per pixel
NSUInteger i, j;
for (j = 0; j < i =" 0;" style="font-weight: bold; font-style: italic; color: rgb(255, 0, 0);"> // get the pointer information /*address space↓↓↓// //___________// //1pixel// //___________// //blue // //___________// //green // //___________// //red // //___________// //next pixel // //___________// //blue // //. // //. // //. */
UInt8* tmp;
tmp = buffer + j * bytesPerRow + i * 4;
//tmpはbufferのメモリ空間を頭から4バイトずつ移動しながらピクセルに効果を与えている。
// RGBの値を取得する
UInt8 r, g, b;
r = *(tmp + 3);//r
g = *(tmp + 2);//g
b = *(tmp + 1);//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) = 255-b;//b *(tmp + 2) = 255-g;//g *(tmp + 3) = 255-r;//r ***************************/

*(tmp + 3) = 0;//r
*(tmp + 2) = g;//g
*(tmp + 1) = 0;//b

}
}
*****************************************************************************
I could get the pixel data of image and various effect to image.
for example gray scale nega


I couldn't understand some a method.((UInt8*)CFDataGetBytePtr(data);)
I'll understand it.

2009年5月28日木曜日

Good morning!

I studied about the bitmap, color coponent and algorithm of my application.

I have problem about my application algorithm.

I use an UIImagePickerController class.

But this class has a few APIs, and it have no API that I want.

I'd like to a get feature that is invoked when cansel button clicked.


Thus I'll make the new method for myproblem is solved.


Next, about the bitmap, color coponent.

These needs knowledge of Quarts2D. 

I got a knowledge of premultiplied alpha value.

Use premultiplied alpha value, so speed up of render.

,,,reference say

"For bitmaps that have an alpha component, whether the color components are already multiplied by the alphavalue. Premultiplied alpha describes a source color whose components are already multiplied by an alpha value. Premultiplying speeds up the rendering of animage bye liminating an extra multiplication operation per color component. For example, inan RGB color space, rendering animage 
with premultiplied alpha eliminates three multiplication operations(red times alpha, green times alpha, 
and blue times alpha)for each pixel in the image."


Bitmap has a difficult  problem.

I studied how to change UIImage to bitmap, and change color component of pixel of  bitmap.

Today, I cold get knowledge the ,,,

size_t macro  a unsigned int.

y = (77 * r + 28 * g + 151 * b) / 256;←this code represent a brightness for human.

concept of pointer of C language.


********************************

I'll study about the bitmap component.

And I'll prepare the attend the technical lab at wwdc2009.





2009年5月27日水曜日

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."

***********************************************************************





2009年5月26日火曜日

Good morning everyone !

I fixed and did analysis of the my native application "YubiFude".

I fixed problem about an algorithm (order of drawing to specified layer).

I completed it. CGLayer objects are good working now.



I did analysis of code of the "YubiFude" application about save and import a image.

It's complication for me.

I don't understand some of this. therefore I'll study it.

But becouse of I could understand some of this, I post the code with comment.

*******************************************************************************

//**********************************************************************
//*******************↓↓↓Save Image to library↓↓↓************************
//**********************************************************************

- (void)saveViewToPhotoLibrary:(id)sender {
    
  CGRect screenRect = [[UIScreen mainScreen] bounds];
    //↑↑↑get the size of window(w:320 h:480)
  UIGraphicsBeginImageContext(screenRect.size);
    //↑↑↑Creates a bitmap-based graphics context and makes it the current context.
    // The drawing environment is pushed onto the graphics context stack immediately.
  CGContextRef ctx = UIGraphicsGetCurrentContext();
    //Returns the current graphics context.ビットマップコンテキストの収集
    //[[UIColor blackColor] set];
  CGContextFillRect(ctx, screenRect);
    //↑↑↑Paints the area contained within the provided rectangle, using the fill color in the current graphics state.
    
  [self.paintingViewController.view.layer renderInContext:ctx];
    //↑↑↑Renders the receiver and its sublayers into the specified context.
    //UIView class has a layer property.It is a CALayer class object 
   
  UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
    //↑↑↑Returns an image based on the contents of the current bitmap-based graphics context.
    
  UIImageWriteToSavedPhotosAlbum(screenImage, 
                                 nil//The object whose selector should be called after the image has been written to the user’s device.
                                 , nil//The selector of the target object to call. This method should be of the form:                        
                                 , nil//An optional pointer to any context-specific data that you want passed to the completion selector.
    );
    //↑↑↑Adds the specified image to the user’s Saved Photos album.
    
  UIGraphicsEndImageContext();    
    //↑↑↑Removes the current bitmap-based graphics context from the top of the stack.
}
//**********************************************************************
//*******************↑↑↑Save Image to library↑↑↑************************
//**********************************************************************


*******************************************************************************
//↓↓↓pushed a loadButton
- (void)showCameraSheet:(id)sender
{
    statusButton.hidden = YES;
    colorButton.hidden = YES;
    fillColorButton.hidden = YES;
    doneButton.hidden = YES;
    allClearButton.hidden = YES;
    layer1ClearButton.hidden = YES;
    layer2ClearButton.hidden = YES;
    layer3ClearButton.hidden = YES;
    saveButton.hidden = YES;
    loadButton.hidden = YES;
    
  // アクションシートを作る:下から出てくるアラートみたいなやつ
  UIActionSheet* sheet;
  sheet = [[UIActionSheet alloc] 
             initWithTitle:@"Add image to current layer" 
             delegate:self 
             cancelButtonTitle:nil 
             destructiveButtonTitle:nil 
             otherButtonTitles:@"Photo Library", @"Saved Photos",@"Cancel" ,nil];
  [sheet autorelease];
    [sheet showInView:self.view];
    
}

- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
  // ボタンインデックスをチェックする、どのボタン押された?
  if (buttonIndex >= 3) {
  return;
  }
    UIImagePickerControllerSourceType sourceType = 0;
  switch (buttonIndex) {
        case 0: {
            sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            // イメージピッカーを作る
            UIImagePickerController* imagePicker;
            imagePicker = [[UIImagePickerController alloc] init];
            [imagePicker autorelease];
            imagePicker.sourceType = sourceType;
            imagePicker.allowsImageEditing = YES;
            imagePicker.delegate = self;
            
            // イメージピッカーを表示する、写真選ぶ画面
            //モーダルな◆ユーザが応答しない限り、そのプログラムの他のコントロールは入力を受け付けない
            [self presentModalViewController:imagePicker animated:YES];
            
            
            break;
        }
        case 1: {
            sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            // イメージピッカーを作る
            UIImagePickerController* imagePicker;
            imagePicker = [[UIImagePickerController alloc] init];
            [imagePicker autorelease];
            imagePicker.sourceType = sourceType;
            imagePicker.allowsImageEditing = YES;
            imagePicker.delegate = self;
            
            // イメージピッカーを表示する
            [self presentModalViewController:imagePicker animated:YES];
            
            break;
        }
        case 2: {//自作キャンセルボタン、デフォルトだとメソッド追加命令不可能
            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];
            //ModalViewControllerの除去
            break;
        }
            
  }
   
  // 使用可能かどうかチェックする(カメラはipodtouchにはないので)
  if (![UIImagePickerController isSourceTypeAvailable:sourceType]) {
        //Returns a Boolean value indicating whether the device supports picking images using the specified source.
  return;
  }
}

- (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;
  rect.size = size;
  [originalImage drawInRect:rect];
  // 描画した画像を取得する
  shrinkedImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
   
  // CGImageを取得する
  CGImageRef cgImage;
  cgImage = shrinkedImage.CGImage;
   
  // 画像情報を取得する
  size_t width;
  size_t height;
  size_t bitsPerComponent;
  size_t bitsPerPixel;
  size_t bytesPerRow;
  CGColorSpaceRef colorSpace;
  CGBitmapInfo bitmapInfo;
  bool shouldInterpolate;
  CGColorRenderingIntent intent;
  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.
   
  // データプロバイダを取得する
  CGDataProviderRef dataProvider;
  dataProvider = CGImageGetDataProvider(cgImage);//Returns the data provider for a bitmap image.
    

   
  // ビットマップデータを取得する
  CFDataRef data;
  UInt8* buffer;
  data = CGDataProviderCopyData(dataProvider);
  buffer = (UInt8*)CFDataGetBytePtr(data);
  // ビットマップに効果を与える
    /* NSUInteger i, j;
     for (j = 0; j < height; j++) {
     for (i = 0; i < width; i++) {
     // ピクセルのポインタを取得する
     UInt8* tmp;
     tmp = buffer + j * bytesPerRow + i * 4;
     
     // RGBの値を取得する
     UInt8 r, g, b;
     r = *(tmp + 3);
     g = *(tmp + 2);
     b = *(tmp + 1);
     
     // 輝度値を計算する
     UInt8 y;
     y = (77 * r + 28 * g + 151 * b) / 256;
     
     // 輝度の値をRGB値として設定する
     *(tmp + 1) = y;
     *(tmp + 2) = y;
     *(tmp + 3) = y;
     }
     }
     */
  // 効果を与えたデータを作成する
  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);
    // effectedImage = [[UIImage alloc] initWithCGImage:effectedCgImage];
    // [effectedImage autorelease];
   
  // 画像を表示する
    // _imageView.image = effectedImage;

  [PaintingView loadImage];
  // 作成したデータを解放する
  CGImageRelease(effectedCgImage);
  CFRelease(effectedDataProvider);
  CFRelease(effectedData);
  CFRelease(data);
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
  // イメージピッカーを隠す
  [self dismissModalViewControllerAnimated:YES];
}

*****************************************************************************


2009年5月25日月曜日

Good morning!

My head is tired...,, because I used my brain hard.


I could load a image of the library to CGLayer object.

********************************************************************

First, load the  image of the  library to UIImage object.

Second, import theUIImage object to CGImageRef type object.

It uses a "CGImage" property of UIImage. ↓↓↓↓↓↓

  CGImageref  = UIImage.CGImage;

Third,  import the CGImageref object image toCGContextRef type object.

It uses this function↓↓↓↓

     CGContextRef = CGLayerGetContext(CGLayerRef);


    CGContextDrawImage(CGContextRef, bounds, CGImageRef);

********************************************************************

It is Completed the import image of library.

But it has a poblem.(↓↓↓iPhone OS programming Guide)


I fixed it by refered to this.

I coomlete the most of  the "YubiFude"application.

But I don't understand some feature and algorithm of  the "YubiFide" application (ex. Import the image of library ).

Therefore, I'll study code of  the "YubiFude" application.



2009年5月24日日曜日

Good morning!


I studied the "YubiFude" application.

I could save the image of PaintingView(UIView class)

and imported image in the photo liblary to the PaintingView(but not complete)

 and changed the value of color and fill color (0.0~1.0→0~255).

I save image of the PaintingView by reffered to this.

 ******code ******

- (void)saveViewToPhotoLibrary:(id)sender {
 
  CGRect screenRect = [[UIScreen mainScreen] bounds];
 //↑↑↑get the size of window:
  UIGraphicsBeginImageContext(screenRect.size);
 //↑↑↑Creates a bitmap-based graphics context and makes it the current context.
 
  CGContextRef ctx = UIGraphicsGetCurrentContext();

  CGContextFillRect(ctx, screenRect);
 //↑↑↑Paints the area contained within the provided rectangle, using the fill color in the current graphics state.
 
  [self.paintingViewController.view.layer renderInContext:ctx];
 //↑↑↑Renders the receiver and its sublayers into the specified context.
 //UIView class has a layer property.It is a CALayer class object  
   
  UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
 //↑↑↑Returns an image based on the contents of the current bitmap-based graphics context.
 
  UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
 //↑↑↑Adds the specified image to the user’s Saved Photos album.
 
  UIGraphicsEndImageContext();  
 //↑↑↑Removes the current bitmap-based graphics context from the top of the stack.
}
***************

Therefore, I could do it.

I could import image in the photo liblary to the PaintingView.

But It's not complete yet.

It is difficulty problem here. ,,, layer problem,,,?

I don't know it well.

Therefore, I'll understand it at tomorrow.