Reverse Engineering Picture Styles

Started by dfort, December 07, 2015, 05:50:39 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Lars Steenhoff

http://web.canon.jp/imaging/picturestyle/file/videocamera.html

perhaps the canon video x?   I have never used it but im curious how it compares

ItsMeLenny

Honestly I'm not the one to call this, but I feel as if this is getting slightly off topic, maybe a new thread should be started for comparisons of picture styles.
On top of that, I guess what's valuable, at least in this thread, is how the picture styles are made, not how they compare visually. It would be valuable if there were two very visually similar picture styles but one did something worse (had bad banding or something) and that was a result of how the picture style is put together under the hood.

In terms of comparing picture styles, I'm just assuming here that you're going to take a photo in each picture style. Even if all settings are kept the same I don't think this is the best or easiest way to go about it. All you'd need to do is take one photo in RAW and then put it into canons DPP software (digital photo professional) and apply the different picture styles.

In saying that it's still a visual comparison (which I guess what the photo looks like at the end of the day is what counts). A better process would be to generate a CR2 image that can fake itself as being taken with a canon that has linear gradients of 0% to 100% black to white and red green blue channels, feed this into DPP and see what the curves actually are, which would also allow finding the canon film curve, also the difference in colours between neutral faithful etc. In addition to faking these raw images to have them look as though they come from different canon models, which would allow to see if the curves do change between camera sensors (assuming this is all in the software, which I'm going to assume it is, if it exists in the first place).

I will actually make one of these CR2 images, hopefully this weekend, which it is the weekend already. Anybody who would like a copy it will only cost $12.99 :P

g3gg0

didn't follow the whole thread.

but if you want to know where the custom picture styles are located, i'd say they are stored in the properties.

you can dump the properties using PropertyEditor.exe which i just updated
see http://www.magiclantern.fm/forum/index.php?topic=4729.msg27865#msg27865

it will operate on a ROM-dump and save all properties as viewable XML.
some models have a CUST property region, like 6D or 60D. would expect it there.
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

dfort

Quote from: g3gg0 on November 20, 2016, 12:07:06 PM
you can dump the properties using PropertyEditor.exe which i just updated

Going to have to dust off the old Windows Laptop to try it out. Is the code available so I could compile a Mac binary?

reddeercity

Quote from: g3gg0 on November 20, 2016, 12:07:06 PM
it will operate on a ROM-dump and save all properties as viewable XML.
some models have a CUST property region, like 6D or 60D. would expect it there.
Just tried on my 5D2 Rom0.BIN got a lot of  "<Property Id=" string but I don't know what they are and not sure where to look to figure out what there mean.

But I got this string with text I under stand ,

Quote
          </Property>
          <Property Id="02000001" BaseAddress="00310024" Length="00000010">
            <String>2.1.2_A1(00)____</String>
            <Data>322E312E320041312830302900000000</Data>
          </Property>
          <Property Id="02000005" BaseAddress="0031003C" Length="00000010">
            <String>6.9.8 A1(00)____</String>
            <Data>362E392E382041312830302900000000</Data>
          </Property>
          <Property Id="02000002" BaseAddress="00310054" Length="00000004">
            <String>____</String>
            <Data>00000000</Data>
          </Property>
          <Property Id="02000003" BaseAddress="00310060" Length="00000004">
            <String>____</String>
            <Data>FFFFFFFF</Data>
          </Property>
          <Property Id="02000004" BaseAddress="0031006C" Length="00000020">
            <String>David Miazga_,__________________</String>
            <Data>4461766964204D69617A6761002C000000000000000000000000000000000000</Data>
          </Property>
         
In red , the first text is my firmware "2.1.2" , next not sure "6.9.8 A1" and then my name .
this repeat itself thought out the xml file from the Rom0.BIN file  , I could not get the programs to dump the Rom1.BIN file just
gave a error "Autodetect property offset failed"

Below is the my XML file , if anyone wishes to have a look and maybe can understand it more.
https://www.dropbox.com/s/cn4fiog894b8hd1/ROM0.BIN_00310000.propxml?dl=0

reddeercity

On my search for info on Property Id string definitions I came upon this old firmware map from 5D2 , I thing it's from 2008 or 2009
below is the link to my Dropbox , just use a text editor to view the *.map
https://www.dropbox.com/s/cwwu89uldl3loql/5D21070a.map?dl=0
what I found very interesting about where Picture Style is in the blocks

0001:001B06E0       GUI_SetPictureStyleData
0001:001B082C       GUI_GetPictureStyleData
0001:001B094C       GUI_SetPictureStyleOfUserSetting
0001:001B09B4       GUI_GetPictureStyleOfUserSetting
0001:001B0A00       GUI_GetPsUserSetting_PCsetValid
0001:001B0A4C       GUI_GetPsUserSetting_PCsetParam
0001:001B0BCC       GUI_GetPsUserSetting_PCsetValid_0



Maybe this is the Luma Curve ?
0001:000898F8       FA_EnableLinerEShutCurve
0001:00089908       FA_DisableLinerEShutCurve


Something to do when connected thought USB cable ?
0001:002990A0       StopLiveViewPictureStyleApp
0001:00299508       StartLiveViewPictureStyleApp
0001:002BE868       StartShootOlcPictureStyleApp
0001:002BEA08       UpdateShootOlcPictureStyleApp
0001:0034030C       StopMnPictureStyleDetailApp
0001:003407BC       StartMnPictureStyleDetailApp
0001:00340F1C       StopMnPictureUserDetailApp
0001:003413C0       StartMnPictureUserDetail


Hope this helps :)

DeafEyeJedi

Quote from: g3gg0 on November 20, 2016, 12:07:06 PM
you can dump the properties using PropertyEditor.exe which i just updated
see http://www.magiclantern.fm/forum/index.php?topic=4729.msg27865#msg27865

it will operate on a ROM-dump and save all properties as viewable XML.
some models have a CUST property region, like 6D or 60D. would expect it there.

Thanks for making progress on this project @g3gg0!

Quote from: reddeercity on November 21, 2016, 08:38:38 AM
Maybe this is the Luma Curve ?
0001:000898F8       FA_EnableLinerEShutCurve
0001:00089908       FA_DisableLinerEShutCurve


Holy SHIT @reddeercity that's some serious digging you have done there...

This definitely smells good. Thanks for sharing these!!!  :)
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

dfort

Hey @reddeercity - this is cool:

0001:002990A0       StopLiveViewPictureStyleApp
0001:00299508       StartLiveViewPictureStyleApp
0001:002BE868       StartShootOlcPictureStyleApp
0001:002BEA08       UpdateShootOlcPictureStyleApp
0001:0034030C       StopMnPictureStyleDetailApp
0001:003407BC       StartMnPictureStyleDetailApp
0001:00340F1C       StopMnPictureUserDetailApp
0001:003413C0       StartMnPictureUserDetail


Wonder if it would be possible to display one picture style on the live view while recording another picture style. This would be like an external monitor that can use luts so that it can preview what a log image will look like after it has a look applied to it.

g3gg0

but dont confuse memory addresses with property IDs

properties are "containers" that are managed by a property manager.
routines can allocate a property and can place any data in it.
the property manager takes care of storing it into flash (which is not a too simple task if you want to make it robust)

that stuff you see in the .propxml is a human readable representation of the content in the flash.
all properties found in the container you specified on the command line are dumped into that .propxml.

there are a few property containers. check the post that i linked in the post before.
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

Lars Steenhoff

@dfort. this is what i already kind of do with raw recording, I put the picture style to high sharpness and good contrast to get a nice image while recording in the liveview. and when i open the raw the picture style is not applied.  It could be nice if the picture style that is used for recodring is stored in the metadata of the mlv, then during raw conversion the same picture style lut can be applied. in this way we can have the look consistent between recoding and post.


reddeercity

@g3gg0 thanks for the help , I'll do more reading in fact being reading a lot of old reverse engineering thread from 2013 etc... being given me a few ideas for this thread .

@DeafEyeJedi not really just got lucky to find that .map file , but that's what you get from reading obsolete threads  :D

Quote from: dfort on November 21, 2016, 07:32:33 PM
Hey @reddeercity - this is cool:
Wonder if it would be possible to display one picture style on the live view while recording another picture style.
This would be like an external monitor that can use luts so that it can preview what a log image will look like after it has a look applied to it.

Thanks, It may be possible at some point , not by me thou .
After reading thought many old threads about h264 and 422 mjpeg  reverse engineering ,
It seems there is a lut for HDMI and or Liveview made reference to in a some documentation I read not too sure if 2 different styles/LUTS can be applied    line 55  // cached LUTs for BM2LV-like macros line 370  vram_update_luts(); 
those two lines came from bitbucket.org/hudson/magic-lantern/src/tip/src/vram.c  lot of info about hdmi , this is way be on my ability right now , but I'm learning  :D

Ok back on topic
Quote from: Lars Steenhoff on November 21, 2016, 08:22:14 PM
It could be nice if the picture style that is used for recording is stored in the metadata of the mlv,
then during raw conversion the same picture style lut can be applied. in this way we can have the look consistent between recoding and post.
Will if the info that I'm working on lead me to the source data of picture style  then you will have a exact copy of your PS in  a LUT or ICC
which picture style are (ICC Profiles), then that can be converted to DCP for ACR etc.... .

kyusu

hi
There i find this blog, he make a file CINEMAEX.cpf

http://ntown.at/2013/11/20/canon-cinema-custom-picture-styles/
http://ntown.at/2015/01/08/canon-c100-cpp-noise-test/

Very low noise level  :)
Some one think it's possible to adapt (Reverse Engineering ) this picture style to .pf2 for the canon dsrl ?  ;D

ps: sorry for my english  :-[
kyusu

reddeercity

@kyusu this thread is for Reverse Engineering picture styles (pf2 , pf3) for eos dslr's !
Apples & Oranges one fruit here only , if you want to know more about c100's profile start reverse engineering the cpf file
and let us know.


DeafEyeJedi

5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

ItsMeLenny

Quote from: reddeercity on January 01, 2017, 07:02:48 AM
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#PictureStyle
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#PSInfo
Looks like we have some "0x" Values in the tags here , may be useful

Just came across this a couple weeks back.
This is the EXIF data in the CR2 files, however the "Canon PictureStyle Values" does make me wonder if those extra ones are available in cameras that don't have them.

I'm still working on my little project to do with this thread which I have to finish before I can get back into looking at the stuff in the camera itself.

dfort

Quote from: ItsMeLenny on January 01, 2017, 01:14:45 PM
I'm still working on my little project to do with this thread...

Provocative.

Quote from: kyusu on December 19, 2016, 11:33:14 AM
...make a file CINEMAEX.cpf
...
Some one think it's possible to adapt (Reverse Engineering ) this picture style to .pf2 for the canon dsrl ?  ;D
.

Although as @reddeercity says it is a different "fruit" look at the way custom picture styles are installed on the Canon cinema cameras:

QuoteUSAGE:

     Just copy the files on a SD Card in the directory structure PRIVATE/C_PICT
      (create it if it's not on the sdcard)

     import them via Custom Picture Menu:

     Transfer File -> Load from SD -> (A or B)

     or just set the CP directly from the SD-Card.

Wouldn't that be cool? For still cameras you get three custom picture styles maximum and you need to use EOS Utility to load them.

michael.huber.2932

Thanks for the stunning progress investigating the file structure of PF2 and PF3! So amazing!

In the excel sheet I recognized a block called "3x20 Matrix sRGB [long]". What can you do with this block? Is it a transformation of RGB-pixel values from one to another value? If so, can someone give me a short example how the transformation is being performed?

michael.huber.2932

@agentirons

If you have some time you can update the specification of PF2.

In the "10 18 00 04   RGB Gamma [long]" block you can enter 12 points for each RGB-channel. The channel order is definitely R, G, B. I have tested this and reproduced curves from Photoshop. Works like charme. The values are altered independently of each channel.

agentirons

Quote from: michael.huber.2932 on January 24, 2017, 01:19:11 PM
@agentirons

If you have some time you can update the specification of PF2.

In the "10 18 00 04   RGB Gamma [long]" block you can enter 12 points for each RGB-channel. The channel order is definitely R, G, B. I have tested this and reproduced curves from Photoshop. Works like charme. The values are altered independently of each channel.

Sure thing, sorry I didn't copy that from the Cinestyle tab into the main tab. It's the same for L*a*b* Gamma too.

For everyone's reference, the way it works is that for each channel, the first set of 4 bytes (ie 00 00 00 02) indicates how many points there are in the curve, and then each pair of 8 bytes following corresponds to an input and output for that point, used to calculate transformations from incoming data. So for instance if there are only 2 curve points, then the first set of I/O corresponds to black level and the next set corresponds to white level, and the remaining values in that channel are left blank. If there are three points, then first is black, second is your custom point, third is white, and the rest are blank. Strangely, the max seems to be twelve even though there's enough space in each data block for 15 points. So, each channel within the data block will always end with at least 24 bytes of zeros.

I think the biggest thing to figure out right now is how much manipulation is possible using the picture styles, and whether the base picture style (ie Landscape) can be negated somehow so that we can effectively apply curves directly to the raw data.

My project that I've been poking away at is a Javascript-based style editor, using Electron as a cross-platform app container. You can drop in a file, see all the data as hex values with tag names as you see in the spreadsheet, and edit individual values for saving back out. At this point I have to get the edit and save parts working, then I'll post a link. With something like this it will at least be much easier for people to see what they're editing while we test custom values out.

michael.huber.2932

Unfortunately the pf2-format only allows to define 3 channels. But often you want to add another RGB-curve that affects all channels at the same time. For example you want to add some contrast with the help of curves. In Photoshop you usually do this with a s-curve in the "RGB-channel". There are 2 solutions here:

1) Replicate this "RGB-channel" to each channel separately. So 3x the same curve in the red-, green- and blue-channel. This is exactly what the "RGB-channel" does.

2) But sometimes the red-channel has its own curve. Or maybe the green- or blue-channel. So in this case you have to add two curves to "simulate" the non existing rgb-curve in pf2-format. All you have to do is to overlap the control-points of the separate channel and the rgb-channel.

The PF3-format has an adavantage here. There you can define a additional RGB-curve that you can use for this purpose. Although I can create "valid files" that are accepted by EOS Utility and the camera, I can't see the effect of the applied curve (5D Mark III) in the live view/resulting image. If I use the exact same file in Canon Digital Professionel or my other cam EOS 5Ds (s!) it works. This is very strange!

Note: I made a lot of tests and sometimes the curves in Photoshop does not exactly look like the curves in PSE - even if use the exact control points. So I think Canon uses a different interpolation method than Adobe. To fit the curve I sometimes have to add another control points for the exact desired replication of the curves.

Does anyone has some information about the PF3-format and can tell me why these files are so huge compared to a PF2-file?

ItsMeLenny

Quote from: agentirons on February 03, 2017, 06:56:44 PM
I think the biggest thing to figure out right now is how much manipulation is possible using the picture styles, and whether the base picture style (ie Landscape) can be negated somehow so that we can effectively apply curves directly to the raw data.

I though the base picture style is neutral.

But also, is this still all done on top of canons film curve, or is that actually hidden away in the picture style?

agentirons

Quote from: michael.huber.2932 on February 04, 2017, 06:31:49 PM
The PF3-format has an adavantage here. There you can define a additional RGB-curve that you can use for this purpose. Although I can create "valid files" that are accepted by EOS Utility and the camera, I can't see the effect of the applied curve (5D Mark III) in the live view/resulting image. If I use the exact same file in Canon Digital Professionel or my other cam EOS 5Ds (s!) it works. This is very strange!

That is strange - did you make those files by hex edit or through the Canon Picture Style Editor software?

Quote from: michael.huber.2932 on February 04, 2017, 06:31:49 PM
Does anyone has some information about the PF3-format and can tell me why these files are so huge compared to a PF2-file?

I haven't dug all the way in but from what I've seen it's just down to the existence of many more tags available in the pf3 format. For instance, in PSE, the extra Sharpness settings, Tone curve (RGB), and the entire Six-color axes tab are not saved in pf2 format. I believe the minimum size for pf3 comes in around 450kb. For instance, I saved a custom pf3 out of PSE with default settings, and the resulting file had 3D LUTs inside for both sRGB and AdobeRGB that each took up 216kb of data.

Quote from: ItsMeLenny on February 05, 2017, 12:34:31 AM
I though the base picture style is neutral.

But also, is this still all done on top of canons film curve, or is that actually hidden away in the picture style?

The Base Picture Style is determined by the 0x1009 tag ("Base Picture Style ID") in the file, with at least nine known styles available. If you open up the PSE program it's the first dropdown option in the Basic tab. I think @andy600 would know better about whether the Canon film curve is involved, as I'm sure he would have dealt with that in his Cinelog work.

michael.huber.2932

Quote from: agentirons on February 06, 2017, 06:22:41 PM
That is strange - did you make those files by hex edit or through the Canon Picture Style Editor software?

I saved a basic file with no adjustments from Canon Picture Style Editor and made my changes in a hex-editor. It's very strange that my pf3-file works in the 5Ds, but not in the 7D Mark I / 5D Mark III.

Quote from: agentirons on February 06, 2017, 06:22:41 PM
I haven't dug all the way in but from what I've seen it's just down to the existence of many more tags available in the pf3 format. For instance, in PSE, the extra Sharpness settings, Tone curve (RGB), and the entire Six-color axes tab are not saved in pf2 format. I believe the minimum size for pf3 comes in around 450kb. For instance, I saved a custom pf3 out of PSE with default settings, and the resulting file had 3D LUTs inside for both sRGB and AdobeRGB that each took up 216kb of data.

Ok, that makes sense, that the pf3-files are much larger than the pf2-files if there are 3d-luts. Do you have more information about the 3d-luts? Do you know the offsets of the two tables and any idea how to use these informations? This would be real cool if we can have customized 3D LUTs out of Photoshop for example. We could nearly reproduce any effect/filter made in Photoshop.

Just a guess: maybe Canon PSE creates a 3D-LUT in the case of the PF3-format out of the seetings made with the Canon Tool and uses this one to make the adjustments in the camera. This would be an explanation why my changes in the PF3-files are ignored in the 7D I and 5D Mark III.

agentirons

Quote from: michael.huber.2932 on February 07, 2017, 06:01:22 PM
I saved a basic file with no adjustments from Canon Picture Style Editor and made my changes in a hex-editor.

That could be due to the "Finalize" tag, which acts as a checksum. It's possible that some cameras can ignore it. If you change data in a hex editor without modifying the Finalize block, then the checksum is incorrect and PSE will tell you there's something wrong with the file if you try to load it. But, I found that Canon's downloadable styles don't even include Finalize, and if you remove it with a hex editor and load the file into PSE it will both load correctly and when saved PSE will handle generating a correct tag for you.

I think it's easiest to just remove it, but the latest .JAR version of the encoding script posted earlier in this thread includes the correct formula for generating a valid Finalize tag.

As for the 3D LUTs, it's certain to be very powerful but I don't know anything about how to properly edit them yet.