Code Monkey home page Code Monkey logo

Comments (4)

photopea avatar photopea commented on June 5, 2024 1

Hi, sure! The object returned by UPNG.decode() has a property "data" with 16-bit raster data of the image.

If you want to use the same ArrayBuffer, you need to swap pairs of bytes from big endian to a little endian.

See here: #30

from upng.js.

mortac8 avatar mortac8 commented on June 5, 2024

Edit: If I do a >> 8 on all my 16-bit values after your endianness code then all the 8-bit values seem right. Maybe I hosed my webgl2 viewer...argh.

I read through the comments on issue #30 but I have a RGBA image I need help with. Can you advise? I think I need to modify the endianness code your provided. Sorry to bother you again.

http://www.schaik.com/pngsuite/basn6a16.png
upngHelp

fetch("basn6a16.png")
  .then(function(response) {
    return response.blob();
  })
  .then(function(blob) {
    console.log("here's your blob");
    console.log(blob);
    blob.arrayBuffer()
  .then(function(buffer) {
        console.log("here's your arraybuffer");
        console.log(buffer);
        let img  = UPNG.decode(buffer); // put ArrayBuffer of the PNG file into UPNG.decode
        console.log("UPNG ArrayBuffer");
        console.log(img);
        let area = img.width * img.height *4;
        let nimg = new Uint16Array(area); // or just  nimg = [];
        for(let i=0; i<area; i++) nimg[i] = (img.data[i*2]<<8) | img.data[i*2+1];
        console.log("UPNG modified");
        console.log(nimg);
  });
});

from upng.js.

photopea avatar photopea commented on June 5, 2024

BTW. the domain http://www.schaik.com/ does not work for me :(

I opened the basn6a16.png in Photopea.com (which uses UPNG.js) and it seems to work correctly (as your example on the right).

If you need to open any PNG image as a 8-channel RGBA image, use UPNG.toRGBA8(....).

The images in your screenshot look different. I think it could be because of additional multiplying or dividing the RGB values by alpha value.

from upng.js.

mortac8 avatar mortac8 commented on June 5, 2024

Your comment was very helpful. It turns out I had to set {premultipliedAlpha: false} on my webgl2 context which fixed the visual differences.

from upng.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.