Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several small improvements #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ and
vcsm_free(state.lens_shading);
```
when finished.

ls_table.txt is a comma separated file for easy visualization with Gnuplot. For a colored plot of all samples:
```
set palette defined (0 "red", 1 "yellow", 2 "magenta", 3 "blue")
splot "ls_table.txt" using 1:2:3:4 w p ps 0.75 pt 7 lc palette z notitle
```
Single sample plot ($4==0 => red):
```
splot "ls_table.txt" using 1:2:($4==0?$3:1/0)
```
14 changes: 11 additions & 3 deletions lens_shading_analyse.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ uint16_t black_level_correct(uint16_t raw_pixel, unsigned int black_level, unsig
int main(int argc, char *argv[])
{
int in = 0;
FILE *out, *header;
FILE *out, *header, *table;
int i, x, y;
uint16_t *out_buf[NUM_CHANNELS];
void *mmap_buf;
Expand All @@ -134,6 +134,7 @@ int main(int argc, char *argv[])
int bayer_order;
struct brcm_raw_header *hdr;
int width, height, stride;
int grid_width, grid_height;
int single_channel_width, single_channel_height;
unsigned int black_level = 16;

Expand Down Expand Up @@ -208,6 +209,10 @@ int main(int argc, char *argv[])
height = hdr->height;
single_channel_width = width/2;
single_channel_height = height/2;
grid_width = single_channel_width / 32 + (single_channel_width % 32 == 0 ? 0 : 1);
grid_height = single_channel_height / 32 + (single_channel_height % 32 == 0 ? 0 : 1);
printf("Grid size: %d x %d\n", grid_width, grid_height);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quicker to do (single_channel_width + 31) / 32


//Stride computed via same formula as the firmware uses.
stride = (((((width + hdr->padding_right)*5)+3)>>2) + 31)&(~31);

Expand Down Expand Up @@ -260,6 +265,7 @@ int main(int argc, char *argv[])
printf("Save data. Bayer order is %d\n", bayer_order);

header = fopen("ls_table.h", "wb");
table = fopen("ls_table.txt", "wb");
fprintf(header, "uint8_t ls_grid[] = {\n");
for (i=0; i<NUM_CHANNELS; i++)
{
Expand Down Expand Up @@ -321,6 +327,7 @@ int main(int argc, char *argv[])
else if (gain < 32)
gain = 32; //Clip at x1.0
fprintf(header, "%d, ", gain );
fprintf(table, "%d %d %d %d\n", x, y, gain, i );
}
//Compute edge value from the very edge 2 pixels.
{
Expand All @@ -331,14 +338,15 @@ int main(int argc, char *argv[])
else if (gain < 32)
gain = 32; //Clip at x1.0
fprintf(header, "%d,\n", gain );
fprintf(table, "%d %d %d %d\n", x, y, gain, i );
}
}

}
fprintf(header, "};\n");
fprintf(header, "uint32_t ref_transform = %u;\n", hdr->transform);
fprintf(header, "uint32_t grid_width = %u;\n", (single_channel_width>>5)+1);
fprintf(header, "uint32_t grid_height = %u;\n", (single_channel_height>>5)+1);
fprintf(header, "uint32_t grid_width = %u;\n", grid_width);
fprintf(header, "uint32_t grid_height = %u;\n", grid_height);

for (i=0; i<NUM_CHANNELS; i++)
{
Expand Down