bytebufferraster.java

来自「world wind java sdk 源码」· Java 代码 · 共 75 行

JAVA
75
字号
/* Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.data;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.util.BufferWrapper;
import gov.nasa.worldwind.util.Logging;

/**
 * @author dcollins
 * @version $Id: ByteBufferRaster.java 8321 2009-01-05 17:06:14Z dcollins $
 */
public class ByteBufferRaster extends BufferWrapperRaster
{
    private java.nio.ByteBuffer byteBuffer;

    public ByteBufferRaster(int width, int height, Sector sector, java.nio.ByteBuffer byteBuffer, AVList params)
    {
        super(width, height, sector, BufferWrapper.wrap(byteBuffer, params));

        this.byteBuffer = byteBuffer;
    }

    public ByteBufferRaster(int width, int height, Sector sector, AVList params)
    {
        this(width, height, sector, createCompatibleBuffer(width, height, params), params);
    }

    public static java.nio.ByteBuffer createCompatibleBuffer(int width, int height, AVList params)
    {
        if (width < 1)
        {
            String message = Logging.getMessage("generic.ArgumentOutOfRange", "width < 1");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (height < 1)
        {
            String message = Logging.getMessage("generic.ArgumentOutOfRange", "height < 1");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (params == null)
        {
            String message = Logging.getMessage("nullValue.ParamsIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        Object pixelType = params.getValue(AVKey.DATA_TYPE);

        int sizeOfDataType = 0;
        if (AVKey.INT8.equals(pixelType))
            sizeOfDataType = (Byte.SIZE / 8);
        else if (AVKey.INT16.equals(pixelType))
            sizeOfDataType = (Short.SIZE / 8);
        else if (AVKey.INT32.equals(pixelType))
            sizeOfDataType = (Integer.SIZE / 8);
        else if (AVKey.FLOAT32.equals(pixelType))
            sizeOfDataType = (Float.SIZE / 8);

        int sizeInBytes = sizeOfDataType * width * height;
        return java.nio.ByteBuffer.allocate(sizeInBytes);
    }

    public java.nio.ByteBuffer getByteBuffer()
    {
        return this.byteBuffer;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?