liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.08k stars 1.71k forks source link

ccv_get_dense_matrix_cell_by() bug? #172

Closed dodoma closed 8 years ago

dodoma commented 8 years ago

hi, liuliu

#define ccv_get_dense_matrix_cell_by(type, x, row, col, ch) \
    (((type) & CCV_32S) ? (void*)((x)->data.i32 + ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_32F) ? (void*)((x)->data.f32+ ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_64S) ? (void*)((x)->data.i64+ ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_64F) ? (void*)((x)->data.f64 + ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (void*)((x)->data.u8 + (row) * (x)->step + (col) * CCV_GET_CHANNEL(type) + (ch))))))

should be this ?

#define ccv_get_dense_matrix_cell_by(type, x, row, col, ch) \
    (((type) & CCV_32S) ? (void*)((x)->data.i32 + ((row) * (x)->step + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_32F) ? (void*)((x)->data.f32+ ((row) * (x)->step + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_64S) ? (void*)((x)->data.i64+ ((row) * (x)->step + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (((type) & CCV_64F) ? (void*)((x)->data.f64 + ((row) * (x)->step + (col)) * CCV_GET_CHANNEL(type) + (ch)) : \
    (void*)((x)->data.u8 + (row) * (x)->step + (col) * CCV_GET_CHANNEL(type) + (ch))))))

E.g.

consider a 3 channel 32F matrix, with 100 rows, 200 cols, There should be 200 * 3 * 4 bytes per row, not 200 * 4 bytes.

liuliu commented 8 years ago

The original code is correct. i32 and f32 are (int) or (float) type, therefore, it is not counting by bytes.