Package gov.lanl.adore.djatoka

Examples of gov.lanl.adore.djatoka.DjatokaException


        try {
            info = new JP2ImageInfo(is);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        return info.getImageRecord();
    }
View Full Code Here


                dims.add(Double.parseDouble(token));
            } else {
                int t = Integer.parseInt(token);

                if (r.getHeight() < t) {
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getHeight());
                }

                dims.add(Double.parseDouble(token) / r.getHeight());
            }

            // left
            if ((token = st.nextToken()).contains(".")) {
                dims.add(Double.parseDouble(token));
            } else {
                int t = Integer.parseInt(token);

                if (r.getWidth() < t) {
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getWidth());
                }

                dims.add(Double.parseDouble(token) / r.getWidth());
            }
View Full Code Here

     * @return a populated ImageRecord object
     * @throws DjatokaException
     */
    public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
        if (!new File(r.getImageFile()).exists()) {
            throw new DjatokaException("Image Does Not Exist");
        }
        Jp2_source inputSource = new Jp2_source();
        Kdu_compressed_source kduIn = null;
        Jp2_family_src jp2_family_in = new Jp2_family_src();
        Jp2_locator loc = new Jp2_locator();

        try {
            jp2_family_in.Open(r.getImageFile(), true);
            inputSource.Open(jp2_family_in, loc);
            inputSource.Read_header();
            kduIn = inputSource;
            Kdu_codestream codestream = new Kdu_codestream();
            codestream.Create(kduIn);
            Kdu_channel_mapping channels = new Kdu_channel_mapping();
            if (inputSource.Exists()) {
                channels.Configure(inputSource, false);
            } else {
                channels.Configure(codestream);
            }
            int ref_component = channels.Get_source_component(0);
            int minLevels = codestream.Get_min_dwt_levels();
            int minLayers = codestream.Get_max_tile_layers();
            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);

            channels.Native_destroy();
            if (codestream.Exists()) {
                codestream.Destroy();
            }
            kduIn.Native_destroy();
            inputSource.Native_destroy();
            jp2_family_in.Native_destroy();
        } catch (KduException e) {
            throw new DjatokaException(e.getMessage(), e);
        }

        return r;
    }
View Full Code Here

        if (input.getImageFile() != null) {
            return process(input, params);
        } else if (input.getObject() != null && (input.getObject() instanceof InputStream)) {
            return process((InputStream) input.getObject(), params);
        } else {
            throw new DjatokaException("File not defined and Input Object Type " +
                    input.getObject().getClass().getName() + " is not supported");
        }
    }
View Full Code Here

            }

            return image;
        } catch (KduException e) {
            e.printStackTrace();
            throw new DjatokaException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DjatokaException(e.getMessage(), e);
        }
    }
View Full Code Here

                IOUtils.copyStream(is, fos);
                is.close();
                fos.close();
            }
        } catch (IOException e) {
            throw new DjatokaException(e.getMessage(), e);
        }

        try {
            Jp2_source inputSource = new Jp2_source();
            Kdu_compressed_source input = null;
            Jp2_family_src jp2_family_in = new Jp2_family_src();
            Jp2_locator loc = new Jp2_locator();
            jp2_family_in.Open(sourceFile, true);
            inputSource.Open(jp2_family_in, loc);
            inputSource.Read_header();
            input = inputSource;

            Kdu_codestream codestream = new Kdu_codestream();
            codestream.Create(input);
            Kdu_channel_mapping channels = new Kdu_channel_mapping();

            if (inputSource.Exists()) {
                channels.Configure(inputSource, false);
            } else {
                channels.Configure(codestream);
            }
            int ref_component = channels.Get_source_component(0);
            Kdu_coords ref_expansion = getReferenceExpansion(ref_component, channels, codestream);
            Kdu_dims image_dims = new Kdu_dims();
            codestream.Get_dims(ref_component, image_dims);
            Kdu_coords imageSize = image_dims.Access_size();
            Kdu_coords imagePosition = image_dims.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() * ref_expansion.Get_x());
            imageSize.Set_y(imageSize.Get_y() * ref_expansion.Get_y());
            imagePosition.Set_x(imagePosition.Get_x() * ref_expansion.Get_x() / reduce -
                    ((ref_expansion.Get_x() / reduce - 1) / 2));
            imagePosition.Set_y(imagePosition.Get_y() * ref_expansion.Get_y() / reduce -
                    ((ref_expansion.Get_y() / reduce - 1) / 2));

            Kdu_dims view_dims = new Kdu_dims();
            view_dims.Assign(image_dims);
            view_dims.Access_size().Set_x(imageSize.Get_x());
            view_dims.Access_size().Set_y(imageSize.Get_y());

            int region_buf_size = imageSize.Get_x() * imageSize.Get_y();
            int[] region_buf = new int[region_buf_size];
            Kdu_region_decompressor decompressor = new Kdu_region_decompressor();
            decompressor.Start(codestream, channels, -1, params.getLevelReductionFactor(), 16384, image_dims,
                    ref_expansion, new Kdu_coords(1, 1), false, Kdu_global.KDU_WANT_OUTPUT_COMPONENTS);

            Kdu_dims new_region = new Kdu_dims();
            Kdu_dims incomplete_region = new Kdu_dims();
            Kdu_coords viewSize = view_dims.Access_size();
            incomplete_region.Assign(image_dims);

            int[] imgBuffer = new int[viewSize.Get_x() * viewSize.Get_y()];
            int[] kduBuffer = null;
            while (decompressor.Process(region_buf, image_dims.Access_pos(), 0, 0, region_buf_size,
                    incomplete_region, new_region)) {
                Kdu_coords newOffset = new_region.Access_pos();
                Kdu_coords newSize = new_region.Access_size();
                newOffset.Subtract(view_dims.Access_pos());

                kduBuffer = region_buf;
                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++];
                    }
                }
            }

            BufferedImage 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 (params.getRotationDegree() > 0) {
                image = ImageProcessingUtils.rotate(image, params.getRotationDegree());
            }

            decompressor.Native_destroy();
            channels.Native_destroy();
            if (codestream.Exists()) {
                codestream.Destroy();
            }
            inputSource.Native_destroy();
            input.Native_destroy();
            jp2_family_in.Native_destroy();

            return image;
        } catch (KduException e) {
            e.printStackTrace();
            throw new DjatokaException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DjatokaException(e.getMessage(), e);
        }
    }
View Full Code Here

TOP

Related Classes of gov.lanl.adore.djatoka.DjatokaException

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.