/* 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."); } }
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"); } }
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"); } }
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(); }