OSErr EI_MakeImageDescription(ImageFramePtr frame, long colorCount, UInt8 *color, ImageDescriptionHandle *descOut)
{
	OSErr err = noErr;
	ImageDescriptionHandle desc = NULL;
	ImageDescriptionPtr idp;
	CTabHandle colors = NULL;

	desc = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription));
	if ( (err = MemError()) ) goto bail;

	idp = *desc;
	idp->idSize = sizeof(ImageDescription);					// total size of this image description structure with extra data including color lookup tables and other per sequence data
	idp->cType = FOUR_CHAR_CODE(kEI_Sig);					// type of compressor component that created this compressed image data
	idp->vendor = kAppleManufacturer;						// identifies the developer of the compressor that created the compressed image
	idp->frameCount = 1;									// the number of frames in the image data associated with this description
	idp->depth = frame->frameBitDepth + frame->frameAlpha;	// pixel depth specified for the compressed image
	idp->clutID = -1;										// ID of the color table for the compressed image, -1 if the image does not use a color table 
	idp->hRes = idp->vRes = 72L << 16;									// resolution dpi
	idp->width = EndianU16_BtoN(frame->frameRect.right) - EndianU16_BtoN(frame->frameRect.left);	// image width in pixels
	idp->height = EndianU16_BtoN(frame->frameRect.bottom) - EndianU16_BtoN(frame->frameRect.top);	// image height in pixels
	idp->version = 0;										// the version of the compressed data

	// make up a color table, if there is one
	if (colorCount > 2) {
		int i;

		colors = (CTabHandle)NewHandleClear(sizeof(ColorTable) + colorCount * sizeof(ColorSpec));
		if ( (err = MemError()) ) goto bail;

		(**colors).ctFlags = 0;
		(**colors).ctSeed = GetCTSeed();
		(**colors).ctSize = colorCount - 1;

		for (i=0; i<colorCount; i++) {
			(**colors).ctTable[i].value = i;
			(**colors).ctTable[i].rgb.red   = (color[0] << 8) | color[0];
			(**colors).ctTable[i].rgb.green = (color[1] << 8) | color[1];
			(**colors).ctTable[i].rgb.blue  = (color[2] << 8) | color[2];

			color += 3;
		}
		
		// copy the custom color table into the image description structure
		err = SetImageDescriptionCTable(desc, colors);
		if (err) goto bail;
	}

bail:
	if (colors)
		DisposeCTable(colors);

	if (desc && err) {
		DisposeHandle((Handle)desc);
		desc = NULL;
	}

	*descOut = desc;

	return err;
}
Esempio n. 2
0
int process_first_packet__flac(StreamInfo *si, ogg_page *op, ogg_packet *opckt)
{
    unsigned long serialnoatom[3] = { EndianU32_NtoB(sizeof(serialnoatom)), EndianU32_NtoB(kCookieTypeOggSerialNo),
                                      EndianS32_NtoB(ogg_page_serialno(op)) };
    unsigned long atomhead[2] = { EndianU32_NtoB(opckt->bytes + sizeof(atomhead) - 13), EndianU32_NtoB(kCookieTypeFLACStreaminfo) };

    UInt32 sib = EndianU32_BtoN(* (UInt32 *) (((char *)opckt->packet) + 27));
    si->si_flac.metablocks =  (SInt32) EndianU16_BtoN(* (UInt16 *) (((char *)opckt->packet) + 7));

    sib >>= 4;
    si->si_flac.bps = (sib & 0x1f) + 1;
    sib >>= 5;
    si->numChannels = (sib & 0x07) + 1;
    si->rate = (sib >> 3) & 0xfffff;

    //si->lastMediaInserted = 0;
    si->mediaLength = 0;

    dbg_printf("! -- - flac_first_packet: ch: %d, rate: %ld, bps: %ld\n", si->numChannels, si->rate, si->si_flac.bps);

    PtrAndHand(serialnoatom, si->soundDescExtension, sizeof(serialnoatom)); //check errors?
    PtrAndHand(atomhead, si->soundDescExtension, sizeof(atomhead)); //check errors?
    PtrAndHand((((char *)opckt->packet) + 13), si->soundDescExtension, opckt->bytes - 13); //check errors?

    si->si_flac.state = kFStateReadingComments;

    return 0;
};