Пример #1
0
static IceTBoolean CompareImageColors(const IceTImage image_a,
                                      const IceTImage image_b)
{
    IceTSizeType width;
    IceTSizeType height;
    IceTUByte *data_a;
    IceTUByte *data_b;
    IceTUByte *data_a_start;
    IceTUByte *data_b_start;
    IceTSizeType x;
    IceTSizeType y;

    if (icetImageGetColorFormat(image_a) != icetImageGetColorFormat(image_b)) {
        printf("ERROR: Image formats do not match.\n");
        return ICET_FALSE;
    }

    if (   (icetImageGetWidth(image_a) != icetImageGetWidth(image_b))
        || (icetImageGetHeight(image_a) != icetImageGetHeight(image_b)) ) {
        printf("ERROR: Images have different dimensions.\n");
        return ICET_FALSE;
    }

    if (icetImageGetColorFormat(image_a) == ICET_IMAGE_COLOR_NONE) {
        /* No color data, trivially the same. */
        return ICET_TRUE;
    }

    width = icetImageGetWidth(image_a);
    height = icetImageGetHeight(image_a);

    data_a = data_a_start = malloc(width*height*4);
    icetImageCopyColorub(image_a, data_a, ICET_IMAGE_COLOR_RGBA_UBYTE);

    data_b = data_b_start = malloc(width*height*4);
    icetImageCopyColorub(image_b, data_b, ICET_IMAGE_COLOR_RGBA_UBYTE);

    for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
            if (   (data_a[0] != data_b[0])
                || (data_a[1] != data_b[1])
                || (data_a[2] != data_b[2])
                || (data_a[3] != data_b[3]) ) {
                printf("ERROR: Encountered bad pixel @ (%d,%d).\n", x, y);
                printf("Expected (%d, %d, %d, %d)\n",
                       data_a[0], data_a[1], data_a[2], data_a[3]);
                printf("Got (%d, %d, %d, %d)\n",
                       data_b[0], data_b[1], data_b[2], data_b[3]);
                return ICET_FALSE;
            }
            data_a += 4;
            data_b += 4;
        }
    }

    free(data_a_start);
    free(data_b_start);

    return ICET_TRUE;
}
Пример #2
0
static IceTImage drawInvokeStrategy(void)
{
    IceTImage image;
    IceTVoid *value;
    IceTEnum strategy;
    IceTInt display_tile;
    IceTInt valid_tile;

    icetGetPointerv(ICET_DRAW_FUNCTION, &value);
    if (value == NULL) {
        icetRaiseError("Drawing function not set.  Call icetDrawCallback.",
                       ICET_INVALID_OPERATION);
        return icetImageNull();
    }

    icetRaiseDebug("Calling strategy");
    icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 1);
    icetGetEnumv(ICET_STRATEGY, &strategy);
    image = icetInvokeStrategy(strategy);

    icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 0);

    /* Ensure that the returned image is the expected size. */
    icetGetIntegerv(ICET_VALID_PIXELS_TILE, &valid_tile);
    icetGetIntegerv(ICET_TILE_DISPLAYED, &display_tile);
    if ((valid_tile != display_tile) && icetIsEnabled(ICET_COLLECT_IMAGES)) {
        icetRaiseDebug2("Display tile: %d, valid tile: %d",
                        display_tile, valid_tile);
        icetRaiseError("Got unexpected tile from strategy.",
                       ICET_SANITY_CHECK_FAIL);
    }
    if (valid_tile >= 0) {
        const IceTInt *valid_tile_viewport
            = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS) + 4*valid_tile;
        if (   (valid_tile_viewport[2] != icetImageGetWidth(image))
            || (valid_tile_viewport[3] != icetImageGetHeight(image)) ) {
            IceTInt valid_offset;
            IceTInt valid_num;
            icetRaiseDebug1("Tile returned from strategy: %d\n", valid_tile);
            icetRaiseDebug4("Expected size: %d %d.  Returned size: %d %d",
                            valid_tile_viewport[2], valid_tile_viewport[3],
                            (int)icetImageGetWidth(image),
                            (int)icetImageGetHeight(image));
            icetGetIntegerv(ICET_VALID_PIXELS_OFFSET, &valid_offset);
            icetGetIntegerv(ICET_VALID_PIXELS_NUM, &valid_num);
            icetRaiseDebug2("Reported pixel offset: %d.  Reported pixel count: %d",
                            valid_offset, valid_num);
            icetRaiseError("Got unexpected image size from strategy.",
                           ICET_SANITY_CHECK_FAIL);
        }
    }

    icetStateCheckMemory();

    return image;
}
Пример #3
0
static IceTBoolean CompareImageDepths(const IceTImage image_a,
                                      const IceTImage image_b)
{
    IceTSizeType width;
    IceTSizeType height;
    IceTFloat *data_a;
    IceTFloat *data_b;
    IceTFloat *data_a_start;
    IceTFloat *data_b_start;
    IceTSizeType x;
    IceTSizeType y;

    if (icetImageGetDepthFormat(image_a) != icetImageGetDepthFormat(image_b)) {
        printf("ERROR: Image formats do not match.\n");
        return ICET_FALSE;
    }

    if (   (icetImageGetWidth(image_a) != icetImageGetWidth(image_b))
        || (icetImageGetHeight(image_a) != icetImageGetHeight(image_b)) ) {
        printf("ERROR: Images have different dimensions.\n");
        return ICET_FALSE;
    }

    if (icetImageGetDepthFormat(image_a) == ICET_IMAGE_DEPTH_NONE) {
        /* No depth data, trivially the same. */
        return ICET_TRUE;
    }

    width = icetImageGetWidth(image_a);
    height = icetImageGetHeight(image_a);

    data_a = data_a_start = malloc(width*height*4);
    icetImageCopyDepthf(image_a, data_a, ICET_IMAGE_DEPTH_FLOAT);

    data_b = data_b_start = malloc(width*height*4);
    icetImageCopyDepthf(image_b, data_b, ICET_IMAGE_DEPTH_FLOAT);

    for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
            if (data_a[0] != data_b[0]) {
                printf("ERROR: Encountered bad pixel @ (%d,%d).\n", x, y);
                printf("Expected %f, got %f\n", data_a[0], data_b[0]);
                return ICET_FALSE;
            }
            data_a++;
            data_b++;
        }
    }

    free(data_a_start);
    free(data_b_start);

    return ICET_TRUE;
}
Пример #4
0
static int TestSparseImageCopyPixels(const IceTImage image)
{
#define NUM_OFFSETS 7
    IceTSizeType interesting_offset[NUM_OFFSETS];
    IceTSizeType width = icetImageGetWidth(image);
    IceTSizeType height = icetImageGetHeight(image);
    int start, end;

    if (height <= 20) {
        printf("Need image height greater than 20.\n");
        return TEST_NOT_RUN;
    }

    interesting_offset[0] = 0;  /* First pixel. */
    interesting_offset[1] = 10*width; /* Some pixels up at left. */
    interesting_offset[2] = 10*width + width/2; /* A bit up in the middle. */
    interesting_offset[3] = width*(height/2) + height/2; /* Middle at triangle diagonal. */
    interesting_offset[4] = width*(height-10); /* Some pixels from top at left. */
    interesting_offset[5] = width*(height-10) + width/2; /* Some pixels from top in middle. */
    interesting_offset[6] = width*height; /* Last pixel. */

    for (start = 0; start < NUM_OFFSETS; start++) {
        for (end = start+1; end < NUM_OFFSETS; end++) {
            int result;
            result = TrySparseImageCopyPixels(image,
                                              interesting_offset[start],
                                              interesting_offset[end]);
            if (result != TEST_PASSED) return result;
        }
    }

    return TEST_PASSED;
#undef NUM_OFFSETS
}
Пример #5
0
/* Fills the given image to have data in the lower triangle like this:
 *
 * +-------------+
 * |  \          |
 * |    \        |
 * |      \      |
 * |        \    |
 * |          \  |
 * +-------------+
 *
 * Where the lower half is filled with data and the upper half is background. */
static void LowerTriangleImage(IceTImage image)
{
    IceTSizeType width = icetImageGetWidth(image);
    IceTSizeType height = icetImageGetHeight(image);
    IceTSizeType x, y;

    if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_RGBA_UBYTE) {
        IceTUInt *data = icetImageGetColorui(image);
        for (y = 0; y < height; y++) {
            for (x = 0; x < width; x++) {
                if ((height-y) < x) {
                    data[0] = ACTIVE_COLOR(x, y);
                } else {
                    data[0] = 0;
                }
                data++;
            }
        }
    } else if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_RGBA_FLOAT) {
        IceTFloat *data = icetImageGetColorf(image);
        for (y = 0; y < height; y++) {
            for (x = 0; x < width; x++) {
                if ((height-y) < x) {
                    data[0] = (float)x;
                    data[1] = (float)y;
                    data[2] = 0.0;
                    data[3] = 1.0;
                } else {
                    data[0] = data[1] = data[2] = data[3] = 0.0;
                }
                data += 4;
            }
        }
    } else if (icetImageGetColorFormat(image) == ICET_IMAGE_COLOR_NONE) {
        /* Do nothing. */
    } else {
        printf("ERROR: Encountered unknown color format.");
    }

    if (icetImageGetDepthFormat(image) == ICET_IMAGE_DEPTH_FLOAT) {
        IceTFloat *data = icetImageGetDepthf(image);
        for (y = 0; y < height; y++) {
            for (x = 0; x < width; x++) {
                if ((height-y) < x) {
                    data[0] = ACTIVE_DEPTH(x, y);
                } else {
                    data[0] = 0.0;
                }
                data++;
            }
        }
    } else if (icetImageGetDepthFormat(image) == ICET_IMAGE_DEPTH_NONE) {
        /* Do nothing. */
    } else {
        printf("ERROR: Encountered unknown depth format.");
    }
}
Пример #6
0
/* Fills the given image to have data in the upper triangle like this:
 *
 * +-------------+
 * |  \          |
 * |    \        |
 * |      \      |
 * |        \    |
 * |          \  |
 * +-------------+
 *
 * Where the upper half is filled with data and the upper half is background. */
static void UpperTriangleImage(IceTImage image)
{
    IceTUInt *data = icetImageGetColorui(image);
    IceTSizeType width = icetImageGetWidth(image);
    IceTSizeType height = icetImageGetHeight(image);
    IceTSizeType x, y;

    for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
            if ((height-y) < x) {
                data[0] = ACTIVE_COLOR(x, y);
            } else {
                data[0] = 0;
            }
            data++;
        }
    }
}
Пример #7
0
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;
}
Пример #8
0
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
}
Пример #9
0
void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
                                const IceTDouble *modelview_matrix,
                                const IceTFloat *background_color,
                                const IceTInt *readback_viewport,
                                IceTImage result)
{
    IceTSizeType width = icetImageGetWidth(result);
    IceTSizeType height = icetImageGetHeight(result);
    GLint gl_viewport[4];
    glGetIntegerv(GL_VIEWPORT, gl_viewport);

  /* Check OpenGL state. */
    {
        if ((gl_viewport[2] != width) || (gl_viewport[3] != height)) {
            icetRaiseError("OpenGL viewport different than expected."
                           " Was it changed?", ICET_SANITY_CHECK_FAIL);
        }
    }

  /* Set up OpenGL. */
    {
      /* Load the matrices. */
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixd(projection_matrix);
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixd(modelview_matrix);

      /* Set the clear color as the background IceT currently wants. */
        glClearColor(background_color[0], background_color[1],
                     background_color[2], background_color[3]);
    }

  /* Call the rendering callback. */
    {
        IceTVoid *value;
        IceTGLDrawCallbackType callback;
        icetRaiseDebug("Calling OpenGL draw function.");
        icetGetPointerv(ICET_GL_DRAW_FUNCTION, &value);
        callback = (IceTGLDrawCallbackType)value;
        (*callback)();
    }

    /* Temporarily stop render time while reading back buffer. */
    icetTimingRenderEnd();

    icetTimingBufferReadBegin();

  /* Read the OpenGL buffers. */
    {
        IceTEnum color_format = icetImageGetColorFormat(result);
        IceTEnum depth_format = icetImageGetDepthFormat(result);
        IceTEnum readbuffer;
        IceTSizeType x_offset = gl_viewport[0] + readback_viewport[0];
        IceTSizeType y_offset = gl_viewport[1] + readback_viewport[1];

        glPixelStorei(GL_PACK_ROW_LENGTH, (GLint)icetImageGetWidth(result));

      /* These pixel store parameters are not working on one of the platforms
       * I am testing on (thank you Mac).  Instead of using these, just offset
       * the buffers we read in from. */
        /* glPixelStorei(GL_PACK_SKIP_PIXELS, readback_viewport[0]); */
        /* glPixelStorei(GL_PACK_SKIP_ROWS, readback_viewport[1]); */

        icetGetEnumv(ICET_GL_READ_BUFFER, &readbuffer);
        glReadBuffer(readbuffer);

        if (color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
            IceTUInt *colorBuffer = icetImageGetColorui(result);
            glReadPixels((GLint)x_offset,
                         (GLint)y_offset,
                         (GLsizei)readback_viewport[2],
                         (GLsizei)readback_viewport[3],
                         GL_RGBA,
                         GL_UNSIGNED_BYTE,
                         colorBuffer + (  readback_viewport[0]
                                        + width*readback_viewport[1]));
        } else if (color_format == ICET_IMAGE_COLOR_RGBA_FLOAT) {
            IceTFloat *colorBuffer = icetImageGetColorf(result);
            glReadPixels((GLint)x_offset,
                         (GLint)y_offset,
                         (GLsizei)readback_viewport[2],
                         (GLsizei)readback_viewport[3],
                         GL_RGBA,
                         GL_FLOAT,
                         colorBuffer + 4*(  readback_viewport[0]
                                          + width*readback_viewport[1]));
        } else if (color_format != ICET_IMAGE_COLOR_NONE) {
            icetRaiseError("Invalid color format.", ICET_SANITY_CHECK_FAIL);
        }

        if (depth_format == ICET_IMAGE_DEPTH_FLOAT) {
            IceTFloat *depthBuffer = icetImageGetDepthf(result);;
            glReadPixels((GLint)x_offset,
                         (GLint)y_offset,
                         (GLsizei)readback_viewport[2],
                         (GLsizei)readback_viewport[3],
                         GL_DEPTH_COMPONENT,
                         GL_FLOAT,
                         depthBuffer + (  readback_viewport[0]
                                        + width*readback_viewport[1]));
        } else if (depth_format != ICET_IMAGE_DEPTH_NONE) {
            icetRaiseError("Invalid depth format.", ICET_SANITY_CHECK_FAIL);
        }

        glPixelStorei(GL_PACK_ROW_LENGTH, 0);
        /* glPixelStorei(GL_PACK_SKIP_PIXELS, 0); */
        /* glPixelStorei(GL_PACK_SKIP_ROWS, 0); */
    }

    icetTimingBufferReadEnd();

    /* Start render timer again.  It's going to be shut off immediately on
       return anyway, but the calling function expects it to be running. */
    icetTimingRenderBegin();
}
Пример #10
0
static int BlankTilesDoTest(void)
{
    int result = TEST_PASSED;
    int tile_dim;
    IceTInt rank, num_proc;

    icetGetIntegerv(ICET_RANK, &rank);
    icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);

    for (tile_dim = 1; tile_dim*tile_dim <= num_proc; tile_dim++) {
        int x, y;
        IceTSizeType my_width = -1;
        IceTSizeType my_height = -1;
        IceTImage image;
        printstat("\nRunning on a %d x %d display.\n", tile_dim, tile_dim);
        icetResetTiles();
        for (y = 0; y < tile_dim; y++) {
            for (x = 0; x < tile_dim; x++) {
                int tile_rank = y*tile_dim + x;
              /* Modify the width and height a bit to detect bad image sizes. */
                IceTSizeType tile_width = SCREEN_WIDTH - x;
                IceTSizeType tile_height = SCREEN_HEIGHT - y;
                icetAddTile((IceTInt)(x*SCREEN_WIDTH),
                            (IceTInt)(y*SCREEN_HEIGHT),
                            tile_width,
                            tile_height,
                            tile_rank);
                if (tile_rank == rank) {
                    my_width = tile_width;
                    my_height = tile_height;
                }
            }
        }

        printstat("Rendering frame.\n");
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-1, tile_dim*2-1, -1, tile_dim*2-1, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        image = icetGLDrawFrame();
        swap_buffers();

        if (rank == 0) {
            /* printrank("Rank == 0, tile should have stuff in it.\n"); */
        } else if (rank < tile_dim*tile_dim) {
            IceTFloat *cb;
            int color_component;

            if (   (my_width != icetImageGetWidth(image))
                || (my_height != icetImageGetHeight(image)) ) {
                printrank("Image size is wrong!!!!!!!!!\n");
                result = TEST_FAILED;
            }

            /* printrank("Checking returned image data.\n"); */
            cb = icetImageGetColorf(image);
            for (color_component = 0;
                 color_component < my_width*my_height*4;
                 color_component++) {
                if (cb[color_component] != 0.25f) {
                    printrank("Found bad pixel!!!!!!!!\n");
                    result = TEST_FAILED;
                    break;
                }
            }
        } else {
            /* printrank("Not a display node.  Not testing image.\n"); */
        }
    }

    return result;
}
Пример #11
0
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;
}
Пример #12
0
static void BackgroundCorrectDraw(const IceTDouble *projection_matrix,
                                  const IceTDouble *modelview_matrix,
                                  const IceTFloat *background_color,
                                  const IceTInt *readback_viewport,
                                  IceTImage result)
{
    IceTDouble full_transform[16];
    IceTSizeType width;
    IceTSizeType height;
    IceTFloat *colors;
    IceTFloat blended_color[4];

    /* This is mostly done for completeness.  Because we are blending and
       correcting the color, we totally expect background_color to be all zeros,
       and therefore blended_color should be equal to g_foreground_color.  The
       real blending will happen within IceT under the covers. */
    ICET_BLEND_FLOAT(g_foreground_color, background_color, blended_color);

    width = icetImageGetWidth(result);
    height = icetImageGetHeight(result);

    colors = icetImageGetColorf(result);

    /* Get full transform all the way to window coordinates (pixels). */ {
        IceTDouble scale_transform[16];
        IceTDouble translate_transform[16];
        icetMatrixScale(0.5*width, 0.5*height, 0.5, scale_transform);
        icetMatrixTranslate(1.0, 1.0, 1.0, translate_transform);
        icetMatrixMultiply(full_transform,scale_transform,translate_transform);
        icetMatrixPostMultiply(full_transform, projection_matrix);
        icetMatrixPostMultiply(full_transform, modelview_matrix);
    }

    /* Clear out the image (testing purposes only). */ {
        IceTSizeType pixel;
        for (pixel = 0; pixel < width*height; pixel++) {
            colors[pixel] = -1.0;
        }
    }

    /* Set my pixels. */ {
        IceTInt rank;
        IceTSizeType region_y_start;
        IceTSizeType region_x;
        IceTSizeType region_y;

        icetGetIntegerv(ICET_RANK, &rank);
        region_y_start = rank*PROC_REGION_HEIGHT;

        for (region_y = 0; region_y < PROC_REGION_HEIGHT; region_y++) {
            for (region_x = 0; region_x < PROC_REGION_WIDTH; region_x++) {
                IceTDouble object_coord[4];
                IceTDouble window_coord[4];
                IceTSizeType window_pixel[2];
                IceTSizeType readback_lower[2];
                IceTSizeType readback_upper[2];
                IceTBoolean in_readback;

                object_coord[0] = (IceTDouble)region_x;
                object_coord[1] = (IceTDouble)(region_y + region_y_start);
                object_coord[2] = 0.0;
                object_coord[3] = 1.0;

                icetMatrixVectorMultiply(window_coord,
                                         full_transform,
                                         object_coord);

                window_pixel[0]=(IceTSizeType)(window_coord[0]/window_coord[3]);
                window_pixel[1]=(IceTSizeType)(window_coord[1]/window_coord[3]);

                readback_lower[0] = readback_viewport[0];
                readback_lower[1] = readback_viewport[1];
                readback_upper[0] = readback_viewport[0] + readback_viewport[2];
                readback_upper[1] = readback_viewport[1] + readback_viewport[3];

                in_readback  = (readback_lower[0] <= window_pixel[0]);
                in_readback &= (readback_lower[1] <= window_pixel[1]);
                in_readback &= (window_pixel[0] < readback_upper[0]);
                in_readback &= (window_pixel[1] < readback_upper[1]);
                if (in_readback) {
                    IceTSizeType pixel_idx
                        = window_pixel[0] + window_pixel[1]*PROC_REGION_WIDTH;
                    colors[4*pixel_idx + 0] = blended_color[0];
                    colors[4*pixel_idx + 1] = blended_color[1];
                    colors[4*pixel_idx + 2] = blended_color[2];
                    colors[4*pixel_idx + 3] = blended_color[3];
                }
            }
        }
    }
}