Skip to content

Commit

Permalink
Added Simple Highlight Reconstruction
Browse files Browse the repository at this point in the history
Will need some improving for colour accuracy, however it's quite fast.
@masc4ii maybe you can add a checkbox to qt GUI - 'Highlight Reconstruction' - use functions processingEnableHighlightReconstruction() and processingDisableHighlightReconstruction()
  • Loading branch information
ilia3101 authored Jul 23, 2017
1 parent b74c716 commit 0b6c196
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
15 changes: 14 additions & 1 deletion platform/cocoa/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,20 @@ int NSApplicationMain(int argc, const char * argv[])
//CREATE_SLIDER_RIGHT( sharpnessSlider, sharpnessLabel, sharpnessValueLabel, @"Sharpen", 10, sharpnessMethod, BLOCK_OFFSET * 2, 0.0 );
/* Maybe we won't have sharpness */

/* Enable/disable highlight reconstruction */
NSButton * highlightReconstructionSelector = [ [NSButton alloc]
initWithFrame: NSMakeRect( RIGHT_SIDEBAR_SLIDER(11, ELEMENT_HEIGHT, 16) )];
[highlightReconstructionSelector setButtonType: NSSwitchButton];
[highlightReconstructionSelector setTitle: @"Highlight Reconstruction"];
[highlightReconstructionSelector anchorRight: YES];
[highlightReconstructionSelector anchorTop: YES];
[highlightReconstructionSelector setTarget: highlightReconstructionSelector];
[highlightReconstructionSelector setAction: @selector(toggleHighlightReconstruction)];
[[window contentView] addSubview: highlightReconstructionSelector];

/* To set always use AMaZE on/off */
NSButton * alwaysUseAmazeSelector = [ [NSButton alloc]
initWithFrame: NSMakeRect( RIGHT_SIDEBAR_SLIDER(11, ELEMENT_HEIGHT, 11) )];
initWithFrame: NSMakeRect( RIGHT_SIDEBAR_SLIDER(12, ELEMENT_HEIGHT, 30) )];
[alwaysUseAmazeSelector setButtonType: NSSwitchButton];
[alwaysUseAmazeSelector setTitle: @"Always use AMaZE"];
[alwaysUseAmazeSelector anchorRight: YES];
Expand Down Expand Up @@ -193,6 +204,8 @@ int NSApplicationMain(int argc, const char * argv[])
videoMLV = initMlvObject();
/* Intialise the processing settings object */
processingSettings = initProcessingObject();
/* Allow highlight reconstruction */
processingDisableHighlightReconstruction(processingSettings);
/* Set exposure to + 1.2 stops instead of correct 0.0, this is to give the impression
* (to those that believe) that highlights are recoverable (shhh don't tell) */
processingSetExposureStops(processingSettings, 1.2);
Expand Down
17 changes: 17 additions & 0 deletions platform/cocoa/main_methods.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,27 @@ -(void)toggleAlwaysAmaze
if ([self state] == NSOnState)
{
setMlvAlwaysUseAmaze(videoMLV);
frameChanged++;
}
else
{
setMlvDontAlwaysUseAmaze(videoMLV);
frameChanged++;
}
}

/* Enables/disables highlight reconstruction */
-(void)toggleHighlightReconstruction
{
if ([self state] == NSOnState)
{
processingEnableHighlightReconstruction(processingSettings);
frameChanged++;
}
else
{
processingDisableHighlightReconstruction(processingSettings);
frameChanged++;
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/processing/processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ void processing_update_matrices(processingObject_t * processing)
/* Temporary working matrix */
double temp_matrix_a[9];

/* (for shorter code) */
int32_t ** pm = processing->pre_calc_matrix;

/* Exposure */
double exposure_factor = pow(2.0, processing->exposure_stops);

Expand Down Expand Up @@ -121,10 +124,13 @@ void processing_update_matrices(processingObject_t * processing)
{
for (int j = 0; j < 65536; ++j)
{
processing->pre_calc_matrix[i][j] = (int32_t)((double)j * processing->final_matrix[i]);
pm[i][j] = (int32_t)((double)j * processing->final_matrix[i]);
}
}

/* Highest green value - pixels at this value will need to be reconstructed */
processing->highest_green = LIMIT16(pm[3][65535] + pm[4][65535] + pm[5][65535]);

/* This is nice */
printMatrix(processing->final_matrix);

Expand Down
4 changes: 4 additions & 0 deletions src/processing/processing_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ typedef struct {
/* (RAW) white and black levels */
int black_level, white_level;

/* Do highlight reconstrucion? It's slow */
int highlight_reconstruction;
uint16_t highest_green; /* Used for reconstruction */

/* Double is classy */

/* Camera's matrix - will need to be set on opening clip, default set for 5D Mark II */
Expand Down
21 changes: 16 additions & 5 deletions src/processing/raw_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
/* Matrix functions which are useful */
#include "../matrix/matrix.h"

/* Because why compile a whole .o just for this? */
#include "processing.c"


#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define LIMIT16(X) MAX(MIN(X, 65535), 0)

/* Because why compile a whole .o just for this? */
#include "processing.c"

/* Initialises processing thing with memory */
processingObject_t * initProcessingObject()
Expand Down Expand Up @@ -114,6 +112,19 @@ void applyProcessingObject( processingObject_t * processing,
pix[2] = LIMIT16(pix2);
}

/* Now highlilght reconstruction */
if (processing->highest_green < 65535 && processing->highlight_reconstruction)
{
for (uint16_t * pix = img; pix < img_end; pix += 3)
{
/* Check if its the highest green value possible */
if (pix[1] == processing->highest_green)
{
pix[1] = (pix[0] + pix[2]) / 2;
}
}
}

/* Gamma */
for (int i = 0; i < img_s; ++i)
{
Expand All @@ -122,7 +133,7 @@ void applyProcessingObject( processingObject_t * processing,

/* Now saturation (looks way better after gamma)
* Also this algorithm is slow, but temporary */
for (uint16_t * pix = img; pix < img_end; pix += 3)
for (uint16_t * pix = outputImage; pix < img_end; pix += 3)
{
/* Pixel brightness = 4/16 R, 11/16 G, 1/16 blue; Try swapping the channels, it will look worse */
int32_t Y1 = ((pix[0] << 2) + (pix[1] * 11) + pix[2]) >> 4;
Expand Down
6 changes: 6 additions & 0 deletions src/processing/raw_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void processingSetGamma(processingObject_t * processing, double gammaValue);



/* Enable/disable highlight reconstruction */
#define processingEnableHighlightReconstruction(processing) (processing)->highlight_reconstruction = 1
#define processingDisableHighlightReconstruction(processing) (processing)->highlight_reconstruction = 0



/* Those ML matrices, camera specific */
void processingSetXyzToCamMatrix(processingObject_t * processing, double * xyzToCamMatrix);
/* This is whatever, probably doesn't need touching */
Expand Down

0 comments on commit 0b6c196

Please sign in to comment.