Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2010-01-19 04:32:06 +0300
committerMatt Ebb <matt@mke3.net>2010-01-19 04:32:06 +0300
commitaab8196a1c16a1695a168c486fc6883953f97722 (patch)
treebcd6de7e916feba5f068936eb7e289605b0fb87a /source/blender/blenkernel/intern/colortools.c
parent849024df83602758f134695495eb0b19a6993421 (diff)
Finished some work from the weekend to keep local tree clean..
* Added a generic 'histogram' ui control, currently available in new image editor 'scopes' region (shortcut P). Shows the histogram of the currently viewed image. It's a baby step in unifying the functionality and code from the sequence editor, so eventually we can migrate the sequence preview to the image editor too, like compositor. Still a couple of rough edges to tweak, regarding when it updates. Also would be very nice to have this region as a partially transparent overlapping region...
Diffstat (limited to 'source/blender/blenkernel/intern/colortools.c')
-rw-r--r--source/blender/blenkernel/intern/colortools.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 09c65f4b21d..ceab3eb259a 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -878,3 +878,85 @@ void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
}
}
+/* ***************** Histogram **************** */
+
+static inline int get_bin_float(float f)
+{
+ CLAMP(f, 0.0, 1.0);
+
+ //return (int) (((f + 0.25) / 1.5) * 512);
+
+ return (int)(f * 511);
+}
+
+
+void histogram_update(Histogram *hist, ImBuf *ibuf)
+{
+ int x, y, n;
+ double div;
+ float *rf;
+ unsigned char *rc;
+ unsigned int *bin_r, *bin_g, *bin_b;
+
+ if (hist->ok == 1 ) return;
+
+ /* hmmmm */
+ if (!(ELEM(ibuf->channels, 3, 4))) return;
+
+ hist->channels = 3;
+
+ bin_r = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+ bin_g = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+ bin_b = MEM_callocN(512 * sizeof(unsigned int), "temp historgram bins");
+
+ if (ibuf->rect_float) {
+ hist->x_resolution = 512;
+
+ /* divide into bins */
+ rf = ibuf->rect_float;
+ for (y = 0; y < ibuf->y; y++) {
+ for (x = 0; x < ibuf->x; x++) {
+ bin_r[ get_bin_float(rf[0]) ] += 1;
+ bin_g[ get_bin_float(rf[1]) ] += 1;
+ bin_b[ get_bin_float(rf[2]) ] += 1;
+ rf+= ibuf->channels;
+ }
+ }
+ }
+ else if (ibuf->rect) {
+ hist->x_resolution = 256;
+
+ rc = (unsigned char *)ibuf->rect;
+ for (y = 0; y < ibuf->y; y++) {
+ for (x = 0; x < ibuf->x; x++) {
+ bin_r[ rc[0] ] += 1;
+ bin_g[ rc[1] ] += 1;
+ bin_b[ rc[2] ] += 1;
+ rc += ibuf->channels;
+ }
+ }
+ }
+
+ /* convert to float */
+ n=0;
+ for (x=0; x<512; 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];
+ }
+ div = 1.f/(double)n;
+ for (x=0; x<512; x++) {
+ hist->data_r[x] = bin_r[x] * div;
+ hist->data_g[x] = bin_g[x] * div;
+ hist->data_b[x] = bin_b[x] * div;
+ }
+
+ MEM_freeN(bin_r);
+ MEM_freeN(bin_g);
+ MEM_freeN(bin_b);
+
+ hist->ok=1;
+}