Example #1
0
void ImageMDCodec::decode(const MDStream* md_stream, AbstractStream* stream) const {
	if (!md_stream->is_empty()) {
		vector<pixel_container> took_stream;
		Uint8 flows_number = md_stream->get_flows_number();
		Uint32 sequences_number = md_stream->get_sequences_number();
		Uint16 image_width, image_height;
		Uint8 bpp = 0;
		bool null_pixel_present = false;
		for (Uint8 i=0; i<flows_number; i++) {
			Uint64 offset = 0;
			Uint16 payload_size = 0;
			for (Uint32 j=0; j<sequences_number; j++) {
				Descriptor* descriptor = new Descriptor();
				if (md_stream->get_descriptor(i, j, descriptor) && (descriptor->get_codec_name()=="image")) {
					payload_size = descriptor->get_payload_size();
					if (md_stream->is_valid(descriptor->get_flow_id(), descriptor->get_sequence_number())) {
						MemDataChunk* payload = decompression(descriptor->get_payload(), payload_size);
						payload_size = payload->get_lenght();
						took_stream.resize(flows_number*sequences_number*(payload_size+1));
						ImageCodecParameters* icp = dynamic_cast<ImageCodecParameters*>(descriptor->get_codec_parameter());
						image_width = icp->get_width();
						image_height = icp->get_height();
						bpp = icp->get_bits_per_pixel();
						if (bpp == 24) {
							Uint32 k;
							Uint32 pixels_in_payload = payload_size/3;
							DataChunkIterator it = payload->get_iterator();
							for (k=0; k<pixels_in_payload; k++) {
								pixel_container curr_pixel;
								Uint8 r,g,b;
								it.get_Uint8(r);
								it.get_Uint8(g);
								it.get_Uint8(b);
								curr_pixel.set_r(r);
								curr_pixel.set_g(g);
								curr_pixel.set_b(b);
								Uint32 locate_position = offset+i+(k*flows_number);
								took_stream[locate_position] = curr_pixel;
							}
							offset += flows_number*k;
						}
						delete payload;
					}
				}
				else {
					Uint32 k;
					Uint32 pixels_in_payload = payload_size/3;
					for (k=0; k<pixels_in_payload; k++) {
						Uint32 locate_position = offset+i+(k*flows_number);
						took_stream[locate_position] = m_null_pixel;
					}
					offset += flows_number*k;
					null_pixel_present = true;
				}
			}
		}

		Uint32 pixel_number = image_width*image_height;
		MemDataChunk* final_pixels= new MemDataChunk();
		final_pixels->resize(pixel_number*3);
		for (Uint32 i=0; i<pixel_number; i++) {
			MemDataChunk* pixel = &(took_stream[i].serialize());
			final_pixels->set_data_chunk(i*3, pixel);
			delete pixel;
		}
		dynamic_cast<ImageStream*>(stream)->set_width(image_width);
		dynamic_cast<ImageStream*>(stream)->set_height(image_height);
		dynamic_cast<ImageStream*>(stream)->set_bits_per_pixel(bpp);
		dynamic_cast<ImageStream*>(stream)->set_null_pixel_presence(null_pixel_present);
		stream->set_data(*final_pixels);
		delete final_pixels;
	}
}
Example #2
0
void TextMDCodec::decode(const MDStream* md_stream, AbstractStream* stream) const {
	if (md_stream->is_empty()) 
	{
		return;
	}
	LOG_INFO("Decoding...");
	MemDataChunk* dc = new MemDataChunk();
	vector<Uint8> took_stream;
	Uint8 flows_number = md_stream->get_flows_number();
	LOG_INFO("Flows number: "<<flows_number);
	Uint32 sequences_number = md_stream->get_sequences_number();
	LOG_INFO("Sequences number: "<<sequences_number);
	Uint64 max_dimension = 0;
	for (Uint8 i=0; i<flows_number; i++) 
	{
		Uint64 offset = 0;
		Uint16 payload_size = 0;
		for (Uint32 j=0; j<sequences_number; j++) 
		{
			Descriptor* descriptor = new Descriptor();
			if(!(descriptor->get_codec_name()=="text"))
			{
				continue;
			}

			if (md_stream->get_descriptor(i, j, descriptor)) 
			{
				payload_size = descriptor->get_payload_size();
				if (md_stream->is_valid(descriptor->get_flow_id(), descriptor->get_sequence_number())) 
				{
					(*dc) += (descriptor->get_payload());
					took_stream.resize(flows_number*sequences_number*(payload_size+1));
					Uint8 current_received_data;
					Uint64 k;
					for (k=0; k<payload_size; k++) {
						dc->extract_head(current_received_data);
						if (current_received_data != 0) {
							Uint64 locate_position = offset+i+(k*flows_number);
							took_stream[locate_position] = current_received_data;
							if (locate_position > max_dimension)
								max_dimension = locate_position;
						}
					}
					offset += flows_number*k;
				}
			}
			else 
			{
				Uint64 k;
				for (k=0; k<payload_size; k++) {
					Uint64 locate_position = offset+i+(k*flows_number);
					took_stream[locate_position] = ' ';
				}
				offset += flows_number*k;
			}
		}
	}
	MemDataChunk* taken_dc = new MemDataChunk();
	Uint8* temp_container = new Uint8[max_dimension+1];
	for (Uint64 i=0; i<max_dimension+1; i++)
		temp_container[i] = took_stream[i];
	taken_dc->append_data(max_dimension+1, temp_container);
	stream->set_data(*taken_dc);

}