How can I convert bmp to linear jpeg

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
sadasar
Posts: 7
Joined: 2016-08-31T01:14:11-07:00
Authentication code: 1151

How can I convert bmp to linear jpeg

Post by sadasar » 2016-08-31T01:20:58-07:00

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

snibgo
Posts: 10856
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert bmp to linear jpeg

Post by snibgo » 2016-08-31T01:49:28-07:00

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?
snibgo's IM pages: im.snibgo.com

sadasar
Posts: 7
Joined: 2016-08-31T01:14:11-07:00
Authentication code: 1151

Re: How can I convert bmp to linear jpeg

Post by sadasar » 2016-08-31T01:55:05-07:00

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).

snibgo
Posts: 10856
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert bmp to linear jpeg

Post by snibgo » 2016-08-31T03:25:12-07:00

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.
snibgo's IM pages: im.snibgo.com

sadasar
Posts: 7
Joined: 2016-08-31T01:14:11-07:00
Authentication code: 1151

Re: How can I convert bmp to linear jpeg

Post by sadasar » 2016-08-31T03:35:42-07:00

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.

snibgo
Posts: 10856
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert bmp to linear jpeg

Post by snibgo » 2016-08-31T04:00:43-07:00

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.
snibgo's IM pages: im.snibgo.com

sadasar
Posts: 7
Joined: 2016-08-31T01:14:11-07:00
Authentication code: 1151

Re: How can I convert bmp to linear jpeg

Post by sadasar » 2016-08-31T05:04:17-07:00

So I apply the quality and gamma function to the bmp image and then transform it to jpg?

snibgo
Posts: 10856
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I convert bmp to linear jpeg

Post by snibgo » 2016-08-31T05:16:25-07:00

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.
snibgo's IM pages: im.snibgo.com

sadasar
Posts: 7
Joined: 2016-08-31T01:14:11-07:00
Authentication code: 1151

Re: How can I convert bmp to linear jpeg

Post by sadasar » 2016-08-31T05:18:41-07:00

Great thanks

Post Reply