bool get_decoded_png_imagesize(imageSrcPtr src, int* width, int* height) {
    unsigned long chunkType = UNDF_CHUNK;
    long chunkLength;
    unsigned long CRC;
    pngData data;

    if (!signatureOK(src)) {
        /* not a PNG image */
        return FALSE;
    }

    if (!getChunk(src, &chunkType, &chunkLength)) {
        return FALSE;
    }

    CRC = init_CRC(chunkType);
    if (chunkType != IHDR_CHUNK) {
        return FALSE;
    }        

    if (chunkLength < 13) {
        return FALSE;
    }

    memset(&data, 0, sizeof(data));

    CRC = readHeader(src, chunkLength, &data, CRC);

    if (!headerOK(&data)) {
        return FALSE;
    }

    *width = data.width;
    *height = data.height;
    return TRUE;
}
Esempio n. 2
0
/*
 * Launch the board's firmware. This function must be called after the 
 * firmware was loaded into the board's memory using TPAM_CMD_DSPLOAD 
 * IOCTL commands. After launching the firmware, this function creates
 * the NCOs and waits for their creation.
 *
 * 	card: the board
 *
 * Return: 0 if OK, <0 on errors.
 */
static int tpam_command_ioctl_dsprun(tpam_card *card) {
	u32 signature = 0, timeout, i;
	isdn_ctrl ctrl;
	struct sk_buff *skb;

	dprintk("TurboPAM(tpam_command_ioctl_dsprun): card=%d\n", card->id);

	/* board must _not_ be running */
	if (card->running)
		return -EBUSY;

	/* reset the board */
	spin_lock_irq(&card->lock);
	copy_to_pam_dword(card, (void *)TPAM_MAGICNUMBER_REGISTER, 0xdeadface);
	readl(card->bar0 + TPAM_DSPINT_REGISTER);
	readl(card->bar0 + TPAM_HINTACK_REGISTER);
	spin_unlock_irq(&card->lock);
	
	/* wait for the board signature */
	timeout = jiffies + SIGNATURE_TIMEOUT;
	while (time_before(jiffies, timeout)) {
		spin_lock_irq(&card->lock);
		signature = copy_from_pam_dword(card, 
						(void *)TPAM_MAGICNUMBER_REGISTER);
		spin_unlock_irq(&card->lock);
		if (signature == TPAM_MAGICNUMBER)
			break;
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout(2);
	}

	/* signature not present -> board not started */
	if (signature != TPAM_MAGICNUMBER) {
		printk(KERN_ERR "TurboPAM(tpam_command_ioctl_dsprun): "
		       "card=%d, signature 0x%lx, expected 0x%lx\n", 
		       card->id, (unsigned long)signature, 
		       (unsigned long)TPAM_MAGICNUMBER);
		printk(KERN_ERR "TurboPAM(tpam_command_ioctl_dsprun): "
		       "card=%d, firmware not started\n", card->id);
		return -EIO;
	}

	/* the firmware is started */
	printk(KERN_INFO "TurboPAM: card=%d, firmware started\n", card->id);

	/* init the CRC routines */
	init_CRC();

	/* create all the NCOs */
	for (i = 0; i < TPAM_NBCHANNEL; ++i)
		if ((skb = build_ACreateNCOReq("")))
			tpam_enqueue(card, skb);

	/* wait for NCO creation confirmation */
	timeout = jiffies + NCOCREATE_TIMEOUT;
	while (time_before(jiffies, timeout)) {
		if (card->channels_tested == TPAM_NBCHANNEL)
			break;
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout(2);
	}

	card->running = 1;

	if (card->channels_tested != TPAM_NBCHANNEL)
		printk(KERN_ERR "TurboPAM(tpam_command_ioctl_dsprun): "
		       "card=%d, tried to init %d channels, "
		       "got reply from only %d channels\n", card->id, 
		       TPAM_NBCHANNEL, card->channels_tested);

	/* if all the channels were not initialized, signal to the ISDN
	 * link layer that fact that some channels are not usable */
	if (card->channels_used != TPAM_NBCHANNEL)
		for (i = card->channels_used; i < TPAM_NBCHANNEL; ++i) {
			ctrl.driver = card->id;
			ctrl.command = ISDN_STAT_DISCH;
			ctrl.arg = i;
			ctrl.parm.num[0] = 0;
			(* card->interface.statcallb)(&ctrl);
		}

	printk(KERN_INFO "TurboPAM: card=%d, ready, %d channels available\n", 
	       card->id, card->channels_used);

	/* let's rock ! */
	ctrl.driver = card->id;
	ctrl.command = ISDN_STAT_RUN;
	ctrl.arg = 0;
	tpam_statcallb(card, ctrl);

	return 0;
}
static
bool
PNGdecodeImage_real(imageSrcPtr src, imageDstPtr dst, 
		    long *paletteData, unsigned char *transData) {

    bool       OK = TRUE;
    bool saw_IDAT = FALSE,
             saw_PLTE = FALSE,
             saw_tRNS = FALSE;
    pngData      data;

    unsigned long chunkType = UNDF_CHUNK;
    long chunkLength;
    unsigned long CRC;

    if (!signatureOK(src)) {
        goto formaterror;               /* not a PNG image */
    }

    memset(&data, 0, sizeof(data));

    while (getChunk(src, &chunkType, &chunkLength)) {
        CRC = init_CRC(chunkType);

        if (chunkType == IHDR_CHUNK) {
            /* size of header is known.  headerOK => IHDR_CHUNK already seen */
            if ((chunkLength < 13) || headerOK(&data)) {
                goto formaterror;
            }

            CRC = readHeader(src, chunkLength, &data, CRC);

            if (!headerOK(&data)) {
                goto formaterror;
            }

            dst->setSize(dst, data.width, data.height);
            if ((data.colorType & CT_COLOR) == 0) {
                /* grayscale--set up a palette */
                int n = 0;
                long _p[4];

                switch (data.depth) {
                case 1:
                    _p[0] = 0;
                    _p[1] = 0xffffff;
                    n = 2;
                    dst->setColormap(dst, _p, n);
                    break;

                case 2:
                    _p[0] = 0;
                    _p[1] = 0x555555;
                    _p[2] = 0xaaaaaa;
                    _p[3] = 0xffffff;
                    n = 4;
                    dst->setColormap(dst, _p, n);
                    break;

                case 4:
                    {
                    long p[16];

                    for (n = 0; n < 16; ++n) {
                        p[n] = n*0x111111;
                    }

                    dst->setColormap(dst, p, n);
                    }
                    break;

                default:
                    {
                    long p[256];

                    for (n = 0; n < 256; ++n) {
                        p[n] = (n << 16) | (n << 8) | n;
                    }

                    dst->setColormap(dst, p, n);
                    }
                    break;
                }
            }
        } else if (chunkType == PLTE_CHUNK) {

            if ((chunkLength < 0) || (chunkLength > (256 * 3)) ||
                    ((chunkLength % 3) != 0)) {
                goto formaterror;
            }

            if ((data.paletteLength > 0) || saw_IDAT || saw_tRNS) {
                goto formaterror;
            }

            CRC = readPalette(src, chunkLength, &data, paletteData, CRC);
            if (data.palette == NULL) {
                goto formaterror;
            }

            if (data.colorType & CT_PALETTE) {
                dst->setColormap(dst, data.palette, data.paletteLength);
            }

            saw_PLTE = TRUE;
        } else if (chunkType == tRNS_CHUNK) {

            if (saw_IDAT || data.colorType == 4 
                         || data.colorType == 6) {
                goto formaterror;
            }

            CRC = readTransPal(src, chunkLength, &data, transData, CRC);
            if (data.trans == NULL) {
                goto formaterror;
            }

            dst->setTransMap(dst, data.trans, data.transLength,
                             saw_PLTE ? data.paletteLength : -1);

            saw_tRNS = TRUE;
        } else if (chunkType == IDAT_CHUNK) {
            idatInflateData  _data;
            FileObj fileObj;
            HeapManObj heapManObj;

            int compLen = 0;
            int decompLen = data.scanlength * data.height;
            unsigned char *decompBuf;
            long startPos = 0, lastGoodPos = 0;

            saw_IDAT = TRUE;

            if (data.interlace) {
                int i;

                /* decompLen is harder to calculate--there are extra rows! */
                decompLen = 0;
                for (i = 0; i < 7; ++i) {
                    int off    = 7 >> (i/2);            /* 7 7 3 3 1 1 0 */
                    int shift  = 3 - (((i - 1) / 2));   /* 3 3 3 2 2 1 1 */
                    int height = ((data.height + off) >> shift);
                    int width  = findPassWidth(i, &data);

                    data.lineBytes[i] = width;
                    data.passSize[i]  = width * height;

                    decompLen += data.passSize[i];
                }
            } else {