com.lowagie.text.ImgRaw Java Examples

The following examples show how to use com.lowagie.text.ImgRaw. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException {
	Image img = new ImgRaw(width, height, 1, bpc, bdata);
	PdfArray colorspace = new PdfArray();
	colorspace.add(PdfName.INDEXED);
	colorspace.add(PdfName.DEVICERGB);
	byte np[] = getPalette(paletteEntries);
	int len = np.length;
	colorspace.add(new PdfNumber(len / 3 - 1));
	colorspace.add(new PdfString(np));
	PdfDictionary ad = new PdfDictionary();
	ad.put(PdfName.COLORSPACE, colorspace);
	img.setAdditional(ad);
	return img;
}
 
Example #2
Source File: BmpImage.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException {
    Image img = new ImgRaw(width, height, 1, bpc, bdata);
    PdfArray colorspace = new PdfArray();
    colorspace.add(PdfName.INDEXED);
    colorspace.add(PdfName.DEVICERGB);
    byte np[] = getPalette(paletteEntries);
    int len = np.length;
    colorspace.add(new PdfNumber(len / 3 - 1));
    colorspace.add(new PdfString(np));
    PdfDictionary ad = new PdfDictionary();
    ad.put(PdfName.COLORSPACE, colorspace);
    img.setAdditional(ad);
    return img;
}
 
Example #3
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private Image read1632Bit(boolean is32) throws IOException, BadElementException {

		int red_mask = findMask(redMask);
		int red_shift = findShift(redMask);
		int red_factor = red_mask + 1;
		int green_mask = findMask(greenMask);
		int green_shift = findShift(greenMask);
		int green_factor = green_mask + 1;
		int blue_mask = findMask(blueMask);
		int blue_shift = findShift(blueMask);
		int blue_factor = blue_mask + 1;
		byte bdata[] = new byte[width * height * 3];
		// Padding bytes at the end of each scanline
		int padding = 0;

		if (!is32) {
			// width * bitsPerPixel should be divisible by 32
			int bitsPerScanline = width * 16;
			if (bitsPerScanline % 32 != 0) {
				padding = (bitsPerScanline / 32 + 1) * 32 - bitsPerScanline;
				padding = (int) Math.ceil(padding / 8.0);
			}
		}

		int imSize = (int) imageSize;
		if (imSize == 0) {
			imSize = (int) (bitmapFileSize - bitmapOffset);
		}

		int l = 0;
		int v;
		if (isBottomUp) {
			for (int i = height - 1; i >= 0; --i) {
				l = width * 3 * i;
				for (int j = 0; j < width; j++) {
					if (is32) {
						v = (int) readDWord(inputStream);
					} else {
						v = readWord(inputStream);
					}
					bdata[l++] = (byte) ((v >>> red_shift & red_mask) * 256 / red_factor);
					bdata[l++] = (byte) ((v >>> green_shift & green_mask) * 256 / green_factor);
					bdata[l++] = (byte) ((v >>> blue_shift & blue_mask) * 256 / blue_factor);
				}
				for (int m = 0; m < padding; m++) {
					inputStream.read();
				}
			}
		} else {
			for (int i = 0; i < height; i++) {
				for (int j = 0; j < width; j++) {
					if (is32) {
						v = (int) readDWord(inputStream);
					} else {
						v = readWord(inputStream);
					}
					bdata[l++] = (byte) ((v >>> red_shift & red_mask) * 256 / red_factor);
					bdata[l++] = (byte) ((v >>> green_shift & green_mask) * 256 / green_factor);
					bdata[l++] = (byte) ((v >>> blue_shift & blue_mask) * 256 / blue_factor);
				}
				for (int m = 0; m < padding; m++) {
					inputStream.read();
				}
			}
		}
		return new ImgRaw(width, height, 3, 8, bdata);
	}
 
Example #4
Source File: BmpImage.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Image read1632Bit(boolean is32) throws IOException, BadElementException {
    
    int red_mask = findMask(redMask);
    int red_shift = findShift(redMask);
    int red_factor = red_mask + 1;
    int green_mask = findMask(greenMask);
    int green_shift = findShift(greenMask);
    int green_factor = green_mask + 1;
    int blue_mask = findMask(blueMask);
    int blue_shift = findShift(blueMask);
    int blue_factor = blue_mask + 1;
    byte bdata[] = new byte[width * height * 3];
    // Padding bytes at the end of each scanline
    int padding = 0;
    
    if (!is32) {
    // width * bitsPerPixel should be divisible by 32
        int bitsPerScanline = width * 16;
        if ( bitsPerScanline%32 != 0) {
            padding = (bitsPerScanline/32 + 1)*32 - bitsPerScanline;
            padding = (int)Math.ceil(padding/8.0);
        }
    }
    
    int imSize = (int)imageSize;
    if (imSize == 0) {
        imSize = (int)(bitmapFileSize - bitmapOffset);
    }
    
    int l=0;
    int v;
    if (isBottomUp) {
        for (int i=height - 1; i >= 0; --i) {
            l = width * 3 * i;
            for (int j=0; j<width; j++) {
                if (is32)
                    v = (int)readDWord(inputStream);
                else
                    v = readWord(inputStream);
                bdata[l++] = (byte)(((v >>> red_shift) & red_mask) * 256 / red_factor);
                bdata[l++] = (byte)(((v >>> green_shift) & green_mask) * 256 / green_factor);
                bdata[l++] = (byte)(((v >>> blue_shift) & blue_mask) * 256 / blue_factor);
            }
            for (int m=0; m<padding; m++) {
                inputStream.read();
            }
        }
    } else {
        for (int i=0; i<height; i++) {
            for (int j=0; j<width; j++) {
                if (is32)
                    v = (int)readDWord(inputStream);
                else
                    v = readWord(inputStream);
                bdata[l++] = (byte)(((v >>> red_shift) & red_mask) * 256 / red_factor);
                bdata[l++] = (byte)(((v >>> green_shift) & green_mask) * 256 / green_factor);
                bdata[l++] = (byte)(((v >>> blue_shift) & blue_mask) * 256 / blue_factor);
            }
            for (int m=0; m<padding; m++) {
                inputStream.read();
            }
        }
    }
    return new ImgRaw(width, height, 3, 8, bdata);
}