Custom processing for JPEG (Tone curve, CA ...) - page 10 - Feature Requests - CHDK Forum supplierdeeply

Custom processing for JPEG (Tone curve, CA ...)

  • 101 Replies
  • 51434 Views
*

Online reyalp

  • ******
  • 12692
Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #90 on: 24 / June / 2009, 19:56:51 »
Advertisements
Hi,

Anyone figure out how to modify curves for the SX10 12 bit raw?  I have looked at the code and it is a mystery to me.

Jon
You'll need to do two things:
1) Adjust the curve code to deal with the 12 bpp format. You can find similar stuff in raw.c (setpixel, getpixel) and raw_merge.c. You can use the get/set functions, but they will probably be quite a bit slower.
2) Do something with the curve data itself to map make it deal with 12 bits.  If you just increase the curve table size, keep in mind this will take significantly more memory. You'd also have to come up with a way of producing 12 bit curve files, and provide a syscurve.cvf.

An alternative would be to keep the 10 bit curves and somehow map the 12 bit data to it. Given that the 12 bit data doesn't actually seem to have 12 bit resolution, this may be the better approach.

Alternately, you could do your curve processing on the PC.
Don't forget what the H stands for.

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #91 on: 24 / June / 2009, 23:02:46 »
Hi,

Anyone figure out how to modify curves for the SX10 12 bit raw?  I have looked at the code and it is a mystery to me.

Jon
You'll need to do two things:
1) Adjust the curve code to deal with the 12 bpp format. You can find similar stuff in raw.c (setpixel, getpixel) and raw_merge.c. You can use the get/set functions, but they will probably be quite a bit slower.
2) Do something with the curve data itself to map make it deal with 12 bits.  If you just increase the curve table size, keep in mind this will take significantly more memory. You'd also have to come up with a way of producing 12 bit curve files, and provide a syscurve.cvf.

An alternative would be to keep the 10 bit curves and somehow map the 12 bit data to it. Given that the 12 bit data doesn't actually seem to have 12 bit resolution, this may be the better approach.

Alternately, you could do your curve processing on the PC.

Thanks, I had forgotten about the routines in raw.c.  After studying them I wrote some code that seems to work.  I use it to do (up to) +-2 EV raw develop.  I generate the curves on the fly so don't have to worry about the official curves routines.
Code: [Select]
for (i=CAM_RAW_ROWS; i;i-=1){
// Loop through picture columns
for (j=CAM_RAW_ROWPIX; j; j-=4, src+=6){
pixVal0 = curve[(unsigned short)(*(src + 1) << 4) | ((*src) >> 4)];
pixVal1 = curve[(unsigned short)((*(src) & 0x0f) << 8) | *(src + 3)];
pixVal2 = curve[(unsigned short)(*(src + 2) << 4) | (*(src + 5) >> 4)];
pixVal3 = curve[(unsigned short)((*(src + 5) & 0x0f) << 8) | *(src + 4)];
 
*(src+1) = (unsigned char) (pixVal0 >> 4);
*(src+0) = (unsigned char) ((pixVal0 << 8) | (pixVal1 >> 8));
*(src+3) = (unsigned char) (pixVal1 & 0xFF);
*(src+2) = (unsigned char) (pixVal2 >> 4);
*(src+5) = (unsigned char) ((pixVal2 << 8) | (pixVal3 >> 8));
*(src+4) = (unsigned char) (pixVal3  & 0xFF);
}
}


*

Online reyalp

  • ******
  • 12692
Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #92 on: 24 / June / 2009, 23:30:05 »
Is curve now a 4096 element array ?
Don't forget what the H stands for.

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #93 on: 25 / June / 2009, 02:00:47 »
Is curve now a 4096 element array ?

Yes, I create the curve on the fly:
Code: [Select]
#if CAM_SENSOR_BITS_PER_PIXEL==12
#define CURVE_SIZE 4096
#endif
#if CAM_SENSOR_BITS_PER_PIXEL==10
#define CURVE_SIZE 1024
#endif
unsigned short curve[CURVE_SIZE];

void raw_change_ev() {
double mult;
double black;
short i,j;
unsigned short pixVal0, pixVal1, pixVal2, pixVal3;
unsigned char *src;

black = 0;
for(i=10;i<20;i++) black += get_raw_pixel(i,1);
black = black / 10;

mult = 1;
if(conf.raw_ev == 0) return;
if(conf.raw_ev == 1) mult = 1.5;
if(conf.raw_ev == 2) mult = 2;
if(conf.raw_ev == 3) mult = 3;
if(conf.raw_ev == 4) mult = 4;
if(conf.raw_ev == 5) mult = .25;
if(conf.raw_ev == 6) mult = .375;
if(conf.raw_ev == 7) mult = .5;
if(conf.raw_ev == 8) mult = .75;

for(i=0;i<CURVE_SIZE;i++) {
j = (short) ((i * mult) + black - mult * black);
if(j > CURVE_SIZE-1) j = CURVE_SIZE-1;
if(j < 0) j = 0;
curve[i] = j;
}

// Set pointer to picture raw data in memory
src = (unsigned char *) hook_raw_image_addr();


etc


Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #94 on: 08 / September / 2009, 01:09:21 »
Custom curves don't seem to be working the same as say adjusting curves in photoshop from what I've noticed. For example I thought it would be neat to have a custom curve that made the image have a "cross processed" look, this is relatively simple in photoshop or gimp however when I apply the same curve using the CurvesEditor4k program my results are just bizarre when I load the .CV file. I want to use the .cv file instead of the .cvf because the point of my curve is to get a little color shift.

I thought that maybe since it was a GRGB matrix that I shouldn't adjust the G1 & G2 channels as far, I essentially adjusted them half as far to compensate, this did not work either.

I just wanted to see if anyone had any info for me on this? Btw I really appreciate the work put into this, it would be great to have custom filter and film effects on camera.

My camera info:
Canon SD1100IS
ixus80_sd1100-101a-0.9.8-796-full FW

Also for what its worth here is a link to the type of curve effect I'm trying to accomplish
http://www.layersmagazine.com/curvy-cross-processing.html

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #95 on: 13 / November / 2009, 21:04:26 »
Hi,

Anyone figure out how to modify curves for the SX10 12 bit raw?  I have looked at the code and it is a mystery to me.

Jon

Sorry for the absence of response.
Here is how the curve data is stored -

   RGB curves:     ouput = curve[input]
   L curves:       output = curve[L] *(input-black) + black
   RGB curves and L curves are 4 colors curves
   L curves contain multiplicator factor (value = multiplicator * 2^12)
   
   DR curves:      output = curve[L] *(input-black) + black
   DR curves are gray scale only

For RGB:
If you have a 12 bit sensor you will need to extend the "curve" table to 4096 elements per channel *4 channels.
You may want to consider using a different extension for the file name (e.g. C12 instead of CV).
Next step is to figure out how the camera stored each of the channel in raw format (see raw.c).
The process is:
1. Extract channel data
2. Apply RGB curve (lookup table)
3. Repack data and store

For L curves
The curve table uses multiplicator of value ranged from [1/2^12 to 2^4]. This multiplicator is stored as
(multiplicator * 2^12). 2^12 is used to allow fast division by logical shift. The multiplicator is selected via lookup table
using the green value as index.
As we are multiplying, a control for overflow is done before storing the data back. We also redivide by 2^12 as in
the following macro:
Code: [Select]
#define CURVE0( a, b ) (((a) * curve0[b]) >> 12) - No change needed here.

See this macro for 10 bits(1023=2^10-1):
Code: [Select]
#define LIM( a ) (((a)>1023) ? 1023: a ) - Change needed here (4095 vs 1023)

The process is same as above.

Last but not least - Update the curve generation utility for 12 bits. As I am getting lazy I don't mind pasting the VB code here
if you want. Please let me know. You will need to have different extension for the name (eg. C12 v.s. CV and F12 v.s. CVF)
I will suggest to change the extension name of curve files as follow:
-C10 for 10 bit RGB curves
-C12 for 12 bit RGB curves
-F10 for 10 bit L curves
-F12 for 12 bit L curves

Toine

PS: The code gets a bit more complex as we want to avoid the black hole (dead pixel) and not converting them to black. The internal JPEG engine will take care of those.

Code: [Select]
// In this context pixVal1 is a green pixel
// If it is dead (i.e. 0) leave the corresponding red or blue untouched

if (pixVal1) {
                        // if not substract the standard black level
                        // with a min value of 0 in case it gets negative
pixVal1 = RBLACK( pixVal1 );

                               // if the corresponding red or blue pixel is not dead
                               // apply curve after removal of black value and add it back after multiplicator and adjust for overflow.

if (pixVal0) {
pixVal0 = RBLACK( pixVal0 );
pixVal0 = CURVE0( pixVal0, pixVal1 ) + BLACK;
pixVal0 = LIM( pixVal0 );
}

                                // apply curve to the green value
pixVal1 = CURVE1( pixVal1, pixVal1 ) + BLACK;
pixVal1 = LIM( pixVal1 );
}

No need to change the above code.
« Last Edit: 13 / November / 2009, 21:24:20 by toinech »

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #96 on: 11 / December / 2009, 12:03:54 »
Hi toinech,

it would be great to get the code of the curve editor

Greetz naddel

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #97 on: 20 / December / 2009, 21:54:38 »
I having some trouble getting this to work.  I have the latest chdk on my card with the syscurves.cvf file in my chdk directory and the curves files in the curves folder.  I load them via the alt menu, take a picture, and it looks normal.  I tried loading the syscurves file as a script and it didn't work either.  My camera is the a570IS.  Do I need to save as raw?  And last, is this still being developed?

*Nevermind, I found out.  I was getting confused on the wiki and was using "Auto DR" when I should have been using "custom". 
« Last Edit: 20 / December / 2009, 21:58:54 by Funky Dung »


Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #98 on: 23 / December / 2009, 21:31:21 »
I don't seem to be able to get the effects I want with the curveseditor.  I use Gimps' curve tool to see what the curve should look like then I set the same curve in the curveseditor tool, but when I take the picture, it looks nothing like it should.  Even using the "solarizing curve" from http://www.curvemeister.com/support/curvemeister2/help/Articles/CurveMoves.htm doesn't work correctly (it takes a very light purplish pic).  Does this not work well for the a570?

Re: Custom processing for JPEG (Tone curve, CA ...)
« Reply #99 on: 15 / May / 2010, 10:48:41 »
Hi toinech,

it would be great to get the code of the curve editor

Greetz naddel

Sorry for the delay- but here is some code.
My PC crashed and I was lucky to find the old code (VB6) stashed somewhere.

 

 

Related Topics