Example #1
0
//box *get_next_box(unsigned char *mem, long int *pos) {
box *get_next_box(FILE *fd) {
	println_start(INFO);
	//box *box = malloc(sizeof(box));

	int read = 0;
	box *box = init_box();

	if( (box->lbox = read_bytes(box->lbox, fd, 4)) == NULL)
		return NULL;

	box->length = hex_to_long(box->lbox, 4);
	if(box->length == 0) {
		return NULL;
	}

	if( (box->tbox = read_bytes(box->tbox, fd, 4)) == NULL) {
		println(INFO, "Corrupted JP2 file. Exitting.");
		return NULL;
	}
	read = 8;

	if(box->length == 1) { //there should be XLbox field present;
		box->xlbox = (unsigned char*)malloc(9 * sizeof(char));
		box->xlbox = read_bytes(box->xlbox, fd, 8);
		box->length = hex_to_long(box->xlbox, 8);
		read += 8;
	}
	box->content_length = box->length - read;

	box->dbox = (unsigned char*)malloc((box->content_length + 1) * sizeof(char));
	box->dbox = read_bytes(box->dbox, fd, box->content_length);
	println_end(INFO);
	return box;
}
Example #2
0
int jp2_parse_boxes(FILE *fd, type_image *img) {
	box *sig = get_next_box(fd);

	if(hex_to_long(sig->tbox, 4) != JP2_SIGNATURE_BOX)
		println(INFO, "JP2 signature box should be very first box in the file: Header");

	if(hex_to_long(sig->dbox, 4) != JP2_SIG_BOX_CONTENT)
		println(INFO, "JP2 signature box should be very first box in the file: Content");

	//dispose_of(sig);
	//free(sig);

	box *ft = get_next_box(fd);

	if(hex_to_long(ft->tbox, 4) != JP2_FILETYPE_BOX)
		println(INFO, "JP2 filetype box should directly follow JP2 signature box");

	if(h_filetype_box(ft, img))
		return 1;

	box *b;
	while( (b = get_next_box(fd)) != NULL ) {
		if(hex_to_long(b->tbox, 4) == JP2_HEADER_BOX) {
			println(INFO, "Header Box");
			h_header_box(b,img);
		} else
		if(hex_to_long(b->tbox,4) ==  CODE_STREAM_BOX) {
			println(INFO, "Contiguous Codestream Box");
			h_contiguous_codestream_box(b,img);

		} else
		if(hex_to_long(b->tbox,4) ==  INTELLECTUAL_PROPERTY_BOX) {
			println(INFO, "Intellectual Property Box");
		}
	}

	println_end(INFO);
	return 0;
}
Example #3
0
int dispose_of(box *b) {
/*	println_start(INFO);
	if(b->lbox == NULL)
		printf("NULL!\n");
	else
		free(b->lbox);
	println(INFO, "A");

	free(b->tbox);
	println(INFO, "A");
	free(b->dbox);

	println(INFO, "A");
	if(b->xlbox != NULL)
		free(b->xlbox);

	println(INFO, "A");
*/
	free(b);
	println_end(INFO);
	return 0;
}
Example #4
0
void h_contiguous_codestream_box(box *cbox, type_image *img) {

	long int codestream_len = cbox->content_length;

	type_buffer *src_buff = (type_buffer *) malloc(sizeof(type_buffer));
	src_buff->data = (unsigned char *) malloc(codestream_len+1);
	src_buff->size = codestream_len;

	src_buff->data = cbox->dbox;

	//src_buff->data = sstrncpy(src_buff->data, cbox->dbox, codestream_len);

	src_buff->start = src_buff->data;
	src_buff->end = src_buff->data + src_buff->size;
	src_buff->bp = src_buff->data;
	src_buff->bits_count = 0;
	src_buff->byte = 0;

	println(INFO, "Decoding codestream");
	decode_codestream(src_buff, img);

	println_end(INFO);
}
Example #5
0
box *get_next_box_char(box *superbox) {
	if(superbox->read >= superbox->content_length)
		return NULL;

	char *content = (char*)superbox->dbox;
	box* nextBox = (box*)malloc(sizeof(box));

	int read = superbox->read;
	nextBox->lbox = (unsigned char*)malloc(5 * sizeof(char));
	nextBox->lbox = (unsigned char*)sstrncpy((char*)nextBox->lbox, &content[read], 4); read += 4;
	nextBox->length = hex_to_long(nextBox->lbox, 4);

	println_var(INFO, "lbox: %i", nextBox->length);
	nextBox->tbox = (unsigned char*)malloc(5 * sizeof(char));
	nextBox->tbox =  (unsigned char*)sstrncpy((char*)nextBox->tbox, &content[read], 4); read += 4;

	println(INFO, "tbox");
	//box->length = hex_to_long(box->lbox, 4);
//	println_var(INFO, "length: %i", box->length);
	if(nextBox->length == 1) { //there should be XLbox field present;
		nextBox->xlbox =  (unsigned char*)malloc(9 * sizeof(char));
		nextBox->xlbox =  (unsigned char*)sstrncpy((char*)nextBox->xlbox, &content[read], 8);
		nextBox->length = hex_to_long(nextBox->xlbox, 8);
		read += 8;
	}

	int size = (nextBox->length - (read - superbox->read));
	nextBox->dbox =  (unsigned char*)malloc((size+1) * sizeof(char));
	nextBox->dbox =  (unsigned char*)sstrncpy((char*)nextBox->dbox, &content[read], size);
	read += size;

	nextBox->content_length = nextBox->length - read;
	println(INFO, "dbox");
	superbox->read = read;
	println_end(INFO);
	return nextBox;
}
Example #6
0
void encode_tile_dbg(type_tile *tile)
{
	println_start(INFO);

//	start_measure();

	std::list<type_codeblock *> cblks;

	type_coding_param *coding_params = tile->parent_img->coding_param;

	int size = 64*64*sizeof(int);
	int *buff = (int*)malloc(size);
	int x = 0, y = 0;
	type_codeblock *cblk_;

	for(int i = 0; i < tile->parent_img->num_components; i++)
	{
		type_tile_comp *tile_comp = &(tile->tile_comp[i]);
		for(int j = 0; j < tile_comp->num_rlvls; j++)
		{
			type_res_lvl *res_lvl = &(tile_comp->res_lvls[j]);
			for(int k = res_lvl->num_subbands - 1; k >= 0 ; k--)
			{
				type_subband *sb = &(res_lvl->subbands[k]);
				for(int l = 0; l < sb->num_cblks; l++)
				{
					cblk_ = &(sb->cblks[l]);
					cuda_memcpy_dth(cblk_->data_d, buff, size);

					printf("ulx:%d uly:%d magbits:%d orient:%d con:%f\n", sb->tlx, sb->tly, sb->mag_bits, sb->orient, sb->convert_factor);

					for(y = 0; y < cblk_->height; y++)
					{
						for(x = 0; x < cblk_->width; x++)
						{
							printf("%d, ", buff[x + y * 64]);
						}
					}
					printf("\n");
					cblks.push_back(&(sb->cblks[l]));
				}
			}
		}
		printf("\n");
	}

	EntropyCodingTaskInfo *tasks = (EntropyCodingTaskInfo *) malloc(sizeof(EntropyCodingTaskInfo) * cblks.size());

	std::list<type_codeblock *>::iterator ii = cblks.begin();

	int num_tasks = 0;
	for(; ii != cblks.end(); ++ii)
		convert_to_task(tasks[num_tasks++], *(*ii));

	printf("%d\n", num_tasks);

	gpuEncode(tasks, num_tasks, coding_params->target_size);

	ii = cblks.begin();

	for(int i = 0; i < num_tasks; i++, ++ii)
	{
		(*ii)->codestream = tasks[i].codeStream;
		(*ii)->length = tasks[i].length;
		(*ii)->significant_bits = tasks[i].significantBits;
	}

	free(tasks);

//	stop_measure(INFO);

	println_end(INFO);
}