/**
 * This function ensure that we are not writing a block number
 * which goes over the last block contained in the current packet.
 */
void check_index(int *index){
    errorcode_t retval;
    short coefficients[NUM_COEFF];
    
    if ( (*index) > get_last_block_index() ) {
        // Discard the packet reading until it ends.
        // TODO: we might directly call the pkg_reader::load function
        // NOTE: i tried, but the result is different. Why?
        //do {
        while( (*index) > get_last_block_index() && retval != ERR_EOF) {
            DEBUG_BLOCK(*index, "Invalid. Skipping it (over current last_block value)");
            //load_frame();
            retval = read_block(coefficients);
        } //while (retval != ERR_PACKET_SWITCH && retval != ERR_EOF);
        
        // Since we have loaded a new packet, we have to sync to its first block
        concealment_write_concealment_blocks(*index, get_first_block_index() - *index);
        (*index) = get_first_block_index();
    }
    // if the first block value is wrong (less than expected) we have to sync,
    // skipping some blocks
    while (*index < written_blocks) {
        retval = read_block(coefficients);
        if(retval != 0) error_handler(coefficients, retval, index);
        (*index)++;
    }
}
unsigned char* zinjpeg_decompressor::decompress_zinjpeg(unsigned char* input_buffer, int buffer_size){
    
    //init of the decompression
    bitbuffer_construct();
    radio_init((char*)input_buffer, buffer_size);
    pkg_reader_construct();
    huff_table_init();
    huff_reset();
    concealment_initialize();
    
    //writting the header of the output buffer
    write_header(this->quality);
    
    
    //loop to transcode ZinJpeg in JPEG
    for (int i = 0; i < NUM_OF_BLOCKS; i++) {
        short coefficients[NUM_COEFF];
        // Check whether this index can be accepted
        //	check_index(&i);
        // Reading the block
        errorcode_t retval = read_block(coefficients);
        check_index(&i);
        
        if(retval == 0) {
            // i < NUM_OF_BLOCKS is necessary because we may encounter
            // a end of file in the check_index: in that case we sync
            // to the end of the image, but here we would try to write
            // one more block
            if(i < NUM_OF_BLOCKS) {
                DEBUG_BLOCK(i, "Valid block. I'm writing it");
                write_block(coefficients);
                concealment_block_written_success(i, coefficients);
            }
        } else error_handler(coefficients, retval, &i);
    }
    
    write_trailer();
    this->output_buffer = write_result_to_buffer(&(this->output_size));
    return this->output_buffer;
}
Пример #3
0
unsigned char * BakerGc::allocateOnPermanentSpace(size_t size)
{
	if (size == 0)
	{
		return NULL; // TODO: Throw exception
	}

	size_t bytesAllocated = this->countAllocatedBlockSize(size);

	DEBUG_BLOCK(std::cerr << "Allocating object of size: " << size << " to 16 aligned size: " << bytesAllocated << " on TENURED space" << std::endl);


	if ((this->permanentSpace->usedBytes + bytesAllocated) >= this->permanentSpace->allocatedBytes)
	{
		// Thats bad - time for FULL old space garbage collection!!
		DEBUG_PRINT("Allocation cannot proceed, garbage TENURED SPACE collection needed\n");
		this->fullCollect();
	}

	MemoryHeader* memory = (MemoryHeader*) new(this->permanentSpace->allocate(bytesAllocated)) MemoryHeader(size);
	memory->tenure(); // automatically tenured - do not move to eden space...
	return (unsigned char*)memory->data;
}
Пример #4
0
unsigned char * BakerGc::allocateOnEdenSpace(size_t size)
{
	if (size == 0)
	{
		return NULL; // TODO: Throw exception
	}
	
	size_t bytesAllocated = this->countAllocatedBlockSize(size);
	DEBUG_BLOCK(std::cerr << "Allocating object of size: " << size << " to 16 aligned size: " << bytesAllocated << " on EDEN space" << std::endl );

	if ((this->memorySlots[this->activeSlot]->usedBytes + bytesAllocated) >= this->memorySlots[this->activeSlot]->allocatedBytes)
	{
		DEBUG_PRINT("Allocation cannot proceed, garbage collection needed\n");
		// Time for garbage collection man!!
		this->collect();		
	}

	void* allocatedAddress = this->memorySlots[this->activeSlot]->allocate(bytesAllocated);
	MemoryHeader* memory = (MemoryHeader*) new(allocatedAddress) MemoryHeader(size);

	DEBUG_PRINT("Allocated memory with address: %p, data start at address: %p\n", (void*) allocatedAddress, (void*) memory->data);

	return (unsigned char*)memory->data;
}