示例#1
0
void Image_loadFromFile_works(CuTest* tc)
{
    Image* image = Image_new();
    BOOL result = Image_loadFromFile(image, "res/test.png");
    CuAssert(tc, "Could not load image.", result == TRUE);
    Image_delete(image);
}
示例#2
0
void Image_loadFromFile_shouldYieldCorrectImage(CuTest* tc)
{
    Image* image = Image_new();
    Image_loadFromFile(image, "res/test.png");

    CuAssert(tc, "Image contents incorrect.", memcmp(testImage, image->data, 6*8*4) == 0);

    Image_delete(image);
}
示例#3
0
void Image_loadFromFile_shouldYieldRightDimensions(CuTest* tc)
{
    Image* image = Image_new();
    Image_loadFromFile(image, "res/test.png");
    CuAssert(tc, "Image dimensions incorrect.", image->width == 6 && image->height == 8);
    CuAssertTrue(tc, image->channels == 3);
    CuAssertTrue(tc, image->bpp == 4);
    CuAssert(tc, "Image size incorrect.", 6*8*4 == image->size);

    Image_delete(image);
}
示例#4
0
int main()
{
    fprintf(stderr, "Testing image loading and saving.\n");
    Log_init();
    
    Image* myimage = Image_newFromData(reference, sizeof(reference), 4, 4, 4);
    
    if (!Image_saveToFile(myimage, "test-image.png"))
    {
        fprintf(stderr, "Saving image failed.\n");
        Image_delete(myimage);
        return 1;
    }
    
    Image* image = Image_new();
    if (!Image_loadFromFile(image, "test-image.png"))
    {
        fprintf(stderr, "Loading image failed.\n");
        Image_delete(image);
        return 1;
    }
    
    if (image->width * image->height * image->channels != image->size)
    {
        fprintf(stderr, "Image size incorrect.\n");
        fprintf(stderr, "Image width: %i, height: %i, channels: %i, size %i \n", image->width, image->height, image->channels, image->size);
        return 1;
    }
    
    int i;
    int j;
    int k;
    for(i = 0; i < image->height; i++)
    {
        for(j = 0; j < image->width; j++)
        {
            for(k = 0; k < image->channels; k++)
            {
                if (image->data[(i * image->channels * image->width) + (j * image->channels) + k] != reference[(i * image->channels * image->width) + (j * image->channels) + k])
                {
                    fprintf(stderr, "Image loaded is not the same as refrence at (%i, %i, %i)\n", i, j, k);
                    return 1;
                }
            }
        }
    }
    
    Image_delete(image);

    Log_terminate();

    return 0;
}
示例#5
0
void init()
{
    // int glfwInit( void )
    if (glfwInit() != GL_TRUE)
    {
        exit(EXIT_FAILURE);
    }

    // int glfwOpenWindow( int width, int height,
    //      int redbits, int greenbits, int bluebits,
    //      int alphabits, int depthbits, int stencilbits,
    //      int mode )
    if (glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) != GL_TRUE)
    {
        // void glfwTerminate( void )
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwSetWindowSizeCallback(windowResize);
    glClearColor(0.5, 0.0, 0.5, 0.0);

    console = StdoutConsole_new();
    Log_init(console);

    renderBatch = RenderBatch_new(4, TRUE);

    image = Image_new();
    Image_loadFromFile(image, "res/box.png");
    texture = Texture_newFromImage(image);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glEnable(GL_TEXTURE_2D);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}