/** * Copy data from specified 2D short array. * * @param copyAlpha Also copy the alpha information. */ public void copyFrom(short[][] maps, boolean copyAlpha) { final int len = maps.length; beginUpdate(); try { // red component if (len > 0) red.copyFrom(maps[0], 8); if (len > 1) green.copyFrom(maps[1], 8); if (len > 2) blue.copyFrom(maps[2], 8); if (copyAlpha && (len > 3)) alpha.copyFrom(maps[3], 8); } finally { endUpdate(); } }
/** * Copy data from specified source colormap. * * @param copyAlpha Also copy the alpha information. */ public void copyFrom(IcyColorMap srcColorMap, boolean copyAlpha) { beginUpdate(); try { // copy colormap band red.copyFrom(srcColorMap.red); green.copyFrom(srcColorMap.green); blue.copyFrom(srcColorMap.blue); gray.copyFrom(srcColorMap.gray); if (copyAlpha) alpha.copyFrom(srcColorMap.alpha); // copy type setType(srcColorMap.type); } finally { endUpdate(); } }
/** @see IcyColorMap#setTypeFromData() */ public void setTypeFromData(boolean notifyChange) { boolean grayColor = true; boolean noColor = true; boolean hasAlpha = false; IcyColorMapType cmType; for (int i = 0; i < MAX_INDEX; i++) { final short r = red.map[i]; final short g = green.map[i]; final short b = blue.map[i]; final short a = alpha.map[i]; grayColor &= (r == g) && (r == b); noColor &= (r == 0) && (g == 0) && (b == 0); hasAlpha |= (a != MAX_LEVEL); } if (noColor && hasAlpha) cmType = IcyColorMapType.ALPHA; else if (grayColor && !noColor) { // set gray map gray.copyFrom(red.map, 0); cmType = IcyColorMapType.GRAY; } else cmType = IcyColorMapType.RGB; if (notifyChange) setType(cmType); else type = cmType; }