-1

I have tried searching for a day for converting JPEG & PNG to RAW image format(*.raw format), but couldn't find any and all the result were RAW to JPEG/PNG. Finally i decided to ask here hoping will get the answer.

So, i want to convert images of format JPEG & PNG to RAW image format(*.raw) only and for that i need C++ library which can do this work. Also, if you can suggest some step by step process to achieve it using C++ will be helpful. As i don't have experience in this and not getting start up.

Please guide me for the same. Your help is highly appreciated.

Thanks

Aasim
  • 113
  • 2
  • 14
  • Why down vote? Is there anything wrong with it? I tried for a long and could find the solution then i asked here. – Aasim Jul 29 '20 at 08:05
  • There are not that many answers about your problem. You are quite right. But you can think in two steps and I think you may find an answer : first uncompress your image, then store it in raw (whatever your reason to do it is). Look at this, eg : https://stackoverflow.com/questions/27477441/opening-a-jpeg-or-png-image-as-pixel-data-in-c-or-c – Marvin Jul 29 '20 at 08:38
  • Please note that questions asking us to recommend or find a tool, software library etc. are off-topic for Stack Overflow. Please browse the [help for asking questions](https://stackoverflow.com/help/asking) and in particular [**What topics can I ask about here?**](https://stackoverflow.com/help/on-topic) to see what you can ask. The downvote wasn't me but that could be the reason why you got it) – FluffyKitten Jul 29 '20 at 10:21
  • @FluffyKitten, i agree with but why i asked this question because i searched for a whole day on internet including SO but could find any library for it and i was exhausted. Lastly i decided to ask here if could get any information about as there are surely people who has expertise in it or used it. And why i am asking for the library because i have short time and need to use this library for the project. And now as guided by Marvin, i am looking into that direction if could get what i want. . By the way, i will follow the community guidelines. – Aasim Jul 29 '20 at 11:19
  • Thank you @Marvin, i am going into that direction and hoping will get the solution. Meanwhile if could go through this SO answer https://photo.stackexchange.com/questions/1455/what-is-raw-technically/8361#8361 and tell me which step to do from going JPEG to RAW format after your suggested answer. BTW, i am looking into it. Thanks – Aasim Jul 29 '20 at 11:23

2 Answers2

3

"Raw" is not a well defined format.

Depending on who you talk to, it could mean a manufacturer's proprietary unprocessed format, such as:

  • Nikon's NEF format or
  • Canon's CR2 format or
  • Adobe's DNG format

Almost no software supports writing such files. dcraw and ufraw support reading them.

Or it could mean straight RGB888 bytes with no header or size information. Many libraries support this:

  • CImg is probably the simplest - link
  • OpenCV can do it
  • ImageMagick Magick++ can do it
  • libvips can do it

You don't need to actually write any C/C++ to convert a JPEG/PNG to raw RGB bytes, you can just use ImageMagick in the commandline:

magick input.png -depth 8 RGB:result.raw
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks @Mark Setchell for your valuable response. I have to pass the converted RAW image file to SDK API, which accept *.RAW image format for some processing. So, is it possible to convert? – Aasim Jul 29 '20 at 22:18
  • The raw file above from Mark Setchell is just a string of byte data. You have to tell the reading software the width, height and depth of the image for it to read it properly. You need to see what information your SDK API needs to accept the RAW image. – fmw42 Jul 30 '20 at 00:22
  • 1
    @Aasim I don't kmow. As I said, RAW format is not well defined. You'll need to check in your SDK, or with its vendor, what they mean. – Mark Setchell Jul 30 '20 at 06:33
  • @MarkSetchell, could you please see [this question](https://stackoverflow.com/questions/64286451/jpeg-image-rotation-in-c-using-libjpeg), to rotate the JPEG image? – Aasim Oct 12 '20 at 04:40
0

Technically you can not convert JPEG/PNG to RAW images. Because RAW images contains lot of data captured from the camera. JPEG image are compressed image format where most of the information ripped off. So you can not write a program to perverse the ripped of data and restore the original RAW image. (Even though you wrote a program, generated RAW file not equivalent to the originally captured RAW file)

hasi90
  • 84
  • 8
  • Thanks @hasi90 for response. It is fine if i loose some information and it is obvious that we can not restore all the thing from JPEG/PNG to RAW. So, there is any library in C++ which can do it? – Aasim Jul 29 '20 at 06:02
  • Also, in JPEG/PNG information is compression to reduce the size as compared to RAW format(Where JPEG is lossy whereas PNG is looseless). But while converting to RAW, we can decompress the JPEG/PNG and convert it to RAW. And in this process we definitely can not retrieve their original RAW counterpart but the one with some less information than their original RAW counterpart. So, how can it be achieved and is there any C++ library available for it? – Aasim Jul 29 '20 at 07:15