static int TrySparseImageCopyPixels(const IceTImage image, IceTSizeType start, IceTSizeType end) { IceTVoid *full_sparse_buffer; IceTSparseImage full_sparse; IceTVoid *compress_sub_buffer; IceTSparseImage compress_sub; IceTVoid *sparse_copy_buffer; IceTSparseImage sparse_copy; IceTSizeType width = icetImageGetWidth(image); IceTSizeType height = icetImageGetHeight(image); IceTSizeType sub_size = end - start; int result; printf("Trying sparse image copy from %d to %d\n", start, end); full_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); full_sparse = icetSparseImageAssignBuffer(full_sparse_buffer,width,height); compress_sub_buffer = malloc(icetSparseImageBufferSize(sub_size, 1)); compress_sub = icetSparseImageAssignBuffer(compress_sub_buffer, sub_size, 1); sparse_copy_buffer = malloc(icetSparseImageBufferSize(sub_size, 1)); sparse_copy = icetSparseImageAssignBuffer(sparse_copy_buffer, sub_size, 1); icetCompressSubImage(image, start, sub_size, compress_sub); icetCompressImage(image, full_sparse); icetSparseImageCopyPixels(full_sparse, start, sub_size, sparse_copy); result = CompareSparseImages(compress_sub, sparse_copy); free(full_sparse_buffer); free(compress_sub_buffer); free(sparse_copy_buffer); return result; }
void icetRenderTransferSparseImages(IceTSparseImage compositeImage1, IceTSparseImage compositeImage2, IceTVoid *inImageBuffer, IceTSparseImage outSparseImage, IceTInt *tile_image_dest, IceTSparseImage *resultImage) { IceTInt num_sending; const IceTInt *tile_list; IceTInt num_tiles; IceTInt width, height; IceTInt *imageDestinations; IceTInt i; rtsi_workingImage = compositeImage1; rtsi_availableImage = compositeImage2; rtsi_outSparseImage = outSparseImage; rtsi_first = ICET_TRUE; icetGetIntegerv(ICET_NUM_CONTAINED_TILES, &num_sending); tile_list = icetUnsafeStateGetInteger(ICET_CONTAINED_TILES_LIST); icetGetIntegerv(ICET_TILE_MAX_WIDTH, &width); icetGetIntegerv(ICET_TILE_MAX_HEIGHT, &height); icetGetIntegerv(ICET_NUM_TILES, &num_tiles); imageDestinations = malloc(num_tiles * sizeof(IceTInt)); /* Make each element imageDestinations point to the processor to send the corresponding image in tile_list. */ for (i = 0; i < num_sending; i++) { imageDestinations[i] = tile_image_dest[tile_list[i]]; } icetSendRecvLargeMessages(num_sending, imageDestinations, icetIsEnabled(ICET_ORDERED_COMPOSITE), rtsi_generateDataFunc, rtsi_handleDataFunc, inImageBuffer, icetSparseImageBufferSize(width, height)); *resultImage = rtsi_workingImage; free(imageDestinations); }
IceTImage icetDirectCompose(void) { IceTImage image; IceTVoid *inSparseImageBuffer; IceTSparseImage outSparseImage; IceTSizeType sparseImageSize; const IceTInt *contrib_counts; const IceTInt *display_nodes; IceTInt max_width, max_height; IceTInt num_tiles; IceTInt num_contributors; IceTInt display_tile; IceTInt tile; IceTInt *tile_image_dest; icetRaiseDebug("In Direct Compose"); icetGetIntegerv(ICET_TILE_MAX_WIDTH, &max_width); icetGetIntegerv(ICET_TILE_MAX_HEIGHT, &max_height); icetGetIntegerv(ICET_NUM_TILES, &num_tiles); sparseImageSize = icetSparseImageBufferSize(max_width, max_height); image = icetGetStateBufferImage(DIRECT_IMAGE_BUFFER, max_width, max_height); inSparseImageBuffer = icetGetStateBuffer(DIRECT_IN_SPARSE_IMAGE_BUFFER, sparseImageSize); outSparseImage = icetGetStateBufferSparseImage( DIRECT_OUT_SPARSE_IMAGE_BUFFER, max_width, max_height); tile_image_dest = icetGetStateBuffer(DIRECT_TILE_IMAGE_DEST_BUFFER, num_tiles*sizeof(IceTInt)); icetGetIntegerv(ICET_TILE_DISPLAYED, &display_tile); if (display_tile >= 0) { contrib_counts = icetUnsafeStateGetInteger(ICET_TILE_CONTRIB_COUNTS); num_contributors = contrib_counts[display_tile]; } else { num_contributors = 0; } display_nodes = icetUnsafeStateGetInteger(ICET_DISPLAY_NODES); for (tile = 0; tile < num_tiles; tile++) { tile_image_dest[tile] = display_nodes[tile]; } icetRaiseDebug("Rendering and transferring images."); icetRenderTransferFullImages(image, inSparseImageBuffer, outSparseImage, tile_image_dest); if (display_tile >= 0) { if (num_contributors > 0) { icetImageCorrectBackground(image); } else { /* Must be displaying a blank tile. */ const IceTInt *tile_viewports = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS); const IceTInt *display_tile_viewport = tile_viewports + 4*display_tile; IceTInt display_tile_width = display_tile_viewport[2]; IceTInt display_tile_height = display_tile_viewport[3]; icetRaiseDebug("Returning blank tile."); icetImageSetDimensions(image, display_tile_width, display_tile_height); icetClearImageTrueBackground(image); } } return image; }
static int TestSparseImageSplit(const IceTImage image) { #define NUM_PARTITIONS 7 IceTVoid *full_sparse_buffer; IceTSparseImage full_sparse; IceTVoid *sparse_partition_buffer[NUM_PARTITIONS]; IceTSparseImage sparse_partition[NUM_PARTITIONS]; IceTSizeType offsets[NUM_PARTITIONS]; IceTVoid *compare_sparse_buffer; IceTSparseImage compare_sparse; IceTSizeType width; IceTSizeType height; IceTSizeType num_partition_pixels; IceTInt partition; width = icetImageGetWidth(image); height = icetImageGetHeight(image); num_partition_pixels = icetSparseImageSplitPartitionNumPixels(width*height, NUM_PARTITIONS, NUM_PARTITIONS); full_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); full_sparse = icetSparseImageAssignBuffer(full_sparse_buffer,width,height); for (partition = 0; partition < NUM_PARTITIONS; partition++) { sparse_partition_buffer[partition] = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); sparse_partition[partition] = icetSparseImageAssignBuffer(sparse_partition_buffer[partition], num_partition_pixels, 1); } compare_sparse_buffer = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); compare_sparse = icetSparseImageAssignBuffer(compare_sparse_buffer, num_partition_pixels, 1); icetCompressImage(image, full_sparse); printf("Spliting image %d times\n", NUM_PARTITIONS); icetSparseImageSplit(full_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTInt result; icetCompressSubImage(image, offsets[partition], icetSparseImageGetNumPixels( sparse_partition[partition]), compare_sparse); printf(" Comparing partition %d\n", partition); result = CompareSparseImages(compare_sparse, sparse_partition[partition]); if (result != TEST_PASSED) return result; } printf("Spliting image %d times with first partition in place.\n", NUM_PARTITIONS); sparse_partition[0] = full_sparse; icetSparseImageSplit(full_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTInt result; icetCompressSubImage(image, offsets[partition], icetSparseImageGetNumPixels( sparse_partition[partition]), compare_sparse); printf(" Comparing partition %d\n", partition); result = CompareSparseImages(compare_sparse, sparse_partition[partition]); if (result != TEST_PASSED) return result; } free(full_sparse_buffer); for (partition = 0; partition < NUM_PARTITIONS; partition++) { free(sparse_partition_buffer[partition]); } free(compare_sparse_buffer); return TEST_PASSED; #undef NUM_PARTITIONS }
static int DoCompressionTest(IceTEnum color_format, IceTEnum depth_format, IceTEnum composite_mode) { IceTInt viewport[4]; IceTSizeType pixels; IceTImage image; IceTVoid *imagebuffer; IceTSizeType imagesize; IceTSparseImage compressedimage; IceTVoid *compressedbuffer; IceTSparseImage interlacedimage; IceTVoid *interlacedbuffer; IceTSizeType compressedsize; IceTSizeType color_pixel_size; IceTSizeType depth_pixel_size; IceTSizeType pixel_size; IceTSizeType size; int result; result = TEST_PASSED; printstat("Using color format of 0x%x\n", (int)color_format); printstat("Using depth format of 0x%x\n", (int)depth_format); printstat("Using composite mode of 0x%x\n", (int)composite_mode); icetSetColorFormat(color_format); icetSetDepthFormat(depth_format); icetCompositeMode(composite_mode); pixels = SCREEN_WIDTH*SCREEN_HEIGHT; printstat("Allocating memory for %dx%d pixel image.\n", (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT); imagesize = icetImageBufferSize(SCREEN_WIDTH, SCREEN_HEIGHT); imagebuffer = malloc(imagesize); image = icetImageAssignBuffer(imagebuffer, SCREEN_WIDTH, SCREEN_HEIGHT); compressedsize = icetSparseImageBufferSize(SCREEN_WIDTH, SCREEN_HEIGHT); compressedbuffer = malloc(compressedsize); compressedimage = icetSparseImageAssignBuffer(compressedbuffer, SCREEN_WIDTH, SCREEN_HEIGHT); interlacedbuffer = malloc(compressedsize); interlacedimage = icetSparseImageAssignBuffer(interlacedbuffer, SCREEN_WIDTH, SCREEN_HEIGHT); /* Get the number of bytes per pixel. This is used in checking the size of compressed images. */ icetImageGetColorVoid(image, &color_pixel_size); icetImageGetDepthVoid(image, &depth_pixel_size); pixel_size = color_pixel_size + depth_pixel_size; printstat("Pixel size: color=%d, depth=%d, total=%d\n", (int)color_pixel_size, (int)depth_pixel_size, (int)pixel_size); printstat("\nCreating worst possible image" " (with respect to compression).\n"); InitPathologicalImage(image); printstat("Compressing image.\n"); icetCompressImage(image, compressedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)(pixel_size*(pixels/2) + 2*sizeof(IceTUShort)*(pixels/2)), (int)size); if ( (size > compressedsize) || (size < pixel_size*(pixels/2)) ) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } printstat("Interlacing image.\n"); icetSparseImageInterlace(compressedimage, 97, ICET_SI_STRATEGY_BUFFER_0, interlacedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)(pixel_size*(pixels/2) + 2*sizeof(IceTUShort)*(pixels/2)), (int)size); if ( (size > compressedsize) || (size < pixel_size*(pixels/2)) ) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } printstat("\nCreating a different worst possible image.\n"); InitActiveImage(image); printstat("Compressing image.\n"); icetCompressImage(image, compressedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)compressedsize, (int)size); if ((size > compressedsize) || (size < pixel_size*pixels)) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } printstat("Interlacing image.\n"); icetSparseImageInterlace(compressedimage, 97, ICET_SI_STRATEGY_BUFFER_0, interlacedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)(pixel_size*(pixels/2) + 2*sizeof(IceTUShort)*(pixels/2)), (int)size); if ( (size > compressedsize) || (size < pixel_size*(pixels/2)) ) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } printstat("\nCompressing zero size image.\n"); icetImageSetDimensions(image, 0, 0); icetCompressImage(image, compressedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)icetSparseImageBufferSize(0, 0), (int)size); if (size > icetSparseImageBufferSize(0, 0)) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } /* This test can be a little volatile. The icetGetCompressedTileImage * expects certain things to be set correctly by the icetDrawFrame * function. Since we want to call icetGetCompressedTileImage directly, * we try to set up these parameters by hand. It is possible for this * test to incorrectly fail if the two functions are mutually changed and * this scaffolding is not updated correctly. */ printstat("\nSetup for actual render.\n"); icetResetTiles(); icetAddTile(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); icetDrawCallback(drawCallback); /* Do a perfunctory draw to set other state variables. */ icetDrawFrame(IdentityMatrix, IdentityMatrix, Black); viewport[0] = viewport[1] = 0; viewport[2] = (IceTInt)SCREEN_WIDTH; viewport[3] = (IceTInt)SCREEN_HEIGHT; icetStateSetIntegerv(ICET_CONTAINED_VIEWPORT, 4, viewport); printstat("Now render and get compressed image.\n"); icetGetCompressedTileImage(0, compressedimage); size = icetSparseImageGetCompressedBufferSize(compressedimage); printstat("Expected size: %d. Actual size: %d\n", (int)compressedsize, (int)size); if ((size > compressedsize) || (size < pixel_size*pixels)) { printrank("*** Size differs from expected size!\n"); result = TEST_FAILED; } printstat("Cleaning up.\n"); free(imagebuffer); free(compressedbuffer); free(interlacedbuffer); return result; }
static int TestInterlaceSplit(const IceTImage image) { #define NUM_PARTITIONS 13 IceTVoid *original_sparse_buffer; IceTSparseImage original_sparse; IceTVoid *interlaced_sparse_buffer; IceTSparseImage interlaced_sparse; IceTVoid *sparse_partition_buffer[NUM_PARTITIONS]; IceTSparseImage sparse_partition[NUM_PARTITIONS]; IceTSizeType offsets[NUM_PARTITIONS]; IceTVoid *reconstruction_buffer; IceTImage reconstruction; IceTSizeType width; IceTSizeType height; IceTSizeType num_partition_pixels; IceTInt partition; width = icetImageGetWidth(image); height = icetImageGetHeight(image); num_partition_pixels = icetSparseImageSplitPartitionNumPixels(width*height, NUM_PARTITIONS, NUM_PARTITIONS); original_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); original_sparse = icetSparseImageAssignBuffer(original_sparse_buffer, width, height); interlaced_sparse_buffer = malloc(icetSparseImageBufferSize(width, height)); interlaced_sparse = icetSparseImageAssignBuffer(interlaced_sparse_buffer, width, height); for (partition = 0; partition < NUM_PARTITIONS; partition++) { sparse_partition_buffer[partition] = malloc(icetSparseImageBufferSize(num_partition_pixels, 1)); sparse_partition[partition] = icetSparseImageAssignBuffer(sparse_partition_buffer[partition], num_partition_pixels, 1); } reconstruction_buffer = malloc(icetImageBufferSize(width, height)); reconstruction = icetImageAssignBuffer(reconstruction_buffer,width,height); icetCompressImage(image, original_sparse); printf("Interlacing image for %d pieces\n", NUM_PARTITIONS); icetSparseImageInterlace(original_sparse, NUM_PARTITIONS, ICET_SI_STRATEGY_BUFFER_0, interlaced_sparse); printf("Splitting image %d times\n", NUM_PARTITIONS); icetSparseImageSplit(interlaced_sparse, 0, NUM_PARTITIONS, NUM_PARTITIONS, sparse_partition, offsets); printf("Reconstructing image.\n"); for (partition = 0; partition < NUM_PARTITIONS; partition++) { IceTSizeType real_offset = icetGetInterlaceOffset(partition, NUM_PARTITIONS, width*height); icetDecompressSubImage(sparse_partition[partition], real_offset, reconstruction); } if (!CompareImageColors(image, reconstruction)) { return TEST_FAILED; } if (!CompareImageDepths(image, reconstruction)) { return TEST_FAILED; } free(original_sparse_buffer); free(interlaced_sparse_buffer); for (partition = 0; partition < NUM_PARTITIONS; partition++) { free(sparse_partition_buffer[partition]); } free(reconstruction_buffer); return TEST_PASSED; }