/** * Make this color darker. Factor used is 0.7 * @return the new BaseColor */ public BaseColor darker() { return new BaseColor(Math.max((int) (getRed() * FACTOR), 0), Math.max((int) (getGreen() * FACTOR), 0), Math.max((int) (getBlue() * FACTOR), 0)); }
/** * Make this color darker. Factor used is 0.7 * @return the new BaseColor */ public BaseColor darker() { return new BaseColor(Math.max((int) (getRed() * FACTOR), 0), Math.max((int) (getGreen() * FACTOR), 0), Math.max((int) (getBlue() * FACTOR), 0)); }
/** * Converts a <CODE>BaseColor</CODE> into a HTML representation of this <CODE>BaseColor</CODE>. * * @param color the <CODE>BaseColor</CODE> that has to be converted. * @return the HTML representation of this <COLOR>BaseColor</COLOR> */ public static String encode(BaseColor color) { StringBuffer buffer = new StringBuffer("#"); if (color.getRed() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getRed(), 16)); if (color.getGreen() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getGreen(), 16)); if (color.getBlue() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getBlue(), 16)); return buffer.toString(); }
/** * Converts a <CODE>BaseColor</CODE> into a HTML representation of this <CODE>BaseColor</CODE>. * * @param color the <CODE>BaseColor</CODE> that has to be converted. * @return the HTML representation of this <COLOR>BaseColor</COLOR> */ public static String encode(BaseColor color) { StringBuffer buffer = new StringBuffer("#"); if (color.getRed() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getRed(), 16)); if (color.getGreen() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getGreen(), 16)); if (color.getBlue() < 16) { buffer.append('0'); } buffer.append(Integer.toString(color.getBlue(), 16)); return buffer.toString(); }
PdfColor(BaseColor color) { this(color.getRed(), color.getGreen(), color.getBlue()); } }
PdfColor(BaseColor color) { this(color.getRed(), color.getGreen(), color.getBlue()); } }
/** * Make this BaseColor brighter. Factor used is 0.7. * @return the new BaseColor */ public BaseColor brighter() { int r = getRed(); int g = getGreen(); int b = getBlue(); int i = (int) (1.0 / (1.0 - FACTOR)); if (r == 0 && g == 0 && b == 0) { return new BaseColor(i, i, i); } if (r > 0 && r < i) r = i; if (g > 0 && g < i) g = i; if (b > 0 && b < i) b = i; return new BaseColor(Math.min((int) (r / FACTOR), 255), Math.min((int) (g / FACTOR), 255), Math.min((int) (b / FACTOR), 255)); }
/** * Make this BaseColor brighter. Factor used is 0.7. * @return the new BaseColor */ public BaseColor brighter() { int r = getRed(); int g = getGreen(); int b = getBlue(); int i = (int) (1.0 / (1.0 - FACTOR)); if (r == 0 && g == 0 && b == 0) { return new BaseColor(i, i, i); } if (r > 0 && r < i) r = i; if (g > 0 && g < i) g = i; if (b > 0 && b < i) b = i; return new BaseColor(Math.min((int) (r / FACTOR), 255), Math.min((int) (g / FACTOR), 255), Math.min((int) (b / FACTOR), 255)); }
public LabColor rgb2lab(BaseColor baseColor) { double rLinear = baseColor.getRed() / 255f; double gLinear = baseColor.getGreen() / 255f; double bLinear = baseColor.getBlue() / 255f; // convert to a sRGB form double r = (rLinear > 0.04045) ? Math.pow((rLinear + 0.055) / (1 + 0.055), 2.2) : (rLinear/12.92); double g = (gLinear > 0.04045) ? Math.pow((gLinear + 0.055) / (1 + 0.055), 2.2) : (gLinear/12.92); double b = (bLinear > 0.04045) ? Math.pow((bLinear + 0.055) / (1 + 0.055), 2.2) : (bLinear/12.92); // converts double x = r * 0.4124 + g * 0.3576 + b * 0.1805; double y = r * 0.2126 + g * 0.7152 + b * 0.0722; double z = r * 0.0193 + g * 0.1192 + b * 0.9505; float l = Math.round((116.0 * fXyz(y/whitePoint[1]) - 16) * 1000) / 1000f; float a = Math.round((500.0*(fXyz(x/whitePoint[0]) - fXyz(y/whitePoint[1]))) * 1000) / 1000f; float bee = Math.round((200.0*(fXyz(y/whitePoint[1]) - fXyz(z/whitePoint[2]))) * 1000) / 1000f; return new LabColor(this, l, a, bee); }
public LabColor rgb2lab(BaseColor baseColor) { double rLinear = baseColor.getRed() / 255f; double gLinear = baseColor.getGreen() / 255f; double bLinear = baseColor.getBlue() / 255f; // convert to a sRGB form double r = (rLinear > 0.04045) ? Math.pow((rLinear + 0.055) / (1 + 0.055), 2.2) : (rLinear/12.92); double g = (gLinear > 0.04045) ? Math.pow((gLinear + 0.055) / (1 + 0.055), 2.2) : (gLinear/12.92); double b = (bLinear > 0.04045) ? Math.pow((bLinear + 0.055) / (1 + 0.055), 2.2) : (bLinear/12.92); // converts double x = r * 0.4124 + g * 0.3576 + b * 0.1805; double y = r * 0.2126 + g * 0.7152 + b * 0.0722; double z = r * 0.0193 + g * 0.1192 + b * 0.9505; float l = Math.round((116.0 * fXyz(y/whitePoint[1]) - 16) * 1000) / 1000f; float a = Math.round((500.0*(fXyz(x/whitePoint[0]) - fXyz(y/whitePoint[1]))) * 1000) / 1000f; float bee = Math.round((200.0*(fXyz(y/whitePoint[1]) - fXyz(z/whitePoint[2]))) * 1000) / 1000f; return new LabColor(this, l, a, bee); }
public LabColor(PdfLabColor labColorSpace, float l, float a, float b) { super(ExtendedColor.TYPE_LAB); this.labColorSpace = labColorSpace; this.l = l; this.a = a; this.b = b; BaseColor altRgbColor = labColorSpace.lab2Rgb(l, a, b); setValue(altRgbColor.getRed(), altRgbColor.getGreen(), altRgbColor.getBlue(), 255); }
public LabColor(PdfLabColor labColorSpace, float l, float a, float b) { super(ExtendedColor.TYPE_LAB); this.labColorSpace = labColorSpace; this.l = l; this.a = a; this.b = b; BaseColor altRgbColor = labColorSpace.lab2Rgb(l, a, b); setValue(altRgbColor.getRed(), altRgbColor.getGreen(), altRgbColor.getBlue(), 255); }
public SpotColor(PdfSpotColor spot, float tint) { super(TYPE_SEPARATION, (spot.getAlternativeCS().getRed() / 255f - 1f) * tint + 1, (spot.getAlternativeCS().getGreen() / 255f - 1f) * tint + 1, (spot.getAlternativeCS().getBlue() / 255f - 1f) * tint + 1); this.spot = spot; this.tint = tint; }
public SpotColor(PdfSpotColor spot, float tint) { super(TYPE_SEPARATION, (spot.getAlternativeCS().getRed() / 255f - 1f) * tint + 1, (spot.getAlternativeCS().getGreen() / 255f - 1f) * tint + 1, (spot.getAlternativeCS().getBlue() / 255f - 1f) * tint + 1); this.spot = spot; this.tint = tint; }
private void setColorAttribute(BaseColor newColor, PdfObject oldColor, PdfName attributeName){ float [] colorArr = new float[]{newColor.getRed()/255f, newColor.getGreen()/255f, newColor.getBlue()/255f}; if ((oldColor != null) && (oldColor instanceof PdfArray)){ PdfArray oldC = (PdfArray)oldColor; if (colorsEqual(oldC, colorArr)) { this.setAttribute(attributeName, new PdfArray(colorArr)); } else this.setAttribute(attributeName, new PdfArray(colorArr)); } else this.setAttribute(attributeName, new PdfArray(colorArr)); }
private void setColorAttribute(BaseColor newColor, PdfObject oldColor, PdfName attributeName){ float [] colorArr = new float[]{newColor.getRed()/255f, newColor.getGreen()/255f, newColor.getBlue()/255f}; if ((oldColor != null) && (oldColor instanceof PdfArray)){ PdfArray oldC = (PdfArray)oldColor; if (colorsEqual(oldC, colorArr)) { this.setAttribute(attributeName, new PdfArray(colorArr)); } else this.setAttribute(attributeName, new PdfArray(colorArr)); } else this.setAttribute(attributeName, new PdfArray(colorArr)); }
public static float[] getColorArray(BaseColor color) { int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { return new float[]{((GrayColor)color).getGray()}; } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor)color; return new float[]{cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()}; } case ExtendedColor.TYPE_SEPARATION: { return new float[]{((SpotColor)color).getTint()}; } case ExtendedColor.TYPE_DEVICEN: { return ((DeviceNColor)color).getTints(); } case ExtendedColor.TYPE_RGB: { return new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f}; } } throwColorSpaceError(); return null; }
public static float[] getColorArray(BaseColor color) { int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { return new float[]{((GrayColor)color).getGray()}; } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor)color; return new float[]{cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()}; } case ExtendedColor.TYPE_SEPARATION: { return new float[]{((SpotColor)color).getTint()}; } case ExtendedColor.TYPE_DEVICEN: { return ((DeviceNColor)color).getTints(); } case ExtendedColor.TYPE_RGB: { return new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f}; } } throwColorSpaceError(); return null; }
private void writeAttributes(final Image image) { if (image != null) { this.setAttribute(PdfName.O, PdfName.LAYOUT); if (image.getWidth() > 0){ this.setAttribute(PdfName.WIDTH, new PdfNumber(image.getWidth())); } if (image.getHeight() > 0){ this.setAttribute(PdfName.HEIGHT, new PdfNumber(image.getHeight())); } PdfRectangle rect = new PdfRectangle(image, image.getRotation()); this.setAttribute(PdfName.BBOX, rect); if (image.getBackgroundColor() != null){ BaseColor color = image.getBackgroundColor(); this.setAttribute(PdfName.BACKGROUNDCOLOR, new PdfArray(new float[] {color.getRed()/255f, color.getGreen()/255f, color.getBlue()/255f}) ); } } }
private void writeAttributes(final Image image) { if (image != null) { this.setAttribute(PdfName.O, PdfName.LAYOUT); if (image.getWidth() > 0){ this.setAttribute(PdfName.WIDTH, new PdfNumber(image.getWidth())); } if (image.getHeight() > 0){ this.setAttribute(PdfName.HEIGHT, new PdfNumber(image.getHeight())); } PdfRectangle rect = new PdfRectangle(image, image.getRotation()); this.setAttribute(PdfName.BBOX, rect); if (image.getBackgroundColor() != null){ BaseColor color = image.getBackgroundColor(); this.setAttribute(PdfName.BACKGROUNDCOLOR, new PdfArray(new float[] {color.getRed()/255f, color.getGreen()/255f, color.getBlue()/255f}) ); } } }