Repository

V-PNG : V PNG Image Processing

How to use :

Its simple , download the module and then you just have to do :

import vpng

png_file := vpng.read("image.png") or { return }
png_file.write("output.png")



Tips


To deal with the different kinds of Pixel , (cf: Pixel Types ) the prefered method is :

pixel := png_file.pixels[i]
match pixel {
    vpng.Grayscale {
        ...
    }
    vpng.TrueColor {
        ...
    }
    ...
    ...
}



Methods

Method use
read(filename string) ?PngFile Parses the given filename png file and returns an optional PngFile .
(PngFile).write(filename string) Writes the given PngFile in the filename png file.

Types

Structure

  • PngFile , Object returned by the .parse function. Contains all useful information about the parsed png file :
    pub struct PngFile {
        ihdr       IHDR
    pub:
        width      int          // Width of image
        height     int          // Height of image
        pixel_type PixelType    // Pixels type
    pub mut:
        pixels     []Pixel      // Modifiable pixel array
    }
    

Pixel Types

  • PixelType , Enum for type of pixel possible in the PngFile :
    pub enum PixelType {
        indexed
        grayscale
        grayscalealpha
        truecolor
        truecoloralpha
    }
    
  • PixelType , Generic type for the different possible types of pixels :
    pub type Pixel = Grayscale | GrayscaleAlpha | Indexed |     TrueColor | TrueColorAlpha
    
  • Pixel s :
    • Indexed ( Not supported yet ) :
      pub struct Indexed {
      pub mut:
          index byte
      }
      
    • Grayscale ( Not supported yet ) :
      pub struct Grayscale {
      pub mut:
          gray byte
      }
      
    • GrayscaleAlpha ( Not supported yet ) :
      pub struct GrayscaleAlpha {
      pub mut:
          gray  byte
          alpha byte
      }
      
    • TrueColor (RGB) :
      pub struct TrueColor {
      pub mut:
          red   byte
          green byte
          blue  byte
      }
      
    • TrueColorAlpha (RGBA) :
      pub struct TrueColorAlpha {
      pub mut:
          red   byte
          green byte
          blue  byte
          alpha byte
      }
      



Examples:

  • png-printer.v : Give it a .png file and it will print it for you in the terminal.
  • redline.v : Give it an input .png file and an output .png file. It will read the input, add a diagonal red line and write the result on the output file.

How to compile them from GitHub repository:

[vpng]$ v examples/png-printer.v -path "..|@vlib|@vmodules"



Todo :

  • Handle all types of colors
    • Indexed
    • Grayscale
    • GrayscaleAlpha
    • TrueColor
    • TrueColorAlpha
  • Functions to easily manipulate the pixels / image, for example :
    • Resize
    • Mirror
    • Rotate
    • Zoom
    • Slide
    • Crop
    • Invert colors
    • Change colors
    • ...
  • Write a png file ( Might be hard to have an optimized one )
    • Optimize it
    • Filter pixels lines
    • Group IDAT in chunks
    • Save metadata

About

0
138
last May 7

Author

Henrixounez