Package kdu_jni

Examples of kdu_jni.Jpx_source


            IOUtils.copyStream(is, fos);
        }

        Kdu_simple_file_source raw_src = null; // Must be disposed last
        Jp2_family_src family_src = new Jp2_family_src(); // Dispose last
        Jpx_source wrapped_src = new Jpx_source(); // Dispose in the middle
        Kdu_region_compositor compositor = null; // Must be disposed first
        BufferedImage image = null;

        try {
            family_src.Open(sourceFile);
            int success = wrapped_src.Open(family_src, true);
            if (success < 0) {
                family_src.Close();
                wrapped_src.Close();
                raw_src = new Kdu_simple_file_source(sourceFile);
            }

            compositor = new Kdu_region_compositor();
      if (raw_src != null)
                compositor.Create(raw_src);
      else
                compositor.Create(wrapped_src);

            Kdu_dims imageDimensions = new Kdu_dims();
            compositor.Get_total_composition_dims(imageDimensions);
            Kdu_coords imageSize = imageDimensions.Access_size();
            Kdu_coords imagePosition = imageDimensions.Access_pos();

      if (useleftDouble)
                left = imagePosition.Get_x() + (int) Math.round(leftDouble * imageSize.Get_x());
      if (usetopDouble)
                top = imagePosition.Get_y() + (int) Math.round(topDouble * imageSize.Get_y());
      if (useheightDouble)
                height = (int) Math.round(heightDouble * imageSize.Get_y());
      if (usewidthDouble)
                width = (int) Math.round(widthDouble * imageSize.Get_x());

            if (useRegion) {
                imageSize.Set_x(width);
                imageSize.Set_y(height);
                imagePosition.Set_x(left);
                imagePosition.Set_y(top);
            }

            int reduce = 1 << params.getLevelReductionFactor();
            imageSize.Set_x(imageSize.Get_x());
            imageSize.Set_y(imageSize.Get_y());
            imagePosition.Set_x(imagePosition.Get_x() / reduce - (1 / reduce - 1) / 2);
            imagePosition.Set_y(imagePosition.Get_y() / reduce - (1 / reduce - 1) / 2);

            Kdu_dims viewDims = new Kdu_dims();
            viewDims.Assign(imageDimensions);
            viewDims.Access_size().Set_x(imageSize.Get_x());
            viewDims.Access_size().Set_y(imageSize.Get_y());
            compositor.Add_compositing_layer(0, viewDims, viewDims);

      if (params.getRotationDegree() == 90)
                compositor.Set_scale(true, false, true, 1.0F);
      else if (params.getRotationDegree() == 180)
                compositor.Set_scale(false, true, true, 1.0F);
      else if (params.getRotationDegree() == 270)
                compositor.Set_scale(true, true, false, 1.0F);
      else
                compositor.Set_scale(false, false, false, 1.0F);

            compositor.Get_total_composition_dims(viewDims);
            Kdu_coords viewSize = viewDims.Access_size();
            compositor.Set_buffer_surface(viewDims);

            int[] imgBuffer = new int[viewSize.Get_x() * viewSize.Get_y()];
            Kdu_compositor_buf compositorBuffer = compositor.Get_composition_buffer(viewDims);
            int regionBufferSize = 0;
            int[] kduBuffer = null;
            Kdu_dims newRegion = new Kdu_dims();
            while (compositor.Process(100000, newRegion)) {
                Kdu_coords newOffset = newRegion.Access_pos();
                Kdu_coords newSize = newRegion.Access_size();
                newOffset.Subtract(viewDims.Access_pos());

                int newPixels = newSize.Get_x() * newSize.Get_y();
        if (newPixels == 0)
                    continue;
                if (newPixels > regionBufferSize) {
                    regionBufferSize = newPixels;
                    kduBuffer = new int[regionBufferSize];
                }

                compositorBuffer.Get_region(newRegion, kduBuffer);
                int imgBuffereIdx = newOffset.Get_x() + newOffset.Get_y() * viewSize.Get_x();
                int kduBufferIdx = 0;
                int xDiff = viewSize.Get_x() - newSize.Get_x();
                for (int j = 0; j < newSize.Get_y(); j++, imgBuffereIdx += xDiff) {
                    for (int i = 0; i < newSize.Get_x(); i++) {
                        imgBuffer[imgBuffereIdx++] = kduBuffer[kduBufferIdx++];
                    }
                }
            }
      if (params.getRotationDegree() == 90 || params.getRotationDegree() == 270)
                image = new BufferedImage(imageSize.Get_y(), imageSize.Get_x(), BufferedImage.TYPE_INT_RGB);
      else
                image = new BufferedImage(imageSize.Get_x(), imageSize.Get_y(), BufferedImage.TYPE_INT_RGB);
            image.setRGB(0, 0, viewSize.Get_x(), viewSize.Get_y(), imgBuffer, 0, viewSize.Get_x());

      if (compositor != null)
                compositor.Native_destroy();
            wrapped_src.Native_destroy();
            family_src.Native_destroy();
      if (raw_src != null)
                raw_src.Native_destroy();

            return image;
View Full Code Here


            } catch (Exception e) {
                throw new DjatokaException("Invalid file.");
            }
        }

        Jpx_source inputSource = new Jpx_source();
        Jp2_family_src jp2_family_in = new Jp2_family_src();

        int ref_component = 0;
        try {
            jp2_family_in.Open(r.getImageFile(), true);
            inputSource.Open(jp2_family_in, true);
            Kdu_codestream codestream = new Kdu_codestream();
            codestream.Create(inputSource.Access_codestream(ref_component).Open_stream());

            int minLevels = codestream.Get_min_dwt_levels();
            int depth = codestream.Get_bit_depth(ref_component);
            int colors = codestream.Get_num_components();
            int[] frames = new int[1];
            inputSource.Count_compositing_layers(frames);
            Kdu_dims image_dims = new Kdu_dims();
            codestream.Get_dims(ref_component, image_dims);
            Kdu_coords imageSize = image_dims.Access_size();

            r.setWidth(imageSize.Get_x());
            r.setHeight(imageSize.Get_y());
            r.setDWTLevels(minLevels);
            int djatokaLevels = ImageProcessingUtils.getLevelCount(r.getWidth(), r.getHeight());
            r.setLevels((djatokaLevels > minLevels) ? minLevels : djatokaLevels);
            r.setBitDepth(depth);
            r.setNumChannels(colors);
            r.setCompositingLayerCount(frames[0]);

            int[] v = new int[1];
            Kdu_params p = codestream.Access_siz().Access_cluster("COD");
            if (p != null) {
                p.Get(Kdu_global.Clayers, 0, 0, v, true, true, true);
          if (v[0] > 0)
                    r.setQualityLayers(v[0]);
            }

      if (codestream.Exists())
                codestream.Destroy();
            inputSource.Native_destroy();
            jp2_family_in.Native_destroy();
        } catch (KduException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Checking: java.library.path = {}", System.getProperty("java.library.path"));
        }

        Jpx_source inputSource = new Jpx_source();
        Jp2_family_src jp2_family_in = new Jp2_family_src();

        int ref_component = 0;

        try {
            jp2_family_in.Open(r.getImageFile(), true);
            inputSource.Open(jp2_family_in, true);
            Kdu_codestream codestream = new Kdu_codestream();
            codestream.Create(inputSource.Access_codestream(ref_component).Open_stream());

            int minLevels = codestream.Get_min_dwt_levels();
            int depth = codestream.Get_bit_depth(ref_component);
            int colors = codestream.Get_num_components();
            int[] frames = new int[1];
            inputSource.Count_compositing_layers(frames);
            Kdu_dims image_dims = new Kdu_dims();
            codestream.Get_dims(ref_component, image_dims);
            Kdu_coords imageSize = image_dims.Access_size();

            r.setWidth(imageSize.Get_x());
            r.setHeight(imageSize.Get_y());
            r.setDWTLevels(minLevels);

            int djatokaLevels = ImageProcessingUtils.getLevelCount(r.getWidth(), r.getHeight());

            r.setLevels((djatokaLevels > minLevels) ? minLevels : djatokaLevels);
            r.setBitDepth(depth);
            r.setNumChannels(colors);
            r.setCompositingLayerCount(frames[0]);

            int[] v = new int[1];
            Kdu_params p = codestream.Access_siz().Access_cluster("COD");

            if (p != null) {
                p.Get(Kdu_global.Clayers, 0, 0, v, true, true, true);

                if (v[0] > 0) {
                    r.setQualityLayers(v[0]);
                }
            }

            if (codestream.Exists()) {
                codestream.Destroy();
            }

            inputSource.Native_destroy();
            jp2_family_in.Native_destroy();
        } catch (KduException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }
View Full Code Here

            IOUtils.copyStream(is, fos);
        }

        Kdu_simple_file_source raw_src = null; // Must be disposed last
        Jp2_family_src family_src = new Jp2_family_src(); // Dispose last
        Jpx_source wrapped_src = new Jpx_source(); // Dispose in the middle
        Kdu_region_compositor compositor = null; // Must be disposed first
        BufferedImage image = null;

        try {
            family_src.Open(sourceFile);
            int success = wrapped_src.Open(family_src, true);
            if (success < 0) {
                family_src.Close();
                wrapped_src.Close();
                raw_src = new Kdu_simple_file_source(sourceFile);
            }

            compositor = new Kdu_region_compositor();
            if (raw_src != null) {
                compositor.Create(raw_src);
            } else {
                compositor.Create(wrapped_src);
            }

            Kdu_dims imageDimensions = new Kdu_dims();
            compositor.Get_total_composition_dims(imageDimensions);
            Kdu_coords imageSize = imageDimensions.Access_size();
            Kdu_coords imagePosition = imageDimensions.Access_pos();

            if (useleftDouble) {
                left = imagePosition.Get_x() + (int) Math.round(leftDouble * imageSize.Get_x());
            }
            if (usetopDouble) {
                top = imagePosition.Get_y() + (int) Math.round(topDouble * imageSize.Get_y());
            }
            if (useheightDouble) {
                height = (int) Math.round(heightDouble * imageSize.Get_y());
            }
            if (usewidthDouble) {
                width = (int) Math.round(widthDouble * imageSize.Get_x());
            }

            if (useRegion) {
                imageSize.Set_x(width);
                imageSize.Set_y(height);
                imagePosition.Set_x(left);
                imagePosition.Set_y(top);
            }

            int reduce = 1 << params.getLevelReductionFactor();
            imageSize.Set_x(imageSize.Get_x());
            imageSize.Set_y(imageSize.Get_y());
            imagePosition.Set_x(imagePosition.Get_x() / reduce - (1 / reduce - 1) / 2);
            imagePosition.Set_y(imagePosition.Get_y() / reduce - (1 / reduce - 1) / 2);

            Kdu_dims viewDims = new Kdu_dims();
            viewDims.Assign(imageDimensions);
            viewDims.Access_size().Set_x(imageSize.Get_x());
            viewDims.Access_size().Set_y(imageSize.Get_y());
            compositor.Add_compositing_layer(0, viewDims, viewDims);

            if (params.getRotationDegree() == 90) {
                compositor.Set_scale(true, false, true, 1.0F);
            } else if (params.getRotationDegree() == 180) {
                compositor.Set_scale(false, true, true, 1.0F);
            } else if (params.getRotationDegree() == 270) {
                compositor.Set_scale(true, true, false, 1.0F);
            } else {
                compositor.Set_scale(false, false, false, 1.0F);
            }

            compositor.Get_total_composition_dims(viewDims);
            Kdu_coords viewSize = viewDims.Access_size();
            compositor.Set_buffer_surface(viewDims);

            int[] imgBuffer = new int[viewSize.Get_x() * viewSize.Get_y()];
            Kdu_compositor_buf compositorBuffer = compositor.Get_composition_buffer(viewDims);
            int regionBufferSize = 0;
            int[] kduBuffer = null;
            Kdu_dims newRegion = new Kdu_dims();
            while (compositor.Process(100000, newRegion)) {
                Kdu_coords newOffset = newRegion.Access_pos();
                Kdu_coords newSize = newRegion.Access_size();
                newOffset.Subtract(viewDims.Access_pos());

                int newPixels = newSize.Get_x() * newSize.Get_y();
                if (newPixels == 0) {
                    continue;
                }
                if (newPixels > regionBufferSize) {
                    regionBufferSize = newPixels;
                    kduBuffer = new int[regionBufferSize];
                }

                compositorBuffer.Get_region(newRegion, kduBuffer);
                int imgBuffereIdx = newOffset.Get_x() + newOffset.Get_y() * viewSize.Get_x();
                int kduBufferIdx = 0;
                int xDiff = viewSize.Get_x() - newSize.Get_x();
                for (int j = 0; j < newSize.Get_y(); j++, imgBuffereIdx += xDiff) {
                    for (int i = 0; i < newSize.Get_x(); i++) {
                        imgBuffer[imgBuffereIdx++] = kduBuffer[kduBufferIdx++];
                    }
                }
            }
            if (params.getRotationDegree() == 90 || params.getRotationDegree() == 270) {
                image = new BufferedImage(imageSize.Get_y(), imageSize.Get_x(), BufferedImage.TYPE_INT_RGB);
            } else {
                image = new BufferedImage(imageSize.Get_x(), imageSize.Get_y(), BufferedImage.TYPE_INT_RGB);
            }
            image.setRGB(0, 0, viewSize.Get_x(), viewSize.Get_y(), imgBuffer, 0, viewSize.Get_x());

            if (compositor != null) {
                compositor.Native_destroy();
            }
            wrapped_src.Native_destroy();
            family_src.Native_destroy();
            if (raw_src != null) {
                raw_src.Native_destroy();
            }

View Full Code Here

TOP

Related Classes of kdu_jni.Jpx_source

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.