Merging r47674 through r47676 from trunk into soc-2011-tomato
This commit is contained in:
@@ -910,7 +910,7 @@ DO_INLINE int get_bin_float(float f)
|
||||
return bin;
|
||||
}
|
||||
|
||||
DO_INLINE void save_sample_line(Scopes *scopes, const int idx, const float fx, const float rgb[3], const float ycc[3])
|
||||
static void save_sample_line(Scopes *scopes, const int idx, const float fx, const float rgb[3], const float ycc[3])
|
||||
{
|
||||
float yuv[3];
|
||||
|
||||
@@ -953,9 +953,9 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
|
||||
double div, divl;
|
||||
float *rf = NULL;
|
||||
unsigned char *rc = NULL;
|
||||
unsigned int *bin_r, *bin_g, *bin_b, *bin_lum;
|
||||
unsigned int *bin_lum, *bin_r, *bin_g, *bin_b, *bin_a;
|
||||
int savedlines, saveline;
|
||||
float rgb[3], ycc[3], luma;
|
||||
float rgba[4], ycc[3], luma;
|
||||
int ycc_mode = -1;
|
||||
const short is_float = (ibuf->rect_float != NULL);
|
||||
|
||||
@@ -987,11 +987,12 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
|
||||
break;
|
||||
}
|
||||
|
||||
/* temp table to count pix value for histo */
|
||||
bin_r = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_g = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_b = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_lum = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
/* temp table to count pix value for histogram */
|
||||
bin_r = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_g = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_b = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_a = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
bin_lum = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
|
||||
|
||||
/* convert to number of lines with logarithmic scale */
|
||||
scopes->sample_lines = (scopes->accuracy * 0.01f) * (scopes->accuracy * 0.01f) * ibuf->y;
|
||||
@@ -1038,27 +1039,28 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
|
||||
|
||||
if (is_float) {
|
||||
if (use_color_management)
|
||||
linearrgb_to_srgb_v3_v3(rgb, rf);
|
||||
linearrgb_to_srgb_v3_v3(rgba, rf);
|
||||
else
|
||||
copy_v3_v3(rgb, rf);
|
||||
copy_v3_v3(rgba, rf);
|
||||
rgba[3] = rf[3];
|
||||
}
|
||||
else {
|
||||
for (c = 0; c < 3; c++)
|
||||
rgb[c] = rc[c] * INV_255;
|
||||
for (c = 0; c < 4; c++)
|
||||
rgba[c] = rc[c] * INV_255;
|
||||
}
|
||||
|
||||
/* we still need luma for histogram */
|
||||
luma = rgb_to_luma(rgb);
|
||||
luma = rgb_to_luma(rgba);
|
||||
|
||||
/* check for min max */
|
||||
if (ycc_mode == -1) {
|
||||
for (c = 0; c < 3; c++) {
|
||||
if (rgb[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgb[c];
|
||||
if (rgb[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgb[c];
|
||||
if (rgba[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgba[c];
|
||||
if (rgba[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgba[c];
|
||||
}
|
||||
}
|
||||
else {
|
||||
rgb_to_ycc(rgb[0], rgb[1], rgb[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode);
|
||||
rgb_to_ycc(rgba[0], rgba[1], rgba[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode);
|
||||
for (c = 0; c < 3; c++) {
|
||||
ycc[c] *= INV_255;
|
||||
if (ycc[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = ycc[c];
|
||||
@@ -1066,16 +1068,17 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
|
||||
}
|
||||
}
|
||||
/* increment count for histo*/
|
||||
bin_r[get_bin_float(rgb[0])] += 1;
|
||||
bin_g[get_bin_float(rgb[1])] += 1;
|
||||
bin_b[get_bin_float(rgb[2])] += 1;
|
||||
bin_lum[get_bin_float(luma)] += 1;
|
||||
bin_r[get_bin_float(rgba[0])] += 1;
|
||||
bin_g[get_bin_float(rgba[1])] += 1;
|
||||
bin_b[get_bin_float(rgba[2])] += 1;
|
||||
bin_a[get_bin_float(rgba[3])] += 1;
|
||||
|
||||
/* save sample if needed */
|
||||
if (saveline) {
|
||||
const float fx = (float)x / (float)ibuf->x;
|
||||
const int idx = 2 * (ibuf->x * savedlines + x);
|
||||
save_sample_line(scopes, idx, fx, rgb, ycc);
|
||||
save_sample_line(scopes, idx, fx, rgba, ycc);
|
||||
}
|
||||
|
||||
rf += ibuf->channels;
|
||||
@@ -1089,27 +1092,26 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management)
|
||||
n = 0;
|
||||
nl = 0;
|
||||
for (x = 0; x < 256; x++) {
|
||||
if (bin_r[x] > n)
|
||||
n = bin_r[x];
|
||||
if (bin_g[x] > n)
|
||||
n = bin_g[x];
|
||||
if (bin_b[x] > n)
|
||||
n = bin_b[x];
|
||||
if (bin_lum[x] > nl)
|
||||
nl = bin_lum[x];
|
||||
if (bin_lum[x] > nl) nl = bin_lum[x];
|
||||
if (bin_r[x] > n) n = bin_r[x];
|
||||
if (bin_g[x] > n) n = bin_g[x];
|
||||
if (bin_b[x] > n) n = bin_b[x];
|
||||
if (bin_a[x] > n) n = bin_a[x];
|
||||
}
|
||||
div = 1.0 / (double)n;
|
||||
divl = 1.0 / (double)nl;
|
||||
for (x = 0; x < 256; x++) {
|
||||
scopes->hist.data_luma[x] = bin_lum[x] * divl;
|
||||
scopes->hist.data_r[x] = bin_r[x] * div;
|
||||
scopes->hist.data_g[x] = bin_g[x] * div;
|
||||
scopes->hist.data_b[x] = bin_b[x] * div;
|
||||
scopes->hist.data_luma[x] = bin_lum[x] * divl;
|
||||
scopes->hist.data_a[x] = bin_a[x] * div;
|
||||
}
|
||||
MEM_freeN(bin_lum);
|
||||
MEM_freeN(bin_r);
|
||||
MEM_freeN(bin_g);
|
||||
MEM_freeN(bin_b);
|
||||
MEM_freeN(bin_lum);
|
||||
MEM_freeN(bin_a);
|
||||
|
||||
scopes->ok = 1;
|
||||
}
|
||||
|
||||
@@ -754,8 +754,12 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
|
||||
fdrawline(rect.xmin + (i / 4.f) * w, rect.ymin, rect.xmin + (i / 4.f) * w, rect.ymax);
|
||||
}
|
||||
|
||||
if (hist->mode == HISTO_MODE_LUMA)
|
||||
if (hist->mode == HISTO_MODE_LUMA) {
|
||||
histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
|
||||
}
|
||||
else if (hist->mode == HISTO_MODE_ALPHA) {
|
||||
histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line);
|
||||
}
|
||||
else {
|
||||
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
|
||||
histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);
|
||||
|
||||
@@ -2150,7 +2150,7 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
|
||||
y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f);
|
||||
|
||||
if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y) {
|
||||
hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = 0.0f;
|
||||
hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = hist->data_a[i] = 0.0f;
|
||||
}
|
||||
else {
|
||||
if (ibuf->rect_float) {
|
||||
@@ -2161,17 +2161,19 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
|
||||
else
|
||||
copy_v3_v3(rgb, fp);
|
||||
|
||||
hist->data_r[i] = rgb[0];
|
||||
hist->data_g[i] = rgb[1];
|
||||
hist->data_b[i] = rgb[2];
|
||||
hist->data_luma[i] = rgb_to_luma(rgb);
|
||||
hist->data_luma[i] = rgb_to_luma(rgb);
|
||||
hist->data_r[i] = rgb[0];
|
||||
hist->data_g[i] = rgb[1];
|
||||
hist->data_b[i] = rgb[2];
|
||||
hist->data_a[i] = fp[3];
|
||||
}
|
||||
else if (ibuf->rect) {
|
||||
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
|
||||
hist->data_r[i] = (float)cp[0] / 255.0f;
|
||||
hist->data_g[i] = (float)cp[1] / 255.0f;
|
||||
hist->data_b[i] = (float)cp[2] / 255.0f;
|
||||
hist->data_luma[i] = (float)rgb_to_luma_byte(cp) / 255.0f;
|
||||
hist->data_luma[i] = (float)rgb_to_luma_byte(cp) / 255.0f;
|
||||
hist->data_r[i] = (float)cp[0] / 255.0f;
|
||||
hist->data_g[i] = (float)cp[1] / 255.0f;
|
||||
hist->data_b[i] = (float)cp[2] / 255.0f;
|
||||
hist->data_a[i] = (float)cp[3] / 255.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +96,14 @@ typedef enum CurveMappingPreset {
|
||||
} CurveMappingPreset;
|
||||
|
||||
/* histogram->mode */
|
||||
#define HISTO_MODE_LUMA 0
|
||||
#define HISTO_MODE_RGB 1
|
||||
#define HISTO_MODE_R 2
|
||||
#define HISTO_MODE_G 3
|
||||
#define HISTO_MODE_B 4
|
||||
enum {
|
||||
HISTO_MODE_LUMA = 0,
|
||||
HISTO_MODE_RGB = 1,
|
||||
HISTO_MODE_R = 2,
|
||||
HISTO_MODE_G = 3,
|
||||
HISTO_MODE_B = 4,
|
||||
HISTO_MODE_ALPHA = 5
|
||||
};
|
||||
|
||||
enum {
|
||||
HISTO_FLAG_LINE = (1 << 0),
|
||||
@@ -110,17 +113,18 @@ enum {
|
||||
typedef struct Histogram {
|
||||
int channels;
|
||||
int x_resolution;
|
||||
float data_luma[256];
|
||||
float data_r[256];
|
||||
float data_g[256];
|
||||
float data_b[256];
|
||||
float data_luma[256];
|
||||
float data_a[256];
|
||||
float xmax, ymax;
|
||||
short mode;
|
||||
short flag;
|
||||
int height;
|
||||
|
||||
/* sample line only */
|
||||
/* image coords src -> est */
|
||||
/* image coords src -> dst */
|
||||
float co[2][2];
|
||||
} Histogram;
|
||||
|
||||
|
||||
@@ -575,9 +575,10 @@ static void rna_def_histogram(BlenderRNA *brna)
|
||||
{HISTO_MODE_R, "R", 0, "R", "Red"},
|
||||
{HISTO_MODE_G, "G", 0, "G", "Green"},
|
||||
{HISTO_MODE_B, "B", 0, "B", "Blue"},
|
||||
{HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
srna = RNA_def_struct(brna, "Histogram", NULL);
|
||||
RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user