updated C library to work with flattened images