Friday, June 22, 2012

Armenia Time issue on Mac OS X 10.6.8 Snow Leopard


As you know government of Armenia announced a decision on 1/2012 that Armenia will remain permanently on "Winter Timer". As a consequence time on Mac OS X 10.6.8 and many other operating systems like Windows, GNU Linux (Ubuntu) the time was shown incorrectly i.e. it was behind of the actual time.

My bug to Apple filed on 22-May-2012

Summary: System time is an hour ahead of the actual time.
Steps to Reproduce: Set the time to updated automatically with the time zone of Yerevan, Armenia

Expected Results: It should be like here

Actual Results: The system time is an hour ahead

Apple responses to my bug on 22-Jun-2012

Hi Levon,

This is a follow-up regarding Bug ID# 11507120.   

Please update your report directly at for the fastest response.  Please do not email your updates.

Engineering has provided the following information:

We believe this issue has been resolved in OS X 10.7.4.  Please verify this issue with OS X Lion 10.7.4 and update this report with your results.  

Note that the configuration summary indicates the problem was reported against 10.6.8, in which case the one hour discrepancy would be expected on 10.6.8 since that release predates the Armenian government's recent  announcement (1/2012) that the country will remain permanently on "winter time". Thus in the summer months 10.6.8 systems in Armenia will always be 1 hour ahead of actual time.

This issue is resolved in recent releases of OS X that incorporate more recent changes in Time Zone Data. The latest update of OS X Lion contains a Time Zone Data update that observes the new Time Zone schedule in Armenia (i.e. permanent adoption of Winter Time with no further Daylight Savings Time changes ).

OS X 10.7.4
Posted Date:  May 9, 2012

Bug reports requiring your attention will appear under ‘My Originated Problems’.  Please review this bug report and provide the requested information via the Apple Bug Reporter at  Once your report has been updated, Engineering will be alerted of the new information.

Thank you for your assistance in helping us discover and isolate bugs within our products. 

Best Regards,

Developer Bug Reporting Team 
Apple Worldwide Developer Relations


I'm happy to inform that the issue is solved for Mac OS X Lion but still exists on running Snow Leopard hosts. I understand that the version 10.6.8 is prior to Armenia's government decision, but still there are lots of people using Snow Leopard on their Macs, and this issue need to be fixed for them, i.e. if Apple doesn't have any mechanism to fix this kind of situation for 10.6.8 system users, this will be really "pity". Anyway I and many other people will hope that this issue will be fixed in 10.6.9 update of Snow Leopard system if it ever happen.

Thursday, May 24, 2012

Quartz : Getting the diff image of two images

Suppose there are following two images the background may be totally different image, e.g. not just plain color.

Image number one
Image number two

So basically I want to get the diff image of these two images i.e.

Diffed image
The diff image of two images is the image with the same size but the pixels are set to be transparent that haven't been changed. The difference image is constructed from the diff pixels with the color from the second image

Using difference blending mode Actually if we use the difference blending mode it doesn't solve the problem as it doesn't keep right colors of the pixels. If we apply difference blend mode to above 2 images we'll get following

Difference blended image

Which seems to have inverted color but, so after inverted the colors we will get  

Inverted diff blended image
So basically this method doesn't solve the issue, so what we need is to use mask the second image where there are differences. Please find below the Objective-C code implementation of the initially setup problem.

Download link

Solution implementation with Objective-C, tested on iPhone/iPad
- (CGContextRef)createCGContextFromCGImage:(CGImageRef)img
    size_t width = CGImageGetWidth(img);
    size_t height = CGImageGetHeight(img);
    size_t bitsPerComponent = CGImageGetBitsPerComponent(img);
    size_t bytesPerRow = CGImageGetBytesPerRow(img);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); //CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(NULL, // Let CG allocate it for us
                                             kCGImageAlphaNone); // RGBA
    NSAssert(ctx, @"CGContext creation fail");
    return ctx;

- (UIImage*) computeDifferenceOfImage:(CGImageRef)oldImage withImage:(CGImageRef)newImage
    // Return the old image if the newImage is nil
    if (newImage == nil) {
        return [UIImage imageWithCGImage:oldImage];
    // We assume both images are the same size, but it's just a matter of finding the biggest
    // CGRect that contains both image sizes and create the CGContext with that size
    CGRect imageRect = CGRectMake(0, 0,
    // Create our context based on the old image
    CGContextRef ctx = [self createCGContextFromCGImage:oldImage];
    // Draw the old image with the default (normal) blendmode 
    CGContextDrawImage(ctx, imageRect, oldImage);
    // Change the blendmode for the remaining drawing operations
    CGContextSetBlendMode(ctx, kCGBlendModeDifference);
    // Draw the new image "on top" of the old one
    CGContextDrawImage(ctx, imageRect, newImage);
    // Grab the composed CGImage
    CGImageRef diffed = CGBitmapContextCreateImage(ctx);

    // Make the gray color based image black and white based
    const CGFloat myMaskingColors[6] = { 1, 255, 1, 255, 1, 255 };
    // Get the masked image consisting of black and transparent pixels
    CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors(diffed, myMaskingColors);
    // Clean the context
    CGContextClearRect(ctx, imageRect);
    // Fill the context with white color 
    CGContextSetFillColorWithColor(ctx, [[UIColor whiteColor] CGColor]);
    CGContextFillRect(ctx, imageRect);
    CGContextDrawImage(ctx, imageRect, myColorMaskedImage);
    // Memory cleanup 
    // Grab the composed CGImage
    diffed = CGBitmapContextCreateImage(ctx);
    // Close the context 
    // Apply the constructed diff mask to newImage
    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(diffed),
                                        CGImageGetDataProvider(diffed), NULL, false);
    CGImageRef masked = CGImageCreateWithMask(newImage, mask);
    UIImage *finalDiffedImage = [UIImage imageWithCGImage:masked];

    return finalDiffedImage;