X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=imagesqueeze.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fimagesqueeze%2Fcodec%2FColor.java;h=08535a278ce5a5738c5aaeed4ee88cd4a48903e4;hp=1d8b7a62a95440dc7b23731a75a6170f6d7e3274;hb=4bcffe8896c08c9f60b2707da71bb39a64618d93;hpb=c7d0b8e1723045c0df086d9214a35f54db47684c diff --git a/src/main/java/eu/svjatoslav/imagesqueeze/codec/Color.java b/src/main/java/eu/svjatoslav/imagesqueeze/codec/Color.java index 1d8b7a6..08535a2 100755 --- a/src/main/java/eu/svjatoslav/imagesqueeze/codec/Color.java +++ b/src/main/java/eu/svjatoslav/imagesqueeze/codec/Color.java @@ -1,3 +1,12 @@ +/* + * Imagesqueeze - Image codec optimized for photos. + * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation. + */ + package eu.svjatoslav.imagesqueeze.codec; /** @@ -13,37 +22,48 @@ public class Color { int u; int v; - public void YUV2RGB(){ + public void RGB2YUV() { - b = (int)(y + 1.4075 * (v - 128)); - g = (int)(y - 0.3455 * (u - 128) - (0.7169 * (v - 128))); - r = (int)(y + 1.7790 * (u - 128)); + y = (int) ((r * 0.299000) + (g * 0.587000) + (b * 0.114000)); + u = (int) ((r * -0.168736) + (g * -0.331264) + (b * 0.500000) + 128); + v = (int) ((r * 0.500000) + (g * -0.418688) + (b * -0.081312) + 128); - if (r < 0) r = 0; - if (g < 0) g = 0; - if (b < 0) b = 0; + if (y < 0) + y = 0; + if (u < 0) + u = 0; + if (v < 0) + v = 0; - if (r > 255) r = 255; - if (g > 255) g = 255; - if (b > 255) b = 255; + if (y > 255) + y = 255; + if (u > 255) + u = 255; + if (v > 255) + v = 255; } - public void RGB2YUV(){ + public void YUV2RGB() { + + b = (int) (y + (1.4075 * (v - 128))); + g = (int) (y - (0.3455 * (u - 128)) - (0.7169 * (v - 128))); + r = (int) (y + (1.7790 * (u - 128))); - y = (int)(r * 0.299000 + g * 0.587000 + b * 0.114000); - u = (int)(r * -0.168736 + g * -0.331264 + b * 0.500000 + 128); - v = (int)(r * 0.500000 + g * -0.418688 + b * -0.081312 + 128); + if (r < 0) + r = 0; + if (g < 0) + g = 0; + if (b < 0) + b = 0; - if (y < 0) y = 0; - if (u < 0) u = 0; - if (v < 0) v = 0; + if (r > 255) + r = 255; + if (g > 255) + g = 255; + if (b > 255) + b = 255; - if (y > 255) y = 255; - if (u > 255) u = 255; - if (v > 255) v = 255; - } - -}; +};