Index: canvasactions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/canvasactions.inc,v
retrieving revision 1.1
diff -u -p -r1.1 canvasactions.inc
--- canvasactions.inc	28 May 2008 11:45:08 -0000	1.1
+++ canvasactions.inc	31 Jan 2011 12:38:50 -0000
@@ -164,7 +164,7 @@ function canvasactions_definecanvas_imag
   $RGB = $action['RGB'];
 
   // convert from hex (as it is stored in the UI)
-  if($RGB['HEX'] && $deduced = hex_to_rgb($RGB['HEX'])) {
+  if($RGB['HEX'] && $deduced = imagecache_actions_hex2rgba($RGB['HEX'])) {
     $RGB = array_merge($RGB, $deduced);
   }
 
Index: textactions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/textactions.inc,v
retrieving revision 1.2.4.1
diff -u -p -r1.2.4.1 textactions.inc
--- textactions.inc	31 Jan 2011 12:10:53 -0000	1.2.4.1
+++ textactions.inc	31 Jan 2011 12:38:50 -0000
@@ -178,7 +178,7 @@ function textactions_text2canvas_image($
   $y_ins = textactions_keyword_filter($action['ypos'], $image->info['height'], $temp['height'], $temp['by'], 'y');
 
   // convert color from hex (as it is stored in the UI)
-  if($action['RGB']['HEX'] && $deduced = hex_to_rgb($action['RGB']['HEX'])) {
+  if($action['RGB']['HEX'] && $deduced = imagecache_actions_hex2rgba($action['RGB']['HEX'])) {
     $action['RGB'] = array_merge($action['RGB'], $deduced);
   }
 
Index: transparency.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/transparency.inc,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 transparency.inc
--- transparency.inc	31 Jan 2011 12:10:53 -0000	1.3.4.1
+++ transparency.inc	31 Jan 2011 12:38:50 -0000
@@ -93,7 +93,7 @@ function imagecache_alpha_image($image, 
     imagealphablending($base_image, FALSE);
 
     // Start with a solid colour
-    $background_rgb = hex_to_rgb($data['color']) ;
+    $background_rgb = imagecache_actions_hex2rgba($data['color']) ;
 
    // Setting the background colour here solid is what flattens the image
    $background_color = @imagecolorallocatealpha($base_image, $background_rgb['red'], $background_rgb['green'], $background_rgb['blue'], 0) ;
@@ -146,7 +146,7 @@ function png_color2alpha($image, $color)
   imagesavealpha( $im1, TRUE);
   imagealphablending($im1, FALSE);
 
-  if ($color) $background = hex_to_rgb($color);
+  if ($color) $background = imagecache_actions_hex2rgba($color);
   $width = imagesx($im1);
   $height = imagesy($im1);
   for ($i = 0; $i < $height; $i++) { //this loop traverses each row in the image
Index: utility-color.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/utility-color.inc,v
retrieving revision 1.2
diff -u -p -r1.2 utility-color.inc
--- utility-color.inc	16 Dec 2010 05:17:44 -0000	1.2
+++ utility-color.inc	31 Jan 2011 12:38:50 -0000
@@ -13,7 +13,7 @@
  * function in order to ensure it's in the registry.
  */
 function imagecache_rgb_form($action) {
-  if ($action['HEX'] && $deduced = hex_to_rgb($action['HEX'])) {
+  if ($action['HEX'] && $deduced = imagecache_actions_hex2rgba($action['HEX'])) {
     $action = array_merge($action, $deduced);
     $action['HEX'] = ltrim($action['HEX'], '#');
     // With or without # is valid, but trim for consistancy
@@ -90,34 +90,3 @@ function theme_imagecacheactions_rgb($va
   }
 }
 
-
-
-/**
- * Decode an HTML hex-code into an array of R, G, and B values.
- * accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff
- */
-function hex_to_rgb($hex) {
-  $hex = trim($hex);
-  // remove '#'
-  if (substr($hex, 0, 1) == '#') {
-    $hex = substr($hex, 1);
-  }
-
-  // expand short form ('fff') color
-  if (strlen($hex) == 3) {
-    $hex = substr($hex, 0, 1) . substr($hex, 0, 1) .
-           substr($hex, 1, 1) . substr($hex, 1, 1) .
-           substr($hex, 2, 1) . substr($hex, 2, 1);
-  }
-
-  if (strlen($hex) != 6) {
-    trigger_error('Error: Invalid color "' . $hex . '"');
-  }
-
-  // convert
-  $rgb['red'] = hexdec(substr($hex, 0, 2));
-  $rgb['green'] = hexdec(substr($hex, 2, 2));
-  $rgb['blue'] = hexdec(substr($hex, 4, 2));
-
-  return $rgb;
-}
Index: utility.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/utility.inc,v
retrieving revision 1.4.4.1
diff -u -p -r1.4.4.1 utility.inc
--- utility.inc	31 Jan 2011 12:10:53 -0000	1.4.4.1
+++ utility.inc	31 Jan 2011 12:38:51 -0000
@@ -139,22 +139,56 @@ function imagecache_actions_calculate_of
 
 
 /**
- * The imageapi version doesn't key the results
+ * Convert a hex string to its RGBA (Red, Green, Blue, Alpha) integer
+ * components.
  *
- * I think it's better if we do.
+ * Stolen from imageapi D6 2011-01
  *
- * @ingroup utility
+ * @param $hex
+ *   A string specifing an RGB color in the formats:
+ *   '#ABC','ABC','#ABCD','ABCD','#AABBCC','AABBCC','#AABBCCDD','AABBCCDD'
+ * @return
+ *   An array with four elements for red, green, blue, and alpha.
  */
 function imagecache_actions_hex2rgba($hex) {
-  $unkeyed = imageapi_hex2rgba($hex);
-  $keyed = array_combine(array('red', 'green', 'blue', 'alpha'), $unkeyed);
-  // bad alpha produces solid black.
-  if ($keyed['alpha'] > 127) {
-    watchdog('imageapi_text', 'Bad alpha value in hex color %hex. Alpha channel cannot be greater than #7F (127)', array('%hex' => $hex), WATCHDOG_NOTICE);
-  }
-  return $keyed;
+  $hex = ltrim($hex, '#');
+  if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {
+    // 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
+    $r = str_repeat($hex{0}, 2);
+    $g = str_repeat($hex{1}, 2);
+    $b = str_repeat($hex{2}, 2);
+    $a = '0';
+  }
+  elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {
+    // #FFAA33 or r=FF, g=AA, b=33
+    list($r, $g, $b) = str_split($hex, 2);
+    $a = '0';
+  }
+  elseif (preg_match('/^[0-9a-f]{8}$/i', $hex)) {
+    // #FFAA33 or r=FF, g=AA, b=33
+    list($r, $g, $b, $a) = str_split($hex, 2);
+  }
+  elseif (preg_match('/^[0-9a-f]{4}$/i', $hex)) {
+    // 'FA37' is the same as 'FFAA3377' so r=FF, g=AA, b=33, a=77
+    $r = str_repeat($hex{0}, 2);
+    $g = str_repeat($hex{1}, 2);
+    $b = str_repeat($hex{2}, 2);
+    $a = str_repeat($hex{3}, 2);
+  }
+  else {
+    //error: invalide hex string, TODO: set form error..
+    return FALSE;
+  }
+
+  $r = hexdec($r);
+  $g = hexdec($g);
+  $b = hexdec($b);
+  $a = hexdec($a);
+  return array('red' => $r, 'green' => $g, 'blue' => $b, 'alpha' => $a);
 }
 
+
+
 /**
  * Accept a keyword (center, top, left, etc) and return it as an offset in pixels.
  * Called on either the x or y values.
Index: coloractions/imagecache_coloractions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/coloractions/imagecache_coloractions.module,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 imagecache_coloractions.module
--- coloractions/imagecache_coloractions.module	31 Jan 2011 12:10:53 -0000	1.2.2.1
+++ coloractions/imagecache_coloractions.module	31 Jan 2011 12:38:51 -0000
@@ -140,7 +140,7 @@ function theme_imagecache_colorshift($va
  */
 function imagecache_colorshift_image($image, $data = array()) {
   // convert color from hex (as it is stored in the UI)
-  if ($data['RGB']['HEX'] && $deduced = hex_to_rgb($data['RGB']['HEX'])) {
+  if ($data['RGB']['HEX'] && $deduced = imagecache_actions_hex2rgba($data['RGB']['HEX'])) {
     $data['RGB'] = array_merge($data['RGB'], $deduced);
   }
 
Index: coloractions/transparency.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_actions/coloractions/transparency.inc,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 transparency.inc
--- coloractions/transparency.inc	31 Jan 2011 12:10:53 -0000	1.2.2.1
+++ coloractions/transparency.inc	31 Jan 2011 12:38:51 -0000
@@ -130,7 +130,7 @@ function imagecache_alpha_image($image, 
     imagealphablending($base_image, FALSE);
 
     // Start with a solid colour
-    $background_rgb = hex_to_rgb($data['RGB']['HEX']);
+    $background_rgb = imagecache_actions_hex2rgba($data['RGB']['HEX']);
 
     // Setting the background colour here solid is what flattens the image
     $background_color = @imagecolorallocatealpha($base_image, $background_rgb['red'], $background_rgb['green'], $background_rgb['blue'], 0);
