diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/colortools.c | 62 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 20 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_color_types.h | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_color.c | 3 |
5 files changed, 61 insertions, 48 deletions
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index d15f678f1c5..12dee600532 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -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; } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 1300c1d266c..f6339d4456f 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -753,8 +753,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); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 5075147869d..97f3bd744dc 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -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; } } } diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index dd2b38ffcf5..99e2a123fe7 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -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; diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index bd0e6c36c48..ce0b396caf7 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -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"); |