eszdman / PhotonCamera

Android Camera that uses Enhanced image processing
GNU General Public License v3.0
757 stars 72 forks source link

Input Bytebuffer of HDRX library. #27

Closed make-j64 closed 3 years ago

make-j64 commented 4 years ago

Hi @eszdman,

Im trying to use a bytebuffer which read from a *.dng for input of HDRX instead of bytebuffer from Image but result is always black.

I would like to ask what is correctly type of bytebuffer for HDRX lib?

Thanks.

eszdman commented 4 years ago

You need a direct bytebuffer Otherwise it won't work.

make-j64 commented 4 years ago

Thanks for quick reply. As you comment, i use allocateDirect to create direct bytebuffer as below, but it still not work.

public static ByteBuffer readBytesFromFile(String filePath) {

    FileInputStream fileInputStream = null;
    byte[] bytesArray = null;

    try {

        File file = new File(filePath);
        bytesArray = new byte[(int) file.length()];
        fileInputStream = new FileInputStream(file);
        fileInputStream.read(bytesArray);

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    ByteBuffer byteBufferOut = ByteBuffer.allocateDirect(bytesArray.length);
    byteBufferOut.position(0);
    byteBufferOut.put(bytesArray);
    byteBufferOut.position(0);
    return byteBufferOut;

}
eszdman commented 4 years ago

You may have entered the wrong number of frames or entered less buffers, also input only bayer16 without packing, not usual .dng files

KillerInk commented 4 years ago

using a dng direct wont work. you are reading the full dng including the metadata, but you only need the data.

make-j64 commented 4 years ago

@KillerInk @eszdman I was made a quick test, write direct bytebuffer from Image and read it back.

public static File writeDirect(Context context, Image image) { ByteBuffer buffer; try { buffer = image.getPlanes()[0].getBuffer(); } catch (IllegalStateException e) { return null; } if (buffer != null) { File tmpDataFile; try { tmpDataFile = File.createTempFile( "RAW", / prefix / ".raw", / suffix / context.getExternalFilesDir("RAW") / directory / ); FileChannel wChannel = new FileOutputStream(tmpDataFile, false).getChannel(); wChannel.write(buffer); wChannel.close(); } catch (IOException e) { e.printStackTrace(); return null; } finally { image.close(); buffer.clear(); } return tmpDataFile; } return null; }

But it still not work.

KillerInk commented 4 years ago

for me this code looks correct. but didnt test it. sure the image format is RAW_SENSOR?

make-j64 commented 4 years ago

sure the image format is RAW_SENSOR?

Yes, in my test, write ByteBuffer from: https://github.com/eszdman/PhotonCamera/blob/ce8311a516fe4b3b9bafefb66f9e2bde5a195cb5/app/src/main/java/com/eszdman/photoncamera/processing/ImageProcessing.java#L218

and read it back after.

eszdman commented 3 years ago

Should be fixed in current dev branch