Regarding printf's, you need to find out why it fails (why it takes some particular code path, what are the return values etc). Some example in pseudocode:
int x = check_this();
if (x > y)
{
do_this();
return 5;
}
else
{
return do_that();
}
After adding printf's, it could look like this:
int x = check_this();
printf("check_this returned %d, expecting > %d\n", x, y);
if (x > y)
{
printf("doing this\n");
do_this();
return 5;
}
else
{
printf("doing that\n");
int ret = do_that();
printf("do_that returned %d\n", ret);
return ret;
}
In particular, we need to find out why the DNGs are not saved - likely bad input data to save_dng. Was save_lossless_dng able to allocate memory? (print the input and output values: max_compressed_size and out_suite). Did the lossless compression work? What return value did you get? (it returns compressed size or negative error code). Does the raw data get recognized by save_dng as a lossless stream? (return value of is_lossless_jpeg). What's the size of the data it's trying to write to card? And so on.
If it's able to allocate memory, but for some reason, lossless_compress_raw fails, compare with your version and see what's different. Do you try to compress an image with different size? (maybe smaller? maybe some dimension is modulo some power of 2? no idea here, there may be additional hardware restrictions on certain cameras).