i sure hope you used dcraw for raw conversion, otherwise you might have re-invented the wheel
the basic idea for image conversion usually is:
- load format x (this should give you a bitmap)
- convert said bitmap to destination format y
i recommended using libjpeg (
http://freshmeat.net/projects/libjpeg/)
just spare yourself the effort of reinventing the wheel
esp. for image processing algorithms the already existing solution is magnitudes
better/faster than what you would come up with.
unless you're a image processing god, or the problem is very special ;-)