Changeset 9

Show
Ignore:
Timestamp:
10/26/2008 4:39:47 PM (13 months ago)
Author:
anonymous
Message:

Fixed improper use of GIL ctor.

I was using the 3-argument ctor for the image class, but GIL trats the 3rd arg. as the image alignment instead of the default pixel value. I had to use the 4 arg. ctor.

This issue suggests a testing practice — always assert that the image has the values you think it should to begin with, and never use 0.0f as an initial value since it is too likely to be accidentally correct.

Location:
gilx/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • gilx/trunk/options.py

    r3 r9  
     1variant = 'all' 
  • gilx/trunk/src/test/test_gil_image_of_regular_type.cpp

    r8 r9  
    1313template<class Regular> 
    1414void test_type(){ 
    15     //A single channel type should be both planar and interleaved, so I 
    16     //am inclined to pass 'true' for planar. Niether option actually compiles. 
    17  
    1815 
    1916    typedef boost::gil::image<float> float_image; 
    2017    typedef float_image::view_t float_view; 
    2118 
    22     float_image img_(256, 256, 0.0f); 
     19    //NOTE: The last argument is necessary 
     20    //      -- gil assumes the 3rd arg. is the alignment otherwise. 
     21    float_image img_(256, 256, 1.0f, 0u); 
    2322    float_view img = view(img_); 
     23 
     24    //Verify image constructed properly (suggested by Nathan Stien). 
     25    I3DEA_CHECK_EQUAL(std::count(img.begin(), img.end(), 1.0f), 256*256); 
    2426 
    2527    for (int r = 0; r < img.height(); ++r) { 
     
    3133    } 
    3234 
    33     I3DEA_CHECK_ALMOST_EQUAL(img(128, 128), 3.0f, 0.001); 
     35    I3DEA_CHECK_EQUAL(img(128, 128), 4.0f); 
    3436 
    3537    float_view::locator loc; 
    3638    loc = img.xy_at(128, 128); 
    37     I3DEA_CHECK(*loc == 3.0f); 
     39    I3DEA_CHECK_EQUAL(*loc, 4.0f); 
    3840} 
    3941