Example #1
0
        /// <summary>
        /// Get a thumbnail of the document, if possible
        /// </summary>
        /// <param name="sizeX">The maximum X size of the thumbnail</param>
        /// <param name="sizeY">The maximum y size of the thumbnail</param>
        /// <param name="forceFullSize">True if the thumbnail should be exatly XxY pixels and False if the thumbnail
        /// should fit inside a XxY box but should maintain its aspect ratio</param>
        /// <returns>A JPEG byte thumbnail or null if the thumbnail canĀ“t be generated</returns>
        public override byte[] GetThumbnail(int sizeX, int sizeY, bool forceFullSize)
        {
            // If we have no bytes then we can't do anything.
            if (Bytes == null || Bytes.Length == 0)
            {
                return(null);
            }

            try
            {
                org.pdfbox.pdfviewer.PageDrawer pagedrawer = new
                                                             org.pdfbox.pdfviewer.PageDrawer();

                java.io.ByteArrayInputStream byteStream = new java.io.ByteArrayInputStream(Bytes);
                PDDocument     doc   = PDDocument.load(byteStream);
                int            count = doc.getNumberOfPages();
                java.util.List pages = doc.getDocumentCatalog().getAllPages();
                if (pages.size() > 0)
                {
                    PDPage page = pagedrawer.getPage();
                    java.awt.image.BufferedImage  image = page.convertToImage();
                    java.io.ByteArrayOutputStream os    = new java.io.ByteArrayOutputStream();
                    ImageIO.write(image, "jpg", os);
                    byte[] data = os.toByteArray();
                    return(data);
                }
            }
            catch (Exception e)
            {
                log.Error("Failed to get the thumbnail from the PDF file " + Name, e);
            }

            return(null);
        }
        public void compressImage(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes,
                                  java.nio.ByteBuffer buffer)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.BufferNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // If it is determined that the image and block have no alpha component, then we compress with DXT1 using a
            // four color palette. Otherwise, we use the three color palette (with the fourth color as transparent black).

            ColorBlock4x4       colorBlock          = new ColorBlock4x4();
            ColorBlockExtractor colorBlockExtractor = this.getColorBlockExtractor(image);

            BlockDXT1           dxt1Block      = new BlockDXT1();
            BlockDXT1Compressor dxt1Compressor = new BlockDXT1Compressor();

            int width  = image.getWidth();
            int height = image.getHeight();

            bool imageHasAlpha  = image.getColorModel().hasAlpha();
            bool enableAlpha    = attributes.isEnableDXT1Alpha();
            int  alphaThreshold = attributes.getDXT1AlphaThreshold();

            for (int j = 0; j < height; j += 4)
            {
                for (int i = 0; i < width; i += 4)
                {
                    colorBlockExtractor.extractColorBlock4x4(attributes, i, j, colorBlock);

                    if (enableAlpha && imageHasAlpha && blockHasDXT1Alpha(colorBlock, alphaThreshold))
                    {
                        dxt1Compressor.compressBlockDXT1a(colorBlock, attributes, dxt1Block);
                    }
                    else
                    {
                        dxt1Compressor.compressBlockDXT1(colorBlock, attributes, dxt1Block);
                    }

                    buffer.putShort((short)dxt1Block.color0);
                    buffer.putShort((short)dxt1Block.color1);
                    buffer.putInt((int)dxt1Block.colorIndexMask);
                }
            }
        }
        /**
         * Creates a <code>BasicColorBlockExtrator</code> which will draw its data from the <code>BufferedImage</code>.
         * The <code>BufferedImage</code> may be of any type, so long as a call to <code>image.getRGB()</code> will
         * succeed.
         *
         * @param image the image to draw data from.
         *
         * @throws ArgumentException if <code>image</code> is null.
         */
        public BasicColorBlockExtractor(java.awt.image.BufferedImage image)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            this.width  = image.getWidth();
            this.height = image.getHeight();
            this.image  = image;
            this.buffer = new int[16];
        }
Example #4
0
        /**
         * Creates a mipmapped version of a BufferedImageRaster from a single BufferedImage instance.
         *
         * @param sector A sector
         * @param image  BufferedImage
         */
        public MipMappedBufferedImageRaster(Sector sector, java.awt.image.BufferedImage image)
        {
            base(sector, image);

            int maxLevel = ImageUtil.getMaxMipmapLevel(image.getWidth(), image.getHeight());

            java.awt.image.BufferedImage[] levelImages = ImageUtil.buildMipmaps(image,
                                                                                java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE, maxLevel);

            this.levelRasters = new BufferedImageRaster[1 + maxLevel];
            for (int i = 0; i <= maxLevel; i++)
            {
                this.levelRasters[i] = new BufferedImageRaster(sector, levelImages[i]);
            }
        }
Example #5
0
        public void compressImage(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes,
                                  java.nio.ByteBuffer buffer)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.BufferNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            ColorBlock4x4       colorBlock          = new ColorBlock4x4();
            ColorBlockExtractor colorBlockExtractor = this.getColorBlockExtractor(image);

            BlockDXT3           dxt3Block      = new BlockDXT3();
            BlockDXT3Compressor dxt3Compressor = new BlockDXT3Compressor();

            int width  = image.getWidth();
            int height = image.getHeight();

            for (int j = 0; j < height; j += 4)
            {
                for (int i = 0; i < width; i += 4)
                {
                    colorBlockExtractor.extractColorBlock4x4(attributes, i, j, colorBlock);
                    dxt3Compressor.compressBlockDXT3(colorBlock, attributes, dxt3Block);

                    AlphaBlockDXT3 dxtAlphaBlock = dxt3Block.getAlphaBlock();
                    buffer.putLong(dxtAlphaBlock.alphaValueMask);

                    BlockDXT1 dxtColorBlock = dxt3Block.getColorBlock();
                    buffer.putShort((short)dxtColorBlock.color0);
                    buffer.putShort((short)dxtColorBlock.color1);
                    buffer.putInt((int)dxtColorBlock.colorIndexMask);
                }
            }
        }
        public int getCompressedSize(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // TODO: comment, provide documentation reference

            int width  = Math.Max(image.getWidth(), 4);
            int height = Math.Max(image.getHeight(), 4);

            return((width * height) / 2);
        }
 protected ColorBlockExtractor getColorBlockExtractor(java.awt.image.BufferedImage image)
 {
     return(new BasicColorBlockExtractor(image));
 }