Wednesday, 28 March 2012

Javascript color conversion

Welcome to Technolog








This Javascript library, will help you to convert colors between different color systems.

It supports RGB, HSV, CMYK color encoding systems.
First you need to create color object you want to convert from.

As mentioned above there are 3 types:
var obj = new RGB(10 /* red */, 20 /* green */, 30 /* blue */);
var obj = new HSV(10 /* hue */, 20 /* saturation */, 30 /* value */);
var obj = new CMYK(10 /* cyan */, 20 /* magenta */, 30 /* yellow */, 40 

Source of the library

Welcome to Technology


/**
*
*  Javascript color conversion
*  http://www.webtoolkit.info/
*
**/
 
function HSV(h, s, v) {
 if (h <= 0) { h = 0; }
 if (s <= 0) { s = 0; }
 if (v <= 0) { v = 0; }
 
 if (h > 360) { h = 360; }
 if (s > 100) { s = 100; }
 if (v > 100) { v = 100; }
 
 this.h = h;
 this.s = s;
 this.v = v;
}
 
function RGB(r, g, b) {
 if (r <= 0) { r = 0; }
 if (g <= 0) { g = 0; }
 if (b <= 0) { b = 0; }
 
 if (r > 255) { r = 255; }
 if (g > 255) { g = 255; }
 if (b > 255) { b = 255; }
 
 this.r = r;
 this.g = g;
 this.b = b;
}
 
function CMYK(c, m, y, k) {
 if (c <= 0) { c = 0; }
 if (m <= 0) { m = 0; }
 if (y <= 0) { y = 0; }
 if (k <= 0) { k = 0; }
 
 if (c > 100) { c = 100; }
 if (m > 100) { m = 100; }
 if (y > 100) { y = 100; }
 if (k > 100) { k = 100; }
 
 this.c = c;
 this.m = m;
 this.y = y;
 this.k = k;
}
 
var ColorConverter = {
 
 _RGBtoHSV : function  (RGB) {
  var result = new HSV(0, 0, 0);
 
  r = RGB.r / 255;
  g = RGB.g / 255;
  b = RGB.b / 255;
 
  var minVal = Math.min(r, g, b);
  var maxVal = Math.max(r, g, b);
  var delta = maxVal - minVal;
 
  result.v = maxVal;
 
  if (delta == 0) {
   result.h = 0;
   result.s = 0;
  } else {
   result.s = delta / maxVal;
   var del_R = (((maxVal - r) / 6) + (delta / 2)) / delta;
   var del_G = (((maxVal - g) / 6) + (delta / 2)) / delta;
   var del_B = (((maxVal - b) / 6) + (delta / 2)) / delta;
 
   if (r == maxVal) { result.h = del_B - del_G; }
   else if (g == maxVal) { result.h = (1 / 3) + del_R - del_B; }
   else if (b == maxVal) { result.h = (2 / 3) + del_G - del_R; }
 
   if (result.h < 0) { result.h += 1; }
   if (result.h > 1) { result.h -= 1; }
  }
 
  result.h = Math.round(result.h * 360);
  result.s = Math.round(result.s * 100);
  result.v = Math.round(result.v * 100);
 
  return result;
 },
 
 _HSVtoRGB : function  (HSV) {
  var result = new RGB(0, 0, 0);
 
  var h = HSV.h / 360;
  var s = HSV.s / 100;
  var v = HSV.v / 100;
 
  if (s == 0) {
   result.r = v * 255;
   result.g = v * 255;
   result.v = v * 255;
  } else {
   var_h = h * 6;
   var_i = Math.floor(var_h);
   var_1 = v * (1 - s);
   var_2 = v * (1 - s * (var_h - var_i));
   var_3 = v * (1 - s * (1 - (var_h - var_i)));
 
   if (var_i == 0) {var_r = v; var_g = var_3; var_b = var_1}
   else if (var_i == 1) {var_r = var_2; var_g = v; var_b = var_1}
   else if (var_i == 2) {var_r = var_1; var_g = v; var_b = var_3}
   else if (var_i == 3) {var_r = var_1; var_g = var_2; var_b = v}
   else if (var_i == 4) {var_r = var_3; var_g = var_1; var_b = v}
   else {var_r = v; var_g = var_1; var_b = var_2};
 
   result.r = var_r * 255;
   result.g = var_g * 255;
   result.b = var_b * 255;
 
   result.r = Math.round(result.r);
   result.g = Math.round(result.g);
   result.b = Math.round(result.b);
  }
 
  return result;
 },
 
 _CMYKtoRGB : function (CMYK){
  var result = new RGB(0, 0, 0);
 
  c = CMYK.c / 100;
  m = CMYK.m / 100;
  y = CMYK.y / 100;
  k = CMYK.k / 100;
 
  result.r = 1 - Math.min( 1, c * ( 1 - k ) + k );
  result.g = 1 - Math.min( 1, m * ( 1 - k ) + k );
  result.b = 1 - Math.min( 1, y * ( 1 - k ) + k );
 
  result.r = Math.round( result.r * 255 );
  result.g = Math.round( result.g * 255 );
  result.b = Math.round( result.b * 255 );
 
  return result;
 },
 
 _RGBtoCMYK : function (RGB){
  var result = new CMYK(0, 0, 0, 0);
 
  r = RGB.r / 255;
  g = RGB.g / 255;
  b = RGB.b / 255;
 
  result.k = Math.min( 1 - r, 1 - g, 1 - b );
  result.c = ( 1 - r - result.k ) / ( 1 - result.k );
  result.m = ( 1 - g - result.k ) / ( 1 - result.k );
  result.y = ( 1 - b - result.k ) / ( 1 - result.k );
 
  result.c = Math.round( result.c * 100 );
  result.m = Math.round( result.m * 100 );
  result.y = Math.round( result.y * 100 );
  result.k = Math.round( result.k * 100 );
 
  return result;
 },
 
 toRGB : function (o) {
  if (o instanceof RGB) { return o; }
  if (o instanceof HSV) { return this._HSVtoRGB(o); }
  if (o instanceof CMYK) { return this._CMYKtoRGB(o); }
 },
 
 toHSV : function (o) {
  if (o instanceof HSV) { return o; }
  if (o instanceof RGB) { return this._RGBtoHSV(o); }
  if (o instanceof CMYK) { return this._RGBtoHSV(this._CMYKtoRGB(o)); }
 },
 
 toCMYK : function (o) {
  if (o instanceof CMYK) { return o; }
  if (o instanceof RGB) { return this._RGBtoCMYK(o); }
  if (o instanceof HSV) { return this._RGBtoCMYK(this._HSVtoRGB(o)); }
 }
 
}

Usage:javascript color

Welcome to Technology


Then you just need to pass that object to appropriate “ColorConverter” method.

To convert from HSV to RGB use library like this:
var result = ColorConverter.toRGB(new HSV(10, 20, 30));
alert("RGB:" + result.r + ":" + result.g + ":" + result.b);
Result:
hsv2rgb
To convert from RGB to HSV use library like this:
var result = ColorConverter.toHSV(new RGB(10, 20, 30));
alert("HSV:" + result.h + ":" + result.s + ":" + result.v);
Result:
rgb2hsv

Unable to execute Bluetooth HDP Demo

Welcome to Technology

 Messages 1 - 25 of 30 - Collapse all  -     Newer >
jfernandez  
View profile  
 More options Dec 15 2011, 12:30 pm
Hi all,
I'm executing the Bluetooth HDP Demo [1]  (offered from Android 4.0
Ice Cream Sandwich) in my Android smartphone. When I have registered
the application in order to receive data, and I have paired the
biomedical device with the smartphone, I try to open the channel
connection and I can see that the device starts sending data to the
smartphone. However, the smartphone is unable to open the channel
connection HDP.
At the end of this message you can see the output obtained in the
LogCat.
Has anybody achieved to run successfully this sample about the use of
the Bluetooth Health Profile API? Any ideas?
Thanks. Regards.
[1] http://developer.android.com/resources/samples/BluetoothHDP/index.html
This is the log that I obtain:
12-15 16:40:54.048: I/BluetoothHDPService(1105): connectChannel()
12-15 16:40:54.068: D/BluetoothService(147): CONNECTION_STATE_CHANGE:
00:80:25:14:A1:BC: 0 -> 1
12-15 16:40:55.169: D/ConnectivityService(147):
handleInetConditionHoldEnd: net=1, condition=0, published condition=0
12-15 16:40:59.393: D/BluetoothEventLoop(147): Device property
changed: 00:80:25:14:A1:BC property: Connected value: true
12-15 16:41:00.024: D/BluetoothEventLoop(147): Health Device :
devicePath: /org/bluez/278/hci0/dev_00_80_25_14_A1_BC:channelPath:/org/
bluez/278/hci0/dev_00_80_25_14_A1_BC/chan3115:existstrue
12-15 16:41:00.034: E/BluetoothService.cpp(147):
getChannelApplicationNative
12-15 16:41:00.044: E/bluetooth_common.cpp(147):
dbus_func_args_timeout_valist: D-Bus error in Acquire:
org.bluez.Error.HealthError (Cannot reconnect: MDL is not closed)
12-15 16:41:00.044: E/BluetoothHealthProfileHandler(147): Error
obtaining fd for channel:/org/bluez/278/hci0/dev_00_80_25_14_A1_BC/
chan3115
12-15 16:41:00.074: E/BluetoothService.cpp(147): destroyChannelNative
12-15 16:41:00.074: E/BluetoothEventLoop.cpp(147):
onHealthDeviceConnectionResult: D-Bus error:
org.bluez.Error.HealthError (Mdl is not created)
12-15 16:41:00.074: D/BluetoothEventLoop(147):
onHealthDeviceConnectionResult 2 6001
12-15 16:41:00.214: D/BluetoothEventLoop(147):
onHealthDeviceConnectionResult 2 6000
12-15 16:41:00.214: D/BluetoothEventLoop(147): Health Device : Name of
Property is: MainChannel Value:/org/bluez/278/hci0/
dev_00_80_25_14_A1_BC/chan3115 

Google friendly domain redirect Google friendly domain redirect

Welcome to Technology




You must use Google friendly domain redirect in these cases:
You changed a domain name for your web page and want the old one to redirect visitors to a new one.
You have many domains for your website (one primary and many alternative).
You want to strip the ‘www’ part from the domain name.

How to redirect?
For case #1 and #2 you must point (alias) all the domains to the same website. Ask your server administrator or hosting providers how to do that. Some times hosting providers call this – domain parking.
Select configuration for desired case below. Replace domain names with your real ones and paste the code to file named ‘.htaccess’. Upload the file it into the root folder of your web page.
Configuration for case #1</div>


RewriteEngine On
RewriteBase /
 
# redirects old domain to a new one
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^.*$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]

Configuration for case #2

RewriteEngine On
RewriteBase /
 
# redirects any alternative domain which name isn't "www.primarydomain.com"
RewriteCond %{HTTP_HOST} !^www\.primarydomain\.com$
RewriteRule ^.*$ http://www.primarydomain.com%{REQUEST_URI} [R=301,L]


gap between list item

Welcome to Technology


Gap between list items

Gap between list items – its the most annoying bug for internet explorer.
You can remove it if you clean all spaces between li and ul elements, o you can just comment those spaces like in example below.

DEMO

Example how to remove gaps

<ul id="navigation"><!--
	--><li><a href="">Sign up</a></li><!--
	--><li><a href="">Orders</a><!--
		--><ul><!--
			--><li><a href="">Dashboard</a></li><!--
			--><li><a href="">Order list</a></li><!--
		--></ul><!--
	--></li><!--
	--><li><a href=""><span><span>My account</span></span></a><!--
		--><ul><!--
			--><li><a href="">Dashboard</a></li><!--
			--><li><a href="">Profile</a></li><!--
			--><li><a href="">Change password</a></li><!--
		--></ul><!--
	--></li><!--
--></ul>