int main() { int compressedSize = 0; int decompressedSize = 0; char buffer[BUFFER_SIZE] = {'h','f','u','h','i','u','g','h','e','r','i','u','g','i','i','i','e','e','e','r','r','r','r','r','r','r','r','f','f','f','f','f','f','w','e'}; char encoded[BUFFER_SIZE]; char decoded[BUFFER_SIZE]; printBuffer(buffer, BUFFER_SIZE); compressedSize = rleEncode(buffer, encoded); printf("Encoded: "); printBuffer(encoded, BUFFER_SIZE); decompressedSize = rleDecode(encoded, decoded); printf("Compressed size: %i\n", compressedSize); printf("Decoded: size - %i\n", decompressedSize); printBuffer(decoded, BUFFER_SIZE); return 0; }
// **************************************************************************** // Method: avtImgCommunicator:: // // Purpose: // // Programmer: Pascal Grosset // Creation: July 2013 // // Modifications: // // **************************************************************************** void avtImgCommunicator::gatherAndAssembleEncodedImages(int sizex, int sizey, int sizeSending, float *images, int numDivisions){ #ifdef PARALLEL float *tempRecvBuffer = NULL; int *recvSizePerProc = NULL; int *offsetBuffer = NULL; int totalDivisions = 0; std::map<float,int> depthPartitions; //float: z-value, int: division index // Only proc 0 receives data if (my_id == 0){ int divIndex = 0; int totalSize = 0; recvSizePerProc = new int[num_procs]; offsetBuffer = new int[num_procs]; for (int i=0; i<num_procs; i++){ int numBoundsPerBlock = boundsPerBlockVec[i].size()/2; totalDivisions += numBoundsPerBlock; int sizeEncoded = 0; for (size_t j=0; j<boundsPerBlockVec[i].size(); j+=2){ depthPartitions.insert( std::pair< float,int > ( (boundsPerBlockVec[i][j] + boundsPerBlockVec[i][j+1]) * 0.5, divIndex ) ); sizeEncoded += compressedSizePerDiv[divIndex]*5; divIndex++; } totalSize += sizeEncoded; recvSizePerProc[i] = sizeEncoded; if (i == 0) offsetBuffer[i] = 0; else offsetBuffer[i] = offsetBuffer[i-1] + recvSizePerProc[i-1]; } tempRecvBuffer = new float[ totalSize ]; } // send recv others MPI_Gatherv(images, sizeSending, MPI_FLOAT, tempRecvBuffer, recvSizePerProc, offsetBuffer,MPI_FLOAT, 0, MPI_COMM_WORLD); // all send to proc 0 if (my_id == 0){ // Create a buffer to store the composited image imgBuffer = new float[sizex * sizey * 4]; // Front to back for (int i=0; i<(sizex * sizey * 4); i+=4){ imgBuffer[i+0] = background[0]/255.0; imgBuffer[i+1] = background[1]/255.0; imgBuffer[i+2] = background[2]/255.0; imgBuffer[i+3] = 1.0; } int count = 0; int offset = 0; int index = 0; if (depthPartitions.size() > 0){ std::map< float,int >::iterator it; it=depthPartitions.end(); it=depthPartitions.end(); do{ --it; debug5 << it->first << " => " << it->second << " compressedSizePerDiv[count]: " << compressedSizePerDiv[count] << std::endl; imageBuffer temp; temp.image = new float[sizex*sizey*4]; index = it->second; if (index == 0) offset = 0; else{ offset = 0; for (int k=0; k<index; k++) offset += compressedSizePerDiv[k]; } rleDecode(compressedSizePerDiv[index], tempRecvBuffer, offset*5, temp.image); for (int j=0; j<sizey; j++){ for (int k=0; k<sizex; k++){ int imgIndex = sizex*4*j + k*4; // index in the image // Back to front compositing imgBuffer[imgIndex+0] = clamp((imgBuffer[imgIndex+0] * (1.0 - temp.image[imgIndex+3])) + temp.image[imgIndex+0]); imgBuffer[imgIndex+1] = clamp((imgBuffer[imgIndex+1] * (1.0 - temp.image[imgIndex+3])) + temp.image[imgIndex+1]); imgBuffer[imgIndex+2] = clamp((imgBuffer[imgIndex+2] * (1.0 - temp.image[imgIndex+3])) + temp.image[imgIndex+2]); } } delete []temp.image; temp.image = NULL; count++; }while( it!=depthPartitions.begin() ); } if (tempRecvBuffer != NULL) delete []tempRecvBuffer; tempRecvBuffer = NULL; if (offsetBuffer != NULL) delete []offsetBuffer; offsetBuffer = NULL; if (recvSizePerProc != NULL) delete []recvSizePerProc; recvSizePerProc = NULL; } syncAllProcs(); #endif }