klauspost / rawspeed

Raw Image Decoder Library
GNU Lesser General Public License v2.1
72 stars 20 forks source link

Fix some unaligned reads (they don't work well on non-x86 platforms) #147

Closed xen2 closed 8 years ago

klauspost commented 8 years ago

I didn't know that trick. Do you know if it works on all both GCC and MSVC?

xen2 commented 8 years ago

I tested it only with MSVC and EMCC (Emscripten) which is using Clang; I am almost sure GCC is fine with it but didn't check it.

xen2 commented 8 years ago

Note: there are probably many other cases like this to fix, just fixed a few so that I could read a .ARW without problem. I should find many more while testing more files in the next weeks.

xen2 commented 8 years ago

Also, for now I take worst-case alignment to 1, but 2 bytes might be enough.

klauspost commented 8 years ago

Some of the bitpumps uses this to access 32 bits at the time instead of 8.

klauspost commented 8 years ago

Just out of curiosity. What platform are you experiencing problems on?

xen2 commented 8 years ago

Emscripten (javascript) don't like it, and ARM would crash as well. Generally it is undefined behavior, but it happens to work on x86 (however, even on x86 it is a slow path when unaligned).

xen2 commented 8 years ago

Just realized that after rebasing on latest version, as you said, changes in BitPumpPlain.cpp are needed. I will submit additional patches soon.