Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Converting a 24-bit color to an 8-bit grayscale

 
   Macintosh computer (Home) -> Graphics RSS
Next:  Help wanted on Powerbook 5300c  
Author Message
Joseph Rooney

External


Since: Nov 22, 2005
Posts: 2



(Msg. 1) Posted: Mon Nov 21, 2005 7:55 pm
Post subject: Converting a 24-bit color to an 8-bit grayscale
Archived from groups: comp>sys>mac>graphics (more info?)

This is another point where no matter what I do, I feel as dumb as dirt...
Graphics on the Mac is certainly not my strong suit, and the client's app
is OS8.5.1, using MacApp. As always, any pointers greatly appreciated.

The challenge:

Convert a color PICT in a res file to a monochrome image, and add it back to
the res file as a new resouce.

The problem: CopyBits() is filing the destination with nulls.

The code:

PicHandle TPixel::MakeImageMono()
{
PicHandle thePict = nil;
long lDataLen = 0, lGestaltReturn = 0;
short nUniqueID = 0;
OSErr err = noErr;
PictInfo colorPictInfo, monoPictInfo;
CRect destRect;
CTabHandle theColorTable;
GDHandle hOldGD, hColorGD, hMonoGD;
CGrafPtr oldPort, colorPort, monoPort;
ResNumber nColorPhoto = 128, nMonoPhoto = 129;
GWorldPtr gwColor = nil;
GWorldPtr gwMono = nil;

PixMapHandle hColorMap;
PixMapHandle hMonoMap;

// MacApp File Handling
TFile *testResFile;
FSSpec spec;
CStr255 theName;
short myVRefNum = gApplication->fAppVRefNum;
long myAppDir = gApplication->fAppDir;
short pictRes = 0;

theName = ":Sales:testpict";
err = FSMakeFSSpec(myVRefNum,myAppDir,theName,&spec);

if (err == noErr)
{
testResFile = new TFile;
testResFile->IFile('rsrc','RSED',false,needResourceFork,false,true);
testResFile->Specify(spec);
testResFile->SetPermissions(fsRdWrPerm,fsRdWrPerm);
err = testResFile->OpenFile();
pictRes = testResFile->UseResource();
UseResFile(pictRes);
}

thePict = GetPicture(nColorPhoto);
GetPictInfo(thePict,&colorPictInfo,0,0,0,0);
destRect = (*thePict)->picFrame;


// Open a color port and fill it
if ( (err = NewGWorld(&gwColor,32,destRect,0,nil,0)) == noErr)
{
// Save the current port
GetGWorld(&oldPort, &hOldGD);
SetGWorld(gwColor, 0);
GetGWorld(&colorPort, &hColorGD);

EraseRect( destRect);
hColorMap = GetGWorldPixMap(gwColor);
LockPixels(hColorMap);
// Load the pict into the color grafport
DrawPicture(thePict,destRect);
}


// Load the grayscale colortable and create the mono grafport
theColorTable = GetCTable(40);
if ( (err = NewGWorld(&gwMono,8,destRect,theColorTable,nil,0)) == noErr)
{
hMonoMap = GetGWorldPixMap(gwMono);
GetGWorld(&monoPort, &hMonoGD);

EraseRect( destRect);
SetIfColor(gRGBBlack);
SetIfBkColor(gRGBWhite);
LockPixels(hMonoMap);


CopyBits(&(((GrafPtr)gwColor)->portBits),&(((GrafPtr)gwMono)->portBits),dest
Rect,
destRect,srcCopy,nil);
}


UnlockPixels(hColorMap);
//ClosePicture();

// Make sure our defaults are set

CStr255 theResName = "MonoPictName";
AddResource( (Handle) hMonoMap, 'PICT', nMonoPhoto, theResName);
WriteResource((Handle) hMonoMap);
UnlockPixels(hMonoMap);

err = testResFile->CloseFile();
err = testResFile->FlushVolume();
FreeIfObject(testResFile);

UseResFile(gApplication->fAppRes);
}

 >> Stay informed about: Converting a 24-bit color to an 8-bit grayscale 
Back to top
Login to vote
LarakSCA

External


Since: Nov 23, 2005
Posts: 4



(Msg. 2) Posted: Wed Nov 23, 2005 9:34 am
Post subject: Re: Converting a 24-bit color to an 8-bit grayscale [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Here is where I show I am dumber than dirt.
I am not a programer but I have in the past used ResEdit to swap out a
pict file in an application.
I can't remember even what application or why I did it but it was a
simple affair.
It was a simple copy and paste affair from photoshop.
This was back in OS 8 something.
Michael

 >> Stay informed about: Converting a 24-bit color to an 8-bit grayscale 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
grayscale: 256 (8bits) or better? - Hi all, how many gray steps are required for which practical application? Some software does permit 16 bits grayscale. On the other hand I was told that Mac does/did support 256 gray steps 'only'. How many grays are supported by typical graphic..

Converting pict.jpg to jfif.jpg - have some JPEG-compressed PICT files. When I upload them to my Web site, browsers won't display them. Apparently, PICT is poorly supported. I'd like to put them on the Web without recompressing them. Is there a way to do that?

converting .cdr images to mac readable? - Am snatching myself bald... cannot find a way to convert some corel draw images (.cdr suffix) to something that my G4 iMac sys 10.2.8 can read. (I have tried Graphic Converter 5.8.1 and it will not recognize the files.) Any insight you can provide is..

Display - Color profiles - I'm having a weird problem with my G4/933 14" iBook. I have calibrated the display color profile and chosen it. But the iBook keeps forgetting that it should be chosen, and reverts back to the uncalibrated profile. I'm running 10.3.4. Thanks in adv...

Color StyleWriter Acting Up-Help - I have an older Apple Color StyleRiter 2400 that I got from a friend who ended his use of Mac computers. I had this hooked up on my system a while back and it seemed to be printing OK, save for the fact that the printing was spotty - needed ink. I..
   Macintosh computer (Home) -> Graphics All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]