java - How to Create JavaFX 16 bit Greyscale Images -


i have application generates 16 bit grey scale images. these images generated awt bufferedimage data type databuffer.type_ushort.

in app, extract 16 bit data bufferedimage, normalise 8 bit, render fx canvas canvas.getgraphicscontext2d().getpixelwriter().setpixels(...)

it works looks messy wondering if possible implement javafx image or writableimage, lets call ushortimage backed 16 bit data. ushortimage have fx properties normalisation levels, otherwise used javafx image.

any or pointers on how achieve run time efficiency appreciated!

i don't know if looking perhaps don't understand question. can convert color image gray image desaturating color using coloradjust effect.

coloradjust monochrome = new coloradjust(); monochrome.setsaturation(-1); imageview gray = new imageview(new image(image_loc)); gray.seteffect(monochrome); 

i not sure why poor grandma , grandpa must faded black , white, must so.

coloradjust

import javafx.application.application; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.effect.coloradjust; import javafx.scene.image.*; import javafx.scene.layout.hbox; import javafx.scene.paint.color; import javafx.stage.stage;  public class grayscale extends application {      @override     public void start(stage stage) {         coloradjust monochrome = new coloradjust();         monochrome.setsaturation(-1);         image image = new image(image_loc);         imageview color = new imageview(image);         imageview gray = new imageview(image);         gray.seteffect(monochrome);          hbox layout = new hbox(10, color, gray);         layout.setpadding(new insets(10));          scene scene = new scene(layout);         scene.setfill(color.black);         stage.setscene(scene);          stage.show();     }      public static void main(string[] args) {         launch(args);     }      // source: http://www.photoshopessentials.com/photo-editing/black-and-white-tutorials/desaturate/     private static final string image_loc =             "http://pe-images.s3.amazonaws.com/photo-effects/black-and-white/grandparents.jpg"; } 

if coloradjust doesn't work you, manipulation on pixel-by-pixel bases using pixelreaders , pixelwriters on writableimage. (i don't see reason canvas involved mention in question). related implementation using writableimage see:


perhaps looking extend pixelformat new type , extend pixelreader read data buffer, may possible, though guess wouldn't necessary accomplish want:

pixelreader reader = new grayscalepixelreader();  reader.getpixels(0, 0, w, h,      grayscalepixelformat.instance(), grayscalebytebuffer, 0, scanlinestride);  image img = new writableimage(reader, w, h);  

where grayscalepixelreader , grayscalepixelformat new classes create via extension.

fx supports pixel types define pixelformat such byte_bgra , byte_bgra_pre; looking add support new pixel type has single sample per pixel 16 unsigned data value.

pixelformat = pixelformat.createbyteindexedinstance(lut); getpixelwriter().setpixels(0, 0, w, h, pixelformat, normalisedimagedata, 0, w);  

yeah, can it, little tricky. agree existing pixelformat in java 8 not readily user extensible, reasons such mention:

some methods e.g getpixelwriter() of writabelimage class final can't override them. image infrastructure looks not designed extended in way.

usually, when comes javafx, lack of extensibility built in on purpose. reasons are:

  1. security, make more difficult people subvert platform doing malicious overriding core functionality perform malicious side effects.
  2. present simplified interface application developer make easier understand , use api.
  3. deliberately make parts of platform opaque, easier library developers maintain core library implementation , change @ without impacting user programs.

of course tradeoff (as in case) can lack of flexibility in trying accomplish wish.

if image implementation in javafx, kind of has 4 different components:

  1. the javafx.scene.image apis.
  2. the platform implementation (prism) backing image apis (see source).
  3. the image io libraries reading common image formats (png, jpg, etc).
  4. interfaces graphics hardware accelerator apis or software rendering apis, example es2, ultimately, treats image texture input hardware graphics api such opengl or direct3d.

the interesting thing grayscale pixel formats not directly exposed in (1) javafx.scene.image apis. however, prism platform implementation, image io libraries , hardware accelerators (2, 3 , 4), have level of inbuilt grayscale support. instance, png file have grayscale format , imageio recognize format , pass grayscale buffer directly prism image class interpereted.

grayscale buffers supported hardware acceleration layer, can seen in es2texture implementation. gives ideal situation of grayscale pixel format encoded buffer image being able directly rendered hardware accelerated texture. note however, current pixel format grayscale byte buffer supported prism/es2 rendering system, 8 bit encoding, not 16 bit encoding ideally ask (though comments on prism pixel format not 16-bit type might needed in future ;-):

// l8, a8 types: // note : might need l8a8 16-bit type byte_gray    (datatype.byte,  1, true,  true),  

so means of infrastructure looking allows direct interpretation of grayscale encoded image buffer javafx runtime there, placed inside com.sun classes , private api , not directly exposed user in public javafx.scene.image apis.

a feature request created enable public api grayscale pixel formats or ask on openjfx-dev mailing list. shortest timeframe such features implemented java 10. looks such request may exist, comment on or bring on openjfx-dev mailing list move forward:

does above info in anyway current problem -> not :-) helps understanding of platform , capabilities, limitations , potential mechanisms future extension support requirements fully.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -