Exemple #1
0
/* Handle after a dma read
 */
static void at91mci_post_dma_read(struct at91mci_host* host)
{
	struct mmc_command* cmd;
	struct mmc_data* data;

	DBG("post dma read\n");

	cmd = host->cmd;
	if (!cmd) {
		DBG("no command\n");
		return;
	}

	data = cmd->data;
	if (!data) {
		DBG("no data\n");
		return;
	}

	while (host->in_use_index < host->transfer_index) {
		unsigned int* buffer;
		int index;
		int len;

		struct scatterlist* sg;

		DBG("finishing index %d\n", host->in_use_index);

		sg = &data->sg[host->in_use_index++];

		DBG("Unmapping page %08X\n", sg->dma_address);

		dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE);

		/* Swap the contents of the buffer */
		buffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
		DBG("buffer = %p, length = %d\n", buffer, sg->length);

		data->bytes_xfered += sg->length;

		len = sg->length / 4;

		for (index = 0; index < len; index++) {
			buffer[index] = BYTE_SWAP4(buffer[index]);
		}
		flush_dcache_page(sg->page);
		kunmap_atomic(sg->page, KM_BIO_SRC_IRQ);
	}

	/* Is there another transfer to trigger? */
	if (host->transfer_index < data->sg_len) {
		at91mci_pre_dma_read(host);
	}
	else {
		controller->MCI_IER = AT91C_MCI_RXBUFF;
		controller->MCI_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;
	}

	DBG("post dma read done\n");
}
Exemple #2
0
quint32 _ntohl(quint32 x) {
    if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
        return x;
    }
    else {
        return BYTE_SWAP4(x);
    }
}
Exemple #3
0
/*
 * Copy from sg to a dma block - used for transfers
 */
static inline void at91mci_sg_to_dma(struct at91mci_host* host, struct mmc_data* data)
{
	unsigned int len, i, size;
	unsigned* dmabuf = host->buffer;

	size = host->total_length;

	len = data->sg_len;

	/*
	 * Just loop through all entries. Size might not
	 * be the entire list though so make sure that
	 * we do not transfer too much.
	 */
	for (i = 0;i < len;i++)
	{
		struct scatterlist* sg;
		int amount;
		int index;
		unsigned int* sgbuffer;

		sg = &data->sg[i];

		sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
		amount = min(size, sg->length);
		size -= amount;
		amount /= 4;

		for (index = 0; index < amount; index++) {
			*dmabuf++ = BYTE_SWAP4(sgbuffer[index]);
		}
		kunmap_atomic(sg->page, KM_BIO_SRC_IRQ);

		if (size == 0)
			break;
	}

	/*
	 * Check that we didn't get a request to transfer
	 * more data than can fit into the SG list.
	 */
	BUG_ON(size != 0);
}
Exemple #4
0
// load the jpeg2000 file format
bool wxJPEG2000Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)
{
	opj_dparameters_t parameters;	/* decompression parameters */
	opj_event_mgr_t event_mgr;		/* event manager */
	opj_image_t *opjimage = NULL;
	unsigned char *src = NULL;
    unsigned char *ptr;
	int file_length, jp2c_point, jp2h_point;
	unsigned long int jp2hboxlen, jp2cboxlen;
	opj_codestream_info_t cstr_info;  /* Codestream information structure */
    unsigned char hdr[24];
	int jpfamform;

	// destroy the image
    image->Destroy();

	/* read the beginning of the file to check the type */ 
    if (!stream.Read(hdr, WXSIZEOF(hdr)))
        return false;
	if ((jpfamform = jpeg2000familytype(hdr, WXSIZEOF(hdr))) < 0)
		return false;
	stream.SeekI(0, wxFromStart);

	/* handle to a decompressor */
	opj_dinfo_t* dinfo = NULL;	
	opj_cio_t *cio = NULL;

	/* configure the event callbacks */
	memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
	event_mgr.error_handler = jpeg2000_error_callback;
	event_mgr.warning_handler = jpeg2000_warning_callback;
	event_mgr.info_handler = jpeg2000_info_callback;

	/* set decoding parameters to default values */
	opj_set_default_decoder_parameters(&parameters);

	/* prepare parameters */
	strncpy(parameters.infile, "", sizeof(parameters.infile) - 1);
	strncpy(parameters.outfile, "", sizeof(parameters.outfile) - 1);
	parameters.decod_format = jpfamform;
	parameters.cod_format = BMP_DFMT;
	if (m_reducefactor)
		parameters.cp_reduce = m_reducefactor;
	if (m_qualitylayers)
		parameters.cp_layer = m_qualitylayers;
	/*if (n_components)
		parameters. = n_components;*/

	/* JPWL only */
#ifdef USE_JPWL
	parameters.jpwl_exp_comps = m_expcomps;
	parameters.jpwl_max_tiles = m_maxtiles;
	parameters.jpwl_correct = m_enablejpwl;
#endif /* USE_JPWL */

	/* get a decoder handle */
	if (jpfamform == JP2_CFMT || jpfamform == MJ2_CFMT)
		dinfo = opj_create_decompress(CODEC_JP2);
	else if (jpfamform == J2K_CFMT)
		dinfo = opj_create_decompress(CODEC_J2K);
	else
		return false;

	/* find length of the stream */
	stream.SeekI(0, wxFromEnd);
	file_length = (int) stream.TellI();

	/* it's a movie */
	if (jpfamform == MJ2_CFMT) {
		/* search for the first codestream box and the movie header box  */
		jp2c_point = searchjpeg2000c(stream, file_length, m_framenum);
		jp2h_point = searchjpeg2000headerbox(stream, file_length);

		// read the jp2h box and store it
		stream.SeekI(jp2h_point, wxFromStart);
		stream.Read(&jp2hboxlen, sizeof(unsigned long int));
		jp2hboxlen = BYTE_SWAP4(jp2hboxlen);

		// read the jp2c box and store it
		stream.SeekI(jp2c_point, wxFromStart);
		stream.Read(&jp2cboxlen, sizeof(unsigned long int));
		jp2cboxlen = BYTE_SWAP4(jp2cboxlen);

		// malloc memory source
		src = (unsigned char *) malloc(jpeg2000headSIZE + jp2hboxlen + jp2cboxlen);

		// copy the jP and ftyp
		memcpy(src, jpeg2000head, jpeg2000headSIZE);

		// copy the jp2h
		stream.SeekI(jp2h_point, wxFromStart);
		stream.Read(&src[jpeg2000headSIZE], jp2hboxlen);

		// copy the jp2c
		stream.SeekI(jp2c_point, wxFromStart);
		stream.Read(&src[jpeg2000headSIZE + jp2hboxlen], jp2cboxlen);
	} else 	if (jpfamform == JP2_CFMT || jpfamform == J2K_CFMT) {
		/* It's a plain image */
		/* get data */
		stream.SeekI(0, wxFromStart);
		src = (unsigned char *) malloc(file_length);
		stream.Read(src, file_length);
	} else
		return false;

	/* catch events using our callbacks and give a local context */
	opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);

	/* setup the decoder decoding parameters using user parameters */
	opj_setup_decoder(dinfo, &parameters);

	/* open a byte stream */
	if (jpfamform == MJ2_CFMT)
		cio = opj_cio_open((opj_common_ptr)dinfo, src, jpeg2000headSIZE + jp2hboxlen + jp2cboxlen);
	else if (jpfamform == JP2_CFMT || jpfamform == J2K_CFMT)
		cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
	else {
		free(src);
		return false;
	}

	/* decode the stream and fill the image structure */
	opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);
	if (!opjimage) {
		wxMutexGuiEnter();
		wxLogError(wxT("JPEG 2000 failed to decode image!"));
		wxMutexGuiLeave();
		opj_destroy_decompress(dinfo);
		opj_cio_close(cio);
		free(src);
		return false;
	}

	/* close the byte stream */
	opj_cio_close(cio);

	/*

	- At this point, we have the structure "opjimage" that is filled with decompressed
	  data, as processed by the OpenJPEG decompression engine

	- We need to fill the class "image" with the proper pixel sample values

	*/
	{
		int shiftbpp;
		int c, tempcomps;

		// check components number
		if (m_components > opjimage->numcomps)
			m_components = opjimage->numcomps;

		// check image depth (only on the first one, for now)
		if (m_components)
			shiftbpp = opjimage->comps[m_components - 1].prec - 8;
		else
			shiftbpp = opjimage->comps[0].prec - 8;

		// prepare image size
		if (m_components)
			image->Create(opjimage->comps[m_components - 1].w, opjimage->comps[m_components - 1].h, true);
		else
			image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true);

		// access image raw data
		image->SetMask(false);
		ptr = image->GetData();

		// workaround for components different from 1 or 3
		if ((opjimage->numcomps != 1) && (opjimage->numcomps != 3)) {
#ifndef __WXGTK__ 
			wxMutexGuiEnter();
#endif /* __WXGTK__ */
			wxLogMessage(wxT("JPEG2000: weird number of components"));
#ifndef __WXGTK__ 
			wxMutexGuiLeave();
#endif /* __WXGTK__ */
			tempcomps = 1;
		} else
			tempcomps = opjimage->numcomps;

		// workaround for subsampled components
		for (c = 1; c < tempcomps; c++) {
			if ((opjimage->comps[c].w != opjimage->comps[c - 1].w) || (opjimage->comps[c].h != opjimage->comps[c - 1].h)) {
				tempcomps = 1;
				break;
			}
		}

		// workaround for different precision components
		for (c = 1; c < tempcomps; c++) {
			if (opjimage->comps[c].bpp != opjimage->comps[c - 1].bpp) {
				tempcomps = 1;
				break;
			}
		}

		// only one component selected
		if (m_components)
			tempcomps = 1;

		// RGB color picture
		if (tempcomps == 3) {
			int row, col;
			int *r = opjimage->comps[0].data;
			int *g = opjimage->comps[1].data;
			int *b = opjimage->comps[2].data;
			if (shiftbpp > 0) {
				for (row = 0; row < opjimage->comps[0].h; row++) {
					for (col = 0; col < opjimage->comps[0].w; col++) {
						
						*(ptr++) = (*(r++)) >> shiftbpp;
						*(ptr++) = (*(g++)) >> shiftbpp;
						*(ptr++) = (*(b++)) >> shiftbpp;

					}
				}

			} else if (shiftbpp < 0) {
				for (row = 0; row < opjimage->comps[0].h; row++) {
					for (col = 0; col < opjimage->comps[0].w; col++) {
						
						*(ptr++) = (*(r++)) << -shiftbpp;
						*(ptr++) = (*(g++)) << -shiftbpp;
						*(ptr++) = (*(b++)) << -shiftbpp;

					}
				}
				
			} else {
				for (row = 0; row < opjimage->comps[0].h; row++) {
					for (col = 0; col < opjimage->comps[0].w; col++) {

						*(ptr++) = *(r++);
						*(ptr++) = *(g++);
						*(ptr++) = *(b++);
					
					}
				}
			}
		}
// load the mj2 file format
bool wxMJ2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)
{
	opj_dparameters_t parameters;	/* decompression parameters */
	opj_event_mgr_t event_mgr;		/* event manager */
	opj_image_t *opjimage = NULL;
	unsigned char *src = NULL;
    unsigned char *ptr;
	int file_length, jp2c_point, jp2h_point;
	unsigned long int jp2hboxlen, jp2cboxlen;
	opj_codestream_info_t cstr_info;  /* Codestream information structure */

	// destroy the image
    image->Destroy();

	/* handle to a decompressor */
	opj_dinfo_t* dinfo = NULL;	
	opj_cio_t *cio = NULL;

	/* configure the event callbacks (not required) */
	memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
	event_mgr.error_handler = mj2_error_callback;
	event_mgr.warning_handler = mj2_warning_callback;
	event_mgr.info_handler = mj2_info_callback;

	/* set decoding parameters to default values */
	opj_set_default_decoder_parameters(&parameters);

	/* prepare parameters */
	strncpy(parameters.infile, "", sizeof(parameters.infile)-1);
	strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1);
	parameters.decod_format = JP2_CFMT;
	parameters.cod_format = BMP_DFMT;
	if (m_reducefactor)
		parameters.cp_reduce = m_reducefactor;
	if (m_qualitylayers)
		parameters.cp_layer = m_qualitylayers;
	/*if (n_components)
		parameters. = n_components;*/

	/* JPWL only */
#ifdef USE_JPWL
	parameters.jpwl_exp_comps = m_expcomps;
	parameters.jpwl_max_tiles = m_maxtiles;
	parameters.jpwl_correct = m_enablejpwl;
#endif /* USE_JPWL */

	/* get a decoder handle */
	dinfo = opj_create_decompress(CODEC_JP2);

	/* find length of the stream */
	stream.SeekI(0, wxFromEnd);
	file_length = (int) stream.TellI();

	/* search for the first codestream box and the movie header box  */
	jp2c_point = searchjp2c(stream, file_length, m_framenum);
	jp2h_point = searchjpegheaderbox(stream, file_length);

	// read the jp2h box and store it
	stream.SeekI(jp2h_point, wxFromStart);
	stream.Read(&jp2hboxlen, sizeof(unsigned long int));
	jp2hboxlen = BYTE_SWAP4(jp2hboxlen);

	// read the jp2c box and store it
	stream.SeekI(jp2c_point, wxFromStart);
	stream.Read(&jp2cboxlen, sizeof(unsigned long int));
	jp2cboxlen = BYTE_SWAP4(jp2cboxlen);

	// malloc memory source
    src = (unsigned char *) malloc(my_jPheadSIZE + jp2hboxlen + jp2cboxlen);

	// copy the jP and ftyp
	memcpy(src, my_jPhead, my_jPheadSIZE);

	// copy the jp2h
	stream.SeekI(jp2h_point, wxFromStart);
	stream.Read(&src[my_jPheadSIZE], jp2hboxlen);

	// copy the jp2c
	stream.SeekI(jp2c_point, wxFromStart);
	stream.Read(&src[my_jPheadSIZE + jp2hboxlen], jp2cboxlen);

	/* catch events using our callbacks and give a local context */
	opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);

	/* setup the decoder decoding parameters using user parameters */
	opj_setup_decoder(dinfo, &parameters);

	/* open a byte stream */
	cio = opj_cio_open((opj_common_ptr)dinfo, src, my_jPheadSIZE + jp2hboxlen + jp2cboxlen);

	/* decode the stream and fill the image structure */
	opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);
	if (!opjimage) {
		wxMutexGuiEnter();
		wxLogError(wxT("MJ2: failed to decode image!"));
		wxMutexGuiLeave();
		opj_destroy_decompress(dinfo);
		opj_cio_close(cio);
		free(src);
		return false;
	}

	/* close the byte stream */
	opj_cio_close(cio);

	/* common rendering method */
#include "imagjpeg2000.cpp"

    wxMutexGuiEnter();
    wxLogMessage(wxT("MJ2: image loaded."));
    wxMutexGuiLeave();

	/* close openjpeg structs */
	opj_destroy_decompress(dinfo);
	opj_image_destroy(opjimage);
	free(src);

	if (!image->Ok())
		return false;
	else
		return true;

}