Transparent Knickers Wrap-up (Alpha)
Transparent Knickers Wrap-up (Alpha)
- Subject: Transparent Knickers Wrap-up (Alpha)
- From: kevin <email@hidden>
- Date: Sat, 01 Sep 2001 10:51:31 +1200
Finally caught up on the backlog (sleep mainly, I just lovit when a new
language just grabs you and you don't sleep for days |-) ) thanks to
everyone for the clues and examples on Alpha and here's something that works
if passed exactly the right 2 TIFF graphics ;-)
[NSThanks from:kevin]
#import "myController.h"
struct PixelColors
{
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
};
@implementation myController
- (IBAction)makeTransparent:(id)sender
{
NSImage *myOutImage;
NSImage *myInImage;
NSImage *myMaskImage;
NSArray *myReps;
NSArray *myMaskReps;
int i,j;
struct PixelColors myColour;
struct PixelColors myMaskColour;
NSBitmapImageRep *myOutBitmap;
NSBitmapImageRep *myInBitmap;
NSBitmapImageRep *myMaskBitmap;
unsigned char *myInPixels;
unsigned char *myOutPixels;
unsigned char *myMaskPixels;
NSData *myBox;
myInImage = [myStartImg image];
myMaskImage = [myMask image];
myReps = [myInImage representations];
myMaskReps = [myMaskImage representations];
myInBitmap = [myReps objectAtIndex:0];
myMaskBitmap = [myMaskReps objectAtIndex:0];
// set size here
imageSize.width = [myInBitmap pixelsWide];
imageSize.height = [myInBitmap pixelsHigh];
[myMaskBitmap setSize:imageSize];
// NSLog( @"The Mask is bits per Sample %i and samples Per Pixel %i ",
// [myMaskBitmap bitsPerPixel] ,
// [myMaskBitmap samplesPerPixel] );
myOutBitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL // let the class
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8 // magic numbers
samplesPerPixel:4 //count the componets
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0 ];
myOutPixels = [myOutBitmap bitmapData];
myInPixels = [myInBitmap bitmapData];
myMaskPixels = [myMaskBitmap bitmapData];
for( j = 0; j < imageSize.height; j++ )
{
for( i = 0 ; i < imageSize.width; i++ )
{
myColour.red = *myInPixels++;
myColour.green = *myInPixels++;
myColour.blue = *myInPixels++;
myMaskColour.red = *myMaskPixels++;
myMaskColour.green = *myMaskPixels++;
myMaskColour.blue = *myMaskPixels++;
myColour.alpha = myMaskColour.red; // or whatever you wish to use
*myOutPixels++ = myColour.red;
*myOutPixels++ = myColour.green;
*myOutPixels++ = myColour.blue;
*myOutPixels++ = myColour.alpha;
}
}
// lets just dump the ourput to file
myOutImage = [[NSImage alloc] initWithSize: imageSize];
[myOutImage addRepresentation: myOutBitmap];
[myEndImg setImage: myOutImage ];
myReps = [myOutImage representations];
myBox =[NSBitmapImageRep TIFFRepresentationOfImageRepsInArray:myReps];
[myBox writeToFile:@"lookhere.tiff" atomically:YES];
}
- (id ) init
{
[super init];
imageSize.width = 128;
imageSize.height = 128;
return self;
}
@end
{\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77
Helvetica;} {\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh9000\viewkind0
\pard\tx1440\tx2880\tx4320\tx5760\tx7200\ql\qnatural \f0\fs24 \cf0
Finally caught up on the backlog (sleep mainly, I just lovit when a new
language just grabs you and you don't sleep for days |-) ) thanks to
everyone for the clues and examples on Alpha and here's something that
works if passed exactly the right 2 TIFF graphics ;-) \ \ [NSThanks