Coder Social home page Coder Social logo

bin2png's Introduction

bin2png

This class is a utility to insert binary data from a file into a PNG image and export the image to a file without keeping the whole binary data (or the whole image) in memory at any given time. This class also implements the reverse process, i.e. it can extract the binary data from a PNG file, and output the binary data to a file, again without ever keeping the whole image (or the binary data) in memory at any given time.

When embedding the binary data into the PNG, the

Binary to PNG: The binary data is inserted as the color information of the PNG image. Each 3-byte block of the binary data is interpreted as an RGB value of a pixel using the ARGB color model, where the alpha channel is always 0xFF. In case the # of bytes in binary data is not a multiple of 3, the last two bytes, or the last one byte, are interpreted as two colors, or one color, with the alpha channel 0xFE, or 0xFD, respectively. The rest of the pixel data is simply for padding purposes with alpha channel 0x00, so that the image is rectangular with a default width of 32 KiB (32768) and calculated height such that 3heightwidth โ‰ฅ # of bytes. The binary data is read in the same order as it is found in the file.

PNG to binary: The use of the alpha channel allows the extraction utility to differentiate between pixels that contain data (alpha=0xFF, 0xFE, 0xFD, depending on if there are 3, 2 or 1 bytes of data embedded in the pixel) and those pixels that are simply there to pad the image to provide it with a rectangular shape (alpha=0x00). The binary data is written in the same order as it is found in the image.

The class can be downloaded with

git clone https://github.com/iagustsson/bin2png

within the directory bin2png, the class is compiled with

javac -d mods/com.iagustsson.bin2png src/com.iagustsson.bin2png/module-info.java src/com.iagustsson.bin2png/com/iagustsson/bin2png/Bin2PNG.java src/com.iagustsson.bin2png/com/iagustsson/bin2png/SimpleRenderedImage.java

and run by

java --module-path mods -m com.iagustsson.bin2png/com.iagustsson.bin2png.Bin2PNG

or for inserting a 10 GiB binary file into a PNG (resulting in a ~11.5 GiB file) and back

java --module-path mods -m com.iagustsson.bin2png/com.iagustsson.bin2png.Bin2PNG -bin big10G.bin -png big10G.png -out copyof_big10G.bin

(try comparing the binary files, e.g. using diff -s big10G.bin copyof_big10G.bin, and they are identical).

bin2png's People

Contributors

iagustsson avatar

Stargazers

Acemir Sousa Mendes avatar

Watchers

James Cloos avatar

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.