Problem using the pixel format indexed bytes in the PixelWriter setPixels method

I'm trying to build a byte array and set it on a WritableImage using the PixelWriter setPixels method.

If I use a RGB pixel format, it works. If I use a byte indexed pixel format, I get a NPE.
Stride etc should be fine if I'm not mistaken.

java.lang.NullPointerException
to com.sun.javafx.image.impl.BaseByteToByteConverter. < init > (BaseByteToByteConverter.java:45)
to com.sun.javafx.image.impl.General$ ByteToByteGeneralConverter. < init > (General.java:69)
at com.sun.javafx.image.impl.General.create(General.java:44)
at com.sun.javafx.image.PixelUtils.getB2BConverter(PixelUtils.java:223)
to com.sun.prism.Image$ ByteAccess.setPixels (Image.java:770)
at com.sun.prism.Image.setPixels(Image.java:606)
to javafx.scene.image.WritableImage$ 2.setPixels(WritableImage.java:199)

Independent, short example here:
import java.nio.ByteBuffer;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class IndexedColorTestApp extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        BorderPane borderPane = new BorderPane();
        Scene scene = new Scene(borderPane, 600, 1100);
        primaryStage.setScene(scene);

        ImageView imageView = new ImageView();
        borderPane.setCenter(imageView);
        primaryStage.show();

        int imageWidth = 200;
        int imageHeight = 200;
        WritableImage writableImage = new WritableImage(imageWidth, imageHeight);

        // this works
        byte[] rgbBytePixels = new byte[imageWidth * imageHeight * 3];
        PixelFormat<ByteBuffer> byteRgbFormat = PixelFormat.getByteRgbInstance();
        writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
                                                 byteRgbFormat, rgbBytePixels, 0, imageWidth * 3);
        imageView.setImage(writableImage);

        // this throws an NPE in setPixels()
        byte[] indexedBytePixels = new byte[imageWidth * imageHeight];
        int[] colorPalette = new int[256];
        PixelFormat<ByteBuffer> byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
        writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
                                                 byteIndexedFormat, indexedBytePixels, 0, imageWidth);
        imageView.setImage(writableImage);
    }

}
If there is no solution, maybe someone knows a solution? We chose to use the format indexed due to the size of the data / performance reasons.

Published by: Andipa on 01.03.2013 10:52

You have found a bug in the platform, filed against the project to-online http://javafx-jira.kenai.com to your sample code and a link to this forum question.
Byte indexed pixel formats seem like a feature never completely (or maybe even any) implemented for me.

The PixelFormat type uses your unsuccessful case is (PixelFormat.Type.BYTE_INDEXED):

PixelFormat byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
System.out.println(byteIndexedFormat.getType());

Here are the valid PixelFormat types =>
http://docs.Oracle.com/JavaFX/2/API/JavaFX/scene/image/PixelFormat.type.html

BYTE_BGRA
The pixels are stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.
BYTE_BGRA_PRE
The pixels are stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.
BYTE_INDEXED
The pixel colors are referenced by byte indices stored in the pixel array, with the byte interpreted as an unsigned index into a list of colors provided by the PixelFormat object.
BYTE_RGB
The opaque pixels are stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.
INT_ARGB
The pixels are stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.
INT_ARGB_PRE
The pixels are stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.

As for a WritableImage native pixel format is not the same that you use the pixel format, the JavaFX platform needs to do a conversion while reading pixels in a format and write it in another format. To do this, he must be able to determine a PixelGetter for your PixelFormat (the PixelGetter is an internal thing, API not public).

And here's the source determines the PixelGetter for a given type of PixelFormat:
http://Hg.OpenJDK.Java.NET/openjfx/8/master/RT/file/06afa65a1aa3/JavaFX-UI-common/src/com/Sun/JavaFX/image/PixelUtils.Java

119     public static  PixelGetter getGetter(PixelFormat pf) {
120         switch (pf.getType()) {
121             case BYTE_BGRA:
122                 return (PixelGetter) ByteBgra.getter;
123             case BYTE_BGRA_PRE:
124                 return (PixelGetter) ByteBgraPre.getter;
125             case INT_ARGB:
126                 return (PixelGetter) IntArgb.getter;
127             case INT_ARGB_PRE:
128                 return (PixelGetter) IntArgbPre.getter;
129             case BYTE_RGB:
130                 return (PixelGetter) ByteRgb.getter;
131         }
132         return null;
133     }

As you can see, the BYTE_INDEXED format is not supported, and null is returned instead... it is the source of your NullPointerException.

Tags: Java

Similar Questions

  • problems using the snap have amd, playback of Jpeg files

    Original title: I'm having problems using the component feature snap-in.

    Sometimes a single document disappears. When this happens while the document program is managed by then will not work. The document seems to be flying around the office. The last time this happened I had a doc JPEG upward and now I can't see what is JPEG. I don't know why the document wants to fly around, and I don't know how to get my use of the JPEG back.

    Hey Graham,.

    To view all jpeg images in the Viewer Windows photo or any other photo software visualization, you must configure this software as a default value in the default programs.

    Check out the link that allows you to configure the program as default.

    http://Windows.Microsoft.com/en-in/Windows7/change-which-programs-Windows-uses-by-default

    You can try to run the Aero Troubleshooter and see if that makes a difference.

    http://Windows.Microsoft.com/en-in/Windows7/open-the-Aero-Troubleshooter

    If the problem persists, provide us newspapers observer of events, as well as the error message if you receive a message.

    http://Windows.Microsoft.com/en-in/Windows7/open-Event-Viewer

  • I'm having a problem using the slideshow module in LR 6.3. The slideshow contains the background image as one of the images to display. Earlier, I had created a slideshow of practice and the background image was not displayed as an image in itself. How to

    I'm having a problem using the slideshow module in LR 6.3. The slideshow contains the background image as one of the images to display. Earlier, I have created a slideshow of practice and the background image was not displayed as an image in itself. How to make it behave?

    Another approach, perhaps a little more elegant (?). Create a collection that includes images for the slideshow. Include the background image in the collection. Drag the background image in the Panel to designate. Then, remove this image from the collection and create the slide show. I just tried and it works, too.

  • Problem using the Overdrive Media Console software program

    When I try to download audio files using the Overdrive Media Console program (used by the public library in my area) I get the error message "error) xC)) D2781: problem occurred in the identification of rights management digital retriving.»   What is the reference for this?

    Hello

    • What is the format of audio file you were trying to play?
    • What version of Windows are you using?

    You can follow below link that can help you to solve your problem:

    http://www.Microsoft.com/windows/windowsmedia/player/Webhelp/default.aspx?&mpver=11.0.5721.5145&ID=C00D11E2&ContextId=71&OriginalID=C00D2781

  • Problem using the REST API by wavemaker

    Hello

    I have a problem using other api with wavemaker. When I do a query GET with the RESTClientin FireFox, everything is fine for example:

    get https://XXX.XXX.XXX.XXX:8281 / vco/api/result:

    1. Status Code: 200 OK
    2. Cache-Control: private
    3. Content-Type: application/xhtml+xml;charset=UTF-8
    4. Date: Sun, 06 Apr 2014 16:50:04 GMT
    5. Expires: Thu, 01 Jan 1970 00:00:00 UTC
    6. Server: Apache-Coyote/1.1
    7. Transfer-Encoding: chunked

    But when I try to connect to the same url using wavemaker I recive: the answer is not in a valid XML Format.

    I use Orchestrator 5.5 and far as I could see the token is no longer required in the header. Anyone know why I get this error message?

    Thank you!

    Well half a day looking, then finally I thought to it:

    The header should be: accept: application/xml

  • Problems using the iPad Pro notes app

    I have a new iPad Pro (IOS 9.2), but the notes app doesn't seem to work properly with a pencil. There is no line doodle icon and I can't write with a pencil. Can I use the pencil to 'click' on the functions as "BOLD" and new, but not as a pencil. Someone at - it experience with this and how can I solve this problem?

    Have you updated the Notes app in the app itself.

  • Equium L40 problems using the recovery disk

    Hello

    I wonder if anyone can help me?

    I want to restore my computer but when I put the recovery disk in I select the cd/dvd rom drive by pressing f12 at startup.
    I also maintained pressed C when I lit. I select the disc I want to start the computer, it goes to a black screen, then it loads just windows up as usual.

    I phoned with Toshiba for help and all they could tell me was that as another drive worked on my computer, it isn't a problem with the disk drive, but a problem with the disc and it will cost me 30 quid for a new!

    Is anyone able to give me any help

    Thank you

    Hello

    If I understand your message, you are not able to recover the laptop using the Toshiba disc. Is this good?

    Well, in your case I recommend to start from another original Windows XP CD bootable disc or Vista DVD or a Linux drive to test if the CD/DVD drive can handle this drive.

    In this case, you can test if your CD/DVD drive is faulty or if the problem is related to the Toshiba DVD recovery.

    Welcome them

  • M277dw: Reset zero problem using the USB to M277dw

    Hello, I'm just trying to see if anyone else has had this problem. I use the laserprinter HP M277dw and use a current running nine Imac El captain. If I print anything on my printer and then decide to reboot my computer for some reason any, if I keep the USB cable connected to my computer that is connected to the printer, the computer hangs on reboot. It is the same on a full stop to the low and new start up as well. It's almost as if the printer is not disconnected somehow when I shut down or restart. The solution I found is to unplug the printer USB whenever I have to restart or shut down and then reconnect to the computer up and running again. My feeling is that this is related to the El captain, but I can't say for sure. Anyone else see this problem?

    Hi @andrewdawson11,

    Welcome to the Forums of HP Support! I see that you have problems, turn off the Mac, it crashes on restart when the printer is connected by a USB connection. I will definitely do my best to help you. If this helps you to find a solution, please click on the button "Accept as Solution" down below in this message. If you want to say thanks for my effort to help, click on the 'Thumbs Up' to give me a Kudos.

    Run Apple updates.

    You download and install the latest drivers for the printer? If the latest driver is not installed, which can cause this problem. Here is the link if you have not already: HP Easy Start.

    Make sure that the correct driver is added.

    Click on the Apple menu, click System Preferences. Click on Printers & Scanners, highlight the name of the printer on the left side and right side of the screen it should show the name of the printer. (Laserjet M277dw)

    If the full name of the printer is not correctly, delete and add the printer name back from the list. Click on the sign - to remove the driver and then click on the + sign to add the driver might have to drop-down list to select the name of the printer to add a click.

    If the problem persists, try the following:

    Fix permissions of the drive on the Mac:

    Close all applications.

    In the Apple menu, click OK, click Applications, and then click utilities.

    Double-click disk utility.

    Highlight your hard drive / partition on the left.

    Click on check and then repair disk permissions.

    Restart the computer...

    Reset the printing system:

    Note: This will remove all printers in the print and Fax/Scan, any printer deleted can be re-added later by clicking the sign plus (+) symbol.

    Click on the Apple icon and then click on System Preferences.

    Click on Printers & Scanners.

    Make a right click (or Ctrl + click) in the left white side panel, and then click Reset printing system.

    Click OK to confirm the reset.

    Type the name and the correct password.

    Click OK to reset the printing system.

    Then click on the sign to add the driver, highlight the printer +. (you may need to click the drop down menu to select the printer name) Then click the Add button.

    Test the printer and try to restart the Mac again.

    If there is anything else I can help you, let me know. Thank you.

  • Problem: Using the command 'msg' with 'system Exec.vi.

    I try to write to the LabView code that takes advantage of the 'Exec.vi System '. For the moment, I have tried to use it to ping machines, return the command ipconfig and run through the code example that provides NEITHER.

    I would use the "msg" command used on Windows operating systems to send a message to several machines on our network at a time. Warning that we're about to update a program and that they should disconnect, things like that.

    I tried to use the command 'msg' LabView maintains return errors. I also wrote a quick command as follows file:

    @echo we
    CD c:\Windows\System32\
    Msg.exe /server:localhost * test

    When I run the batch of windows, it runs. When I launch from LabView (using the Exec.vi system), it fails.

    Potential quirks:

    I discovered in a different place under a machine to receive these messages they need to have a registry entry:

    "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" and have a DWord value called "AllowRemoteRPC' = 1.

    Note that "/ Server: localhost" might be "/ server: anycomputer" and the "*" is used as a wildcard character that sends a message to anyone who is connected to this computer. Also note that the 'test' is the message to send.

    Any ideas why I'm having a problem?

    TL; Dr.: "System Exec.vi" does not have the command "msg". Why is this?


  • I have problems using the parental control. I want to block facebook from a user account. I have facebook in the ban list, but apparently not block. I have Vista. What should I do to block facebook?

    I have problems using parental controls. I want to block facebook from a user account. I have facebook in the ban list, but apparently not block. I have Vista. What should I do to block facebook?

    Have you followed all the steps like that?

    http://www.howtogeek.com/HOWTO/Windows-Vista/use-parental-controls-to-filter-websites-in-Windows-Vista/

    It is an alternative.

    http://explore.live.com/Windows-Live-Family-Safety?OS=other

    http://Windows.Microsoft.com/en-us/Windows-Vista/protecting-your-kids-with-family-safety

    If this post answers your question, click mark as answer .

  • Having a problem using the request of Sirius/XM.

    Hello world. I recently downloaded the Sirius/XM app on my phone, because it allows me to listen to and still take calls throughout my non bluetooth car system, using the input of the car radio. I have the phone cradle-mounted car of Motorola. All my other radio apps will turn horizontal / landscape with the phone, but the Sirius app does not work. It can be quite dangerous trying to find stations or songs while driving when you arm yer head sideways to read the list on the screen. Today, ' I can't ' get smoked a number with Willie more "came and I was trying to see who did the song. I almost lost control of my car!  Anyone know if this is a problem of motorcycle or Sirius? I also emailed Sirius/XM about it. Anyone else having the same problem? Thanks, Matt

    If other applications are running, I believe it's the app that was not intended to turn. curious to see if they meet you?

  • problem using the FileConnection API (JSR 75) in an application for Blackberry "BOLD" MIDLET

    Hello

    I developed a MIDLET which is to read files and store the contents of files in arrays. I could make using the FileConnection API in J2ME (Java ME) and it works very well in mobile emulators provided by Sun, Sun Kit tool 2.5.1 wireless and Sprint Wireless tool 3.3.2 Kit. I have been using netbeans IDE 6.8 for this.

    Now, here's the deal. Playback of the files does not work when in one of the Blackberry mobile emulators. I tried to install all versions of Blackberry JDE 4.2.1 to 5.0 and test the same thing, but none of them worked.  After reading that the Blackberry plugin for Eclipse is good, I used it to find that I am always faced with the problem.

    I desperately need help. Can someone help me do the reading work file in a Blackberry emulator? I insert the code that makes the file reading. It reads a file containing a single column of 60 entries, and stores it in an array of double type.

    Vector time = new Vector();
    
    try{
    
     FileConnection filecon = (FileConnection) Connector.open("file:///" +"SDCard/BlackBerry/documents/"+"timescale.dat");
    
     if(!filecon.exists()) {    Dialog.show("Note ! ", "File doesn't exists !", "okay","cancel"); }
    
         StringBuffer sb = new StringBuffer();      try      {       InputStream in = filecon.openInputStream();       int chars;
    
           while ((chars = in.read()) != -1)// read until EOF is reached       {          if(chars == '\n') // read all characters until the end of line is reached          {              time.addElement(sb.toString().trim()); // stores all the characters as a vector element when the end of line is reached
    
                  sb.delete(0,sb.length());// clear the stringbuffer for storing the next line of the file
    
              }
    
              else          {              sb.append((char)chars); // appends each character read          }
    
          }// end of while
    
        }    catch(IOException e)    {               }
    
        filecon.close();
    
    }// end of outer try
    
       int i =0;   Enumeration etime = time.elements();
    
       while(etime.hasMoreElements() && i < 60) // timescale.dat has 60 entries in one column   {       time_1d[i]=Double.parseDouble(etime.nextElement().toString());// convert to double       i++;   }
    

    Can you elaborate on what does not work?  Is an error or exception thrown?  If Yes, what is it and what line of code triggers it?

    You have configured the BlackBerry smartphone Simulator to simulate a micro SD card?

    Use a computer filesystem in the form of microSD card

    http://supportforums.BlackBerry.com/T5/testing-and-deployment/use-a-computer-file-system-as-a-microS...

  • Problem using the serial port with windows 7

    Hello

    I have a modem of SIM cards (used to update remote controller of the electronic gate) that connects to my computer via the serieal port (COM1).

    The modem comes with its own piece of software that worked fine on my old computer with windows 7 (I had a similar problem, but then I just need to update the driver).

    I now have a new computer and I am unable to connect using the modem (I think I'm using the latest drivers for the serial port).

    Is it possible that I need an older version? If so, how can I get a?

    My motherboard is a GIGABYTE H81M-D2V.

    Any ideas?

    Thank you

    AVI

    Hi Avi,

    Thank you for the update on the issue.

    The UART, or Universal Asynchronous Receiver / Transmitter, is a characteristic of your microcontroller useful to connect serial data (text, numbers, etc.) to your PC. The unit switches incoming parallel information (in the microcontroller/PC) to series data that can be sent over a communication line.

    According to the description you provided it seems that your modem isn't connecting with your Windows 7 computer, then I would contact Duetech Berès your modem manufacturer, so that they provide you with the steps to set it up.

    Get back to us after contacting them and please get back to us with your question was last updated.

    Kind regards.

  • How to solve problems using the event viewr log?

    Hello guys,.

    Can someone tell me how to use the event viewr log and resolve the problems or errors?

    I can solve the problems by myself, but do not know as the use of the display of event logs and information.

    Kind regards

    Claude of RAM

    Notes on the use of Event Viewer:
    http://www.gerryscomputertips.co.UK/syserrors5.htm

  • Having problems using the Arabic language in Windows 7

    Original title: I have language problem with my windows home Prem 7

    Hello

    I have the problem with languages, the Arabic one.

    When I try to write Arabic words in Notepad or Arab opening for laptop or any file letters Arabs language conversion in order to understand the language.

    And I tried to change the Arabic language in the Control Panel, but there is something missing,

    Look at the picture I captured, look at the space marked in blue

    http://WWW7.0ZZ0.com/2012/12/14/20/187833468.jpg

    where is the meeting?

    How can I solve the problem?

    Hello

     

    Welcome to the Microsoft community!

     

    You have problems in the use of Arabic text.

     

    1. have you installed the language pack?

    2. do you receive any error messages?

     

    If you have not installed the language pack, and then install it from the site:

    Language packs

    http://Windows.Microsoft.com/en-in/Windows/language-packs#lptabs=Win7

    Also visit the site to add or change an input language:

    Add or change an input language

    http://Windows.Microsoft.com/en-in/Windows7/add-or-change-an-input-language

    I hope this helps. If the problem persists, let know us and we would be happy to help you.

     

Maybe you are looking for

  • Where is located the Contacts/address book template file?

    My custom template of Contacts was damaged. Where is the template located in OS X Yosemite file? I would like to try and restore from a backup.

  • My storage said I used 12.8 GB but I have no

    When I want to download something, it says not enough blah blah of storage so I'll put and I use only 8GB on the photos and I have only a few applications. There are, I deleted up to 10 apps and storage should be a diminished, but he's still 12.8 GB.

  • my request of Hürriyet

    my request of Hürriyet is off. I can't return my mainpage in my iphone. My mainpage button is also disabled.

  • Satellite Pro L100 PSLA1E - need a new charger

    Hey, to cut a long story short I need a new charger for my laptop and didn't know exactly how many different models there is. My laptop is a: Satellite Pro L100Model no 004006EN - PSLA1E- The site I am trying to buy the charger is asking a number of

  • How to download pictures from a canon eos 450 d to ipad pro?

    I have a Canon EOS 450 d, and given the fact that there not on the iPad Pro card slot, I guess I'll need some sort of connection cable. Does anyone know if this is still available? If not, is there another workaround solution. Thanks in advance.