On 12/18/2016 04:40 PM, Vir Campestris wrote:
> You're missing the second parameter to the function. Perhaps if he'd
> written
>
> Reader foo;
> std::thread paint(&reader::read_chunk, &foo);
>
> it would have made more sense to you. You can pass args to the function,
> which may include a pointer to an object of the type. I prefer to pass a
> pointer to a static member function for the first parameter which takes
> a pointer to an object of the class and invokes a corresponding
> non-static member.
>
> Andy
Not really. There are data members of the object that are dynamically altered
and stored in the private encapsulation of the object which a a method handles
inside the thread. read_chunk is a member of the Image class and it is
assigned indexes within a block of memory, and a chunk of raw data. It
interprets the block of memory and writes to the block of memory which is
private to an instance of Image. The idea was to create a number of threads
that write to the block, each in its assigned area, simultaneously in parallel.
read_chunk looks like this
void Image::read_chunk ( )
{
CHUNKY * new_chunk = set_chunk();//the chunk construction call is within
std::cout << "Type " << new_chunk->type() << std::endl;
std::cout << "Length " << new_chunk->length() << std::endl;
std::cout << "CRC " << new_chunk->cr() << std::endl;
if(new_chunk->type() == "IHDR")
{
std::cout << "we have a header chunk " << std::endl;
IHDR * head = new IHDR;
unsigned char * cur = new_chunk->data(); //NOTE:: cur is now point at the new heap for in CHNUNK and not the index for the file
head->width = ntohl( *(reinterpret_cast<int32_t *>(cur ) ) );
cur += 4;
head->height = ntohl( *(reinterpret_cast<int32_t *>( cur ) ) );
cur += 4;
head->depth = *( reinterpret_cast<int8_t *>( cur ) );
cur++;
head->color_type = *( reinterpret_cast<int8_t *>( cur ) );
cur++;
head->compress = *( reinterpret_cast<int8_t *>( cur ) );
cur++;
head->filter = *( reinterpret_cast<int8_t *>( cur ) );
cur++;
head->interlace = *( reinterpret_cast<int8_t *>( cur ) );
cur++;
canvas_size = static_cast<long int>(head->height) * static_cast<long int>(head->width) * blank_canvas_psize(*head);
canvas = new unsigned char[ canvas_size ];
std::cout << "Canvas made: " << static_cast<long int>(head->height) * static_cast<long int>(head->width) * blank_canvas_psize(*head) << " bytes" << std::endl;
//char tmp;
//std::cin >> tmp;
}
if(new_chunk->type() == "IDAT")
{
//confusion here. Do we want to create a new data array on the heap to pass through to the images for placement on canvas?
//No. Not needed. Use the CHUNKY object instead. It already has the data array. Have the chunky obj schedule itself for
//copy to the canvas
set_canvas(*new_chunk); //SET MUTEX LOCK and assign canvas index to a CHUNKY object
}
if(new_chunk->type() == "IEND")
{
std::cout << "we have a IEND chunk " << std::endl;
//set_index(get_index() + 12 + new_chunk->length() ) ;
return;
}
std::thread ctch = getNext(); //calls this method in recursion
ctch.join(); //I want this to be detached
//read_chunk();
return ;
} /* ----- end of method Image::read_chunk ----- */