Author Topic: Reverse Engineering Picture Styles  (Read 42792 times)

Lars Steenhoff

  • Member
  • ***
  • Posts: 166
Re: Reverse Engineering Picture Styles
« Reply #275 on: November 19, 2016, 01:57:55 AM »
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

  • Hero Member
  • *****
  • Posts: 843
  • 550D
Re: Reverse Engineering Picture Styles
« Reply #276 on: November 19, 2016, 03:04:31 AM »
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

  • Developer
  • Hero Member
  • *****
  • Posts: 2861
Re: Reverse Engineering Picture Styles
« Reply #277 on: November 20, 2016, 12:07:06 PM »
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.

dfort

  • Hero Member
  • *****
  • Posts: 1506
Re: Reverse Engineering Picture Styles
« Reply #278 on: November 21, 2016, 02:37:11 AM »
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?
EOSM.202 EOSM.203 700D.115 5D3.*

reddeercity

  • Hero Member
  • *****
  • Posts: 1227
Re: Reverse Engineering Picture Styles
« Reply #279 on: November 21, 2016, 05:28:20 AM »
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

  • Hero Member
  • *****
  • Posts: 1227
Re: Reverse Engineering Picture Styles
« Reply #280 on: November 21, 2016, 08:38:38 AM »
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
Code: [Select]
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 ?
Code: [Select]
0001:000898F8       FA_EnableLinerEShutCurve
0001:00089908       FA_DisableLinerEShutCurve

Something to do when connected thought USB cable ?
Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 2771
  • 5D3 / M1 / 7D / 70D / SL1
Reverse Engineering Picture Styles
« Reply #281 on: November 21, 2016, 06:34:40 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!

Maybe this is the Luma Curve ?
Code: [Select]
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.123 • EOSM.203 • 7D.203 • 70D.112 • 100D.101

dfort

  • Hero Member
  • *****
  • Posts: 1506
Re: Reverse Engineering Picture Styles
« Reply #282 on: November 21, 2016, 07:32:33 PM »
Hey @reddeercity - this is cool:

Code: [Select]
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.
EOSM.202 EOSM.203 700D.115 5D3.*

g3gg0

  • Developer
  • Hero Member
  • *****
  • Posts: 2861
Re: Reverse Engineering Picture Styles
« Reply #283 on: November 21, 2016, 08:15:33 PM »
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.

Lars Steenhoff

  • Member
  • ***
  • Posts: 166
Re: Reverse Engineering Picture Styles
« Reply #284 on: November 21, 2016, 08:22:14 PM »
@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

  • Hero Member
  • *****
  • Posts: 1227
Re: Reverse Engineering Picture Styles
« Reply #285 on: November 22, 2016, 02:41:29 AM »
@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

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   
Code: [Select]
line 55  // cached LUTs for BM2LV-like macros
Code: [Select]
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
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

  • Just arrived
  • *
  • Posts: 1
Re: Reverse Engineering Picture Styles
« Reply #286 on: December 19, 2016, 11:33:14 AM »
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

  • Hero Member
  • *****
  • Posts: 1227
Re: Reverse Engineering Picture Styles
« Reply #287 on: January 01, 2017, 06:32:05 AM »
@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.

reddeercity

  • Hero Member
  • *****
  • Posts: 1227

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 2771
  • 5D3 / M1 / 7D / 70D / SL1
5D3.123 • EOSM.203 • 7D.203 • 70D.112 • 100D.101

ItsMeLenny

  • Hero Member
  • *****
  • Posts: 843
  • 550D
Re: Reverse Engineering Picture Styles
« Reply #290 on: January 01, 2017, 01:14:45 PM »
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

  • Hero Member
  • *****
  • Posts: 1506
Re: Reverse Engineering Picture Styles
« Reply #291 on: January 02, 2017, 08:30:28 AM »
I'm still working on my little project to do with this thread...

Provocative.

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

Quote
USAGE:

     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.
EOSM.202 EOSM.203 700D.115 5D3.*

michael.huber.2932

  • New to the forum
  • *
  • Posts: 4
Re: Reverse Engineering Picture Styles
« Reply #292 on: January 24, 2017, 01:14:13 PM »
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

  • New to the forum
  • *
  • Posts: 4
Re: Reverse Engineering Picture Styles
« Reply #293 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.

agentirons

  • New to the forum
  • *
  • Posts: 42
Re: Reverse Engineering Picture Styles
« Reply #294 on: February 03, 2017, 06:56:44 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

  • New to the forum
  • *
  • Posts: 4
Re: Reverse Engineering Picture Styles
« Reply #295 on: February 04, 2017, 06:31:49 PM »
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

  • Hero Member
  • *****
  • Posts: 843
  • 550D
Re: Reverse Engineering Picture Styles
« Reply #296 on: February 05, 2017, 12:34:31 AM »
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

  • New to the forum
  • *
  • Posts: 42
Re: Reverse Engineering Picture Styles
« Reply #297 on: February 06, 2017, 06:22:41 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?

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.

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

  • New to the forum
  • *
  • Posts: 4
Re: Reverse Engineering Picture Styles
« Reply #298 on: February 07, 2017, 06:01:22 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.

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

  • New to the forum
  • *
  • Posts: 42
Re: Reverse Engineering Picture Styles
« Reply #299 on: February 10, 2017, 01:05:27 AM »
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.