static int BackgroundCorrectCheckImage(const IceTImage image)
{
    IceTInt rank;

    icetGetIntegerv(ICET_RANK, &rank);
    if (rank == 0) {
        IceTInt num_proc;
        IceTInt proc;
        const IceTFloat *pixel;

        icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);

        pixel = icetImageGetColorcf(image);

        for (proc = 0; proc < num_proc; proc++) {
            if (!BackgroundCorrectCheckImageRegion(&pixel, g_blended_color)) {
                printrank("For process %d\n", proc);
                if (ColorsEqual(pixel, g_foreground_color)) {
                    printrank("Pixel never blended with background.\n");
                }
                return TEST_FAILED;
            }
        }

        /* Also check a final patch on top that should be background. */
        if (!BackgroundCorrectCheckImageRegion(&pixel, g_background_color)) {
            printrank("For background area\n");
            return TEST_FAILED;
        }
    }

    return TEST_PASSED;
}
static IceTBoolean BackgroundCorrectCheckImageRegion(
                                                const IceTFloat **pixel_p,
                                                const IceTFloat *expected_color)
{
    IceTInt x, y;
    const IceTFloat *pixel = *pixel_p;
    for (y = 0; y < PROC_REGION_HEIGHT; y++) {
        for (x = 0; x < PROC_REGION_WIDTH; x++) {
            if (!ColorsEqual(pixel, expected_color)) {
                *pixel_p = pixel;
                printrank("**** Found bad pixel!!!! ****\n");
                printrank("Region location x = %d, y = %d\n", x, y);
                printrank("Got color %f %f %f %f\n",
                          pixel[0], pixel[1], pixel[2], pixel[3]);
                printrank("Expected %f %f %f %f\n",
                          expected_color[0],
                          expected_color[1],
                          expected_color[2],
                          expected_color[3]);
                return ICET_FALSE;
            }
            pixel += 4;
        }
    }

    *pixel_p = pixel;
    return ICET_TRUE;
}
示例#3
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)) {
        printrank("ERROR: Image formats do not match.\n");
        return ICET_FALSE;
    }

    if (   (icetImageGetWidth(image_a) != icetImageGetWidth(image_b))
        || (icetImageGetHeight(image_a) != icetImageGetHeight(image_b)) ) {
        printrank("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]) ) {
                printrank("ERROR: Encountered bad pixel @ (%d,%d).\n", x, y);
                printrank("Expected (%d, %d, %d, %d)\n",
                          data_a[0], data_a[1], data_a[2], data_a[3]);
                printrank("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;
}
示例#4
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 {
        printrank("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 {
        printrank("ERROR: Encountered unknown depth format.");
    }
}
示例#5
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)) {
        printrank("ERROR: Image formats do not match.\n");
        return ICET_FALSE;
    }

    if (   (icetImageGetWidth(image_a) != icetImageGetWidth(image_b))
        || (icetImageGetHeight(image_a) != icetImageGetHeight(image_b)) ) {
        printrank("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]) {
                printrank("ERROR: Encountered bad pixel @ (%d,%d).\n", x, y);
                printrank("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;
}
示例#6
0
static void InitActiveImage(IceTImage image)
{
  /* Create a worst case possible for image with respect to compression.
     All the pixels are active, so no data can be removed. */
    IceTEnum format;
    IceTSizeType num_pixels;
    int seed;

    seed = (int)time(NULL);
    srand(seed);

    num_pixels = icetImageGetNumPixels(image);

    format = icetImageGetColorFormat(image);
    if (format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
        IceTUByte *buffer = icetImageGetColorub(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[4*i + 0] = (IceTUByte)(rand()%255 + 1);
            buffer[4*i + 1] = (IceTUByte)(rand()%255 + 1);
            buffer[4*i + 2] = (IceTUByte)(rand()%255 + 1);
            buffer[4*i + 3] = (IceTUByte)(rand()%255 + 1);
        }
    } else if (format == ICET_IMAGE_COLOR_RGBA_FLOAT) {
        IceTFloat *buffer = icetImageGetColorf(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[4*i + 0] = ((IceTFloat)(rand()%255 + 1))/255;
            buffer[4*i + 1] = ((IceTFloat)(rand()%255 + 1))/255;
            buffer[4*i + 2] = ((IceTFloat)(rand()%255 + 1))/255;
            buffer[4*i + 3] = ((IceTFloat)(rand()%255 + 1))/255;
        }
    } else if (format != ICET_IMAGE_COLOR_NONE) {
        printrank("*** Unknown color format? ***\n");
    }

    format = icetImageGetDepthFormat(image);
    if (format == ICET_IMAGE_DEPTH_FLOAT) {
        IceTFloat *buffer = icetImageGetDepthf(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[i] = ((IceTFloat)(rand()%255))/255;
        }
    } else if (format != ICET_IMAGE_DEPTH_NONE) {
        printrank("*** Unknown depth format? ***\n");
    }
}
示例#7
0
static void InitPathologicalImage(IceTImage image)
{
  /* Create a worst case possible for image with respect to compression.
     Every other pixel is active so the run lengths are all 1. */
    IceTEnum format;
    IceTSizeType num_pixels;

    num_pixels = icetImageGetNumPixels(image);

    format = icetImageGetColorFormat(image);
    if (format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
        IceTUByte *buffer = icetImageGetColorub(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[4*i + 0] = 255*(IceTUByte)(i%2);
            buffer[4*i + 1] = 255*(IceTUByte)(i%2);
            buffer[4*i + 2] = 255*(IceTUByte)(i%2);
            buffer[4*i + 3] = 255*(IceTUByte)(i%2);
        }
    } else if (format == ICET_IMAGE_COLOR_RGBA_FLOAT) {
        IceTFloat *buffer = icetImageGetColorf(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[4*i + 0] = (IceTFloat)(i%2);
            buffer[4*i + 1] = (IceTFloat)(i%2);
            buffer[4*i + 2] = (IceTFloat)(i%2);
            buffer[4*i + 3] = (IceTFloat)(i%2);
        }
    } else if (format != ICET_IMAGE_COLOR_NONE) {
        printrank("*** Unknown color format? ***\n");
    }

    format = icetImageGetDepthFormat(image);
    if (format == ICET_IMAGE_DEPTH_FLOAT) {
        IceTFloat *buffer = icetImageGetDepthf(image);
        IceTSizeType i;
        for (i = 0; i < num_pixels; i++) {
            buffer[i] = (IceTFloat)(i%2);
        }
    } else if (format != ICET_IMAGE_DEPTH_NONE) {
        printrank("*** Unknown depth format? ***\n");
    }
}
示例#8
0
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;
}
示例#9
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;
}