Exemplo n.º 1
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.");
    }
}
Exemplo n.º 2
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");
    }
}
Exemplo n.º 3
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");
    }
}
Exemplo n.º 4
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();
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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];
                }
            }
        }
    }
}