Page 1 of 1

How can I convert bmp to linear jpeg

Posted: 2016-08-31T01:20:58-07:00
by sadasar
Hello,

I want to convert a bmp image to jpeg. But I want to be able to change the parameters of the jpeg image that is created. I want to use linear gamma, because i want to get linear jpeg in the end. Is there a function that does this?

Thanks

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T01:49:28-07:00
by snibgo
I think IM always encodes JPEG files as YCbCr colorspace, converting from and to sRGB (non-linear). If your image is linear (RGB colorspace), IM will first convert it to sRGB. Most software will assume the JPEG has been encoded that way.

The workaround is to convert your image to linear RGB, if it isn't already encoded that way, but then tell IM that the image is actually non-linear sRGB. You do this with "-set colorspace sRGB". For example:

Code: Select all

convert rose: -colorspace RGB -set colorspace sRGB s.jpg
Then s.jpg will be encoded as linear but viewers will think it is sRGB, so it will appear dark.

I'm curious. Why do you want to do this?

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T01:55:05-07:00
by sadasar
Can I do that in C++ ? I have a lot of bmp images that are 80MB each one. So it takes a lot of memory, that is way I want to convert it to JPEG. When I use the CImage functions the new jpeg image is only 3MB I lose a lot of information. So that is why I want to be able to change the parameters of the converted JPEG image in C++(I forgot to mention that before).

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T03:25:12-07:00
by snibgo
Certainly, you can do it in C++, or various other languages. You might want to experiment at the command-line first, before writing any code.

Jpegs are only 8 bits/channel/pixel, so if your BMPs are 16 bits/channel/pixel you immediately throw away half your data. The "-quality" setting then determines how far the compression will go.

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T03:35:42-07:00
by sadasar
Yes your right the -quality is what I'm looking for maybe -gamma also but I could not find any function that takes as parameters the quality, the gamma and the other parameters and transforms the image from bmp to jpg using this parameters. Everything around 10Mb(the original is 80Mb) is fine for me.

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T04:00:43-07:00
by snibgo
sadasar wrote:... but I could not find any function that takes as parameters the quality, the gamma and the other parameters and transforms the image from bmp to jpg using this parameters.
These are separate functions. One to read a file (the BMP), another to write a file (the JPG). In the middle, call functions to change colorspace or gamma or set the quality or whatever you want.

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T05:04:17-07:00
by sadasar
So I apply the quality and gamma function to the bmp image and then transform it to jpg?

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T05:16:25-07:00
by snibgo
Not exactly. You read images from any raster file format you want. At the end, you write images to whatever raster file format you want. In the middle you do whatever processing you want to the raster images. But these are images you are processing, not specifically BMP images.

Re: How can I convert bmp to linear jpeg

Posted: 2016-08-31T05:18:41-07:00
by sadasar
Great thanks