-
1. Re: How to use ADMDrawSuite::DrawAGMImage();
minimum99 Oct 22, 2010 10:04 AM (in response to starnight1981)I am trying to do the same thing but I have not all the way done yet but you can start with these:
My current approach is:
AIRasterizeSettings settings;
//settings.type = kRasterizeRGB; //RGB no alpha
settings.type = kRasterizeARGB; //RGB with alpha
settings.resolution = 72;
settings.antialiasing = 0;
settings.preserveSpotColors = false;
settings.options = kRasterizeOptionsNone ;
settings.ccoptions = AIColorConvertOptions::kDefault;//Converts a jpg image to raster image
AIRasterRecord info;
AIRealMatrix matrix;
sArtSet->AddArtToArtSet(imageSet, art); //art is the original jpg image
sArt->GetArtBounds(art, &artBounds);
sRasterize->Rasterize(imageSet, &settings, &artBounds, kPlaceAbove, art, &raster, NULL);// then scale it with AIRealMatrixSetScale and ConcatRasterMatrix like this:
AIReal wr = fabs(width/(artBounds.right - artBounds.left)); //width and height is the final pixel dimension of your image
AIReal hr = fabs(height/(artBounds.bottom - artBounds.top));sMath->AIRealMatrixSetScale(&matrix, wr, hr);
sRaster->ConcatRasterMatrix(raster, &matrix);//At this point the raster image is scaled for the item in your dialog, now we get the info of the scaled image:
sRaster->GetRasterInfo(raster, &info);
width = info.bounds.right;
height = info.bounds.bottom;
long bytesPerPx = info.bitsPerPixel/8;//Next fill a temp buffer with the pixel data from the scaled image
//Calculate number pixels required. Use this to get a local buffer.
long byteCount = width * height * bytesPerPx;
error = sBlock->AllocateBlock(byteCount, &data); if (error) goto error;g->imageRef = sImage->Create(width, height, 0); //0 mean no alpha
//get pixels from raster image
AISlice artSlice; //When copying from the raster art object to local data, GetRasterTile() iterates over art slices.
AISlice workSlice;//When copying from the local data to the raster art object, SetRasterTile() iterates over work slices.
artSlice.top = 0; artSlice.left = 0; artSlice.bottom = height; artSlice.right = width; artSlice.front = 0; artSlice.back = 3;
workSlice = artSlice;
AITile workTile;workTile.data = data;//A pointer to the memory containing the local copy of the pixels.
workTile.bounds = artSlice
workTile.channelInterleave[0] = 0;.
workTile.channelInterleave[1] = 1;
workTile.channelInterleave[2] = 2;
workTile.channelInterleave[3] = 3;
workTile.rowBytes = byteWidth;//The number of bytes in a row of pixel data.
workTile.colBytes = bytesPerPx;//The number of bytes used to specify a single pixel.
workTile.planeBytes = 0;//When 0, the tile receives all color data for a single pixel together.//This next line will place the pixels into the data buffer
error = sRaster->GetRasterTile(raster, &artSlice, &workTile, &workSlice); if (error) goto error;//Now get the pixel data from data buffer to the ADMImage
ADMPoint inPoint;
ADMRGBColor inColor;
unsigned char *byte = (unsigned char *)data;
unsigned short alpha;
sImage->BeginBaseAddressAccess(g->imageRef);
for (long m=0; m<height; m++) {
for (long k=0; k<byteWidth; k++) {
inPoint.v = m;
inPoint.h = k;
alpha = *byte++;
inColor.red = *byte++;
inColor.green = *byte++;
inColor.blue = *byte++;
//*byte++ = 1;
error = sImage->SetPixel(g->imageRef, &inPoint, &inColor); if (error) goto error;
}
}
sImage->EndBaseAddressAccess(g->imageRef);
//sArt->DisposeArt(raster);
sBlock->DisposeBlock(data);//At this point the scaled raster is in the ADMImage and we can use it in the drawer callback routine to draw
void image_dialog_entry_draw_proc(ADMEntryRef entry, ADMDrawerRef drawer)
{ADMPoint p; p.h = p.v = 0;
if(g->imageRef)
sDrawer->DrawADMImage(drawer, g->imageRef, &p);//ADMDrawerSuite7
}you should use a path filled with known RGB color instead of a jpg image to test it and look at the ADMImage buffer to debug.
This is what works so far and :
- raster and scaled the jpg image
What is partially working:
- the data in the ADMImage has correct red, green and alpha but the blue is always zero.
-
2. Re: How to use ADMDrawSuite::DrawAGMImage();
minimum99 Oct 22, 2010 1:54 PM (in response to minimum99)I found out what the problem was with the blue.
It is documented anywhere!
So, everything works now.

