<commit_before># Rust Image [![Build Status](https://travis-ci.org/PistonDevelopers/image.svg?branch=master)](https://travis-ci.org/PistonDevelopers/image)
## An Image Processing Library

This crate provides basic imaging processing functions and methods for converting to and from image formats.

All image processing functions provided operate on types that implement the ```GenericImage``` trait and return an ```ImageBuf```.

### Usage

Add the following to the Cargo.toml in your project:

```
[dependencies.image]

git = "https://github.com/PistonDevelopers/rust-image"
```

and import using ```extern crate```:

```rust
    extern crate image;

    //Use image::
```

## 1. Documentation

http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html

## 2. Supported Image Formats
```rust-image``` provides implementations of common image format encoders and decoders.

### 2.1 Supported Image Formats
| Format | Decoding | Encoding |
|---     |---       | --- |
| JPEG   | Baseline JPEG | Baseline JPEG |
| PNG    | All supported color types | Same as decoding|
| GIF    | Yes | No |
| Webp   | Lossy(Luma channel only) | No |
| PPM    | No | Yes |

### 2.2 The ```ImageDecoder``` Trait
All image format decoders implement the ```ImageDecoder``` trait which provides the following methods:
+ **dimensions**: Return a tuple containing the width and height of the image
+ **colortype**: Return the color type of the image.
+ **row_len**: Returns the length in bytes of one decoded row of the image
+ **read_scanline**: Read one row from the image into buf Returns the row index
+ **read_image**: Decode the entire image and return it as a Vector
+ **load_rect**: Decode a specific region of the image

## 3 Pixels
```rust-image``` provides the following pixel types:
+ **Rgb**: RGB pixel
+ **Rgba**: RGBA pixel
+ **Luma**: Grayscale pixel
+ **LumaA**: Grayscale with alpha

All pixels are parameterised by their component type.

## 4 Images
### 4.1 The ```GenericImage``` Trait
A trait that provides functions for manipulating images, parameterised over the image's pixel type.

```rust
pub trait GenericImage<P> {
    ///The width and height of this image.
    fn dimensions(&self) -> (u32, u32);

    ///The bounding rectangle of this image.
    fn bounds(&self) -> (u32, u32, u32, u32);

    ///Return the pixel located at (x, y)
    fn get_pixel(&self, x: u32, y: u32) -> P;

    ///Put a pixel at location (x, y)
    fn put_pixel(&mut self, x: u32, y: u32, pixel: P);

    ///Return an Iterator over the pixels of this image.
    ///The iterator yields the coordinates of each pixel
    ///along with their value
    fn pixels(&self) -> Pixels<Self>;
}
```

### 4.2 Representation of Images
```rust-image``` provides two main ways of representing image data:

#### 4.2.1 ```ImageBuf```
An image parametarised by its Pixel types, represented by a width and height and a vector of pixels. It provides direct access to its pixels and implements the ```GenericImage``` trait.

```rust
extern crate image;

use image::{
    GenericImage
    ImageBuf,
};


//Construct a new ImageBuf with the specified width and height.
let img = ImageBuf::new(512, 512);

//Construct a new by repeated calls to the supplied closure.
let img = ImageBuf::from_fn(512, 512, |(x, y)| {
    if x % 2 == 0 {
        image::Luma(0u8)
    } else {<commit_msg>Fix usage of ImageBuf::from_fn in README.md<commit_after># Rust Image [![Build Status](https://travis-ci.org/PistonDevelopers/image.svg?branch=master)](https://travis-ci.org/PistonDevelopers/image)
## An Image Processing Library

This crate provides basic imaging processing functions and methods for converting to and from image formats.

All image processing functions provided operate on types that implement the ```GenericImage``` trait and return an ```ImageBuf```.

### Usage

Add the following to the Cargo.toml in your project:

```
[dependencies.image]

git = "https://github.com/PistonDevelopers/rust-image"
```

and import using ```extern crate```:

```rust
    extern crate image;

    //Use image::
```

## 1. Documentation

http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html

## 2. Supported Image Formats
```rust-image``` provides implementations of common image format encoders and decoders.

### 2.1 Supported Image Formats
| Format | Decoding | Encoding |
|---     |---       | --- |
| JPEG   | Baseline JPEG | Baseline JPEG |
| PNG    | All supported color types | Same as decoding|
| GIF    | Yes | No |
| Webp   | Lossy(Luma channel only) | No |
| PPM    | No | Yes |

### 2.2 The ```ImageDecoder``` Trait
All image format decoders implement the ```ImageDecoder``` trait which provides the following methods:
+ **dimensions**: Return a tuple containing the width and height of the image
+ **colortype**: Return the color type of the image.
+ **row_len**: Returns the length in bytes of one decoded row of the image
+ **read_scanline**: Read one row from the image into buf Returns the row index
+ **read_image**: Decode the entire image and return it as a Vector
+ **load_rect**: Decode a specific region of the image

## 3 Pixels
```rust-image``` provides the following pixel types:
+ **Rgb**: RGB pixel
+ **Rgba**: RGBA pixel
+ **Luma**: Grayscale pixel
+ **LumaA**: Grayscale with alpha

All pixels are parameterised by their component type.

## 4 Images
### 4.1 The ```GenericImage``` Trait
A trait that provides functions for manipulating images, parameterised over the image's pixel type.

```rust
pub trait GenericImage<P> {
    ///The width and height of this image.
    fn dimensions(&self) -> (u32, u32);

    ///The bounding rectangle of this image.
    fn bounds(&self) -> (u32, u32, u32, u32);

    ///Return the pixel located at (x, y)
    fn get_pixel(&self, x: u32, y: u32) -> P;

    ///Put a pixel at location (x, y)
    fn put_pixel(&mut self, x: u32, y: u32, pixel: P);

    ///Return an Iterator over the pixels of this image.
    ///The iterator yields the coordinates of each pixel
    ///along with their value
    fn pixels(&self) -> Pixels<Self>;
}
```

### 4.2 Representation of Images
```rust-image``` provides two main ways of representing image data:

#### 4.2.1 ```ImageBuf```
An image parametarised by its Pixel types, represented by a width and height and a vector of pixels. It provides direct access to its pixels and implements the ```GenericImage``` trait.

```rust
extern crate image;

use image::{
    GenericImage
    ImageBuf,
};


//Construct a new ImageBuf with the specified width and height.
let img = ImageBuf::new(512, 512);

//Construct a new by repeated calls to the supplied closure.
let img = ImageBuf::from_fn(512, 512, |x, y| {
    if x % 2 == 0 {
        image::Luma(0u8)
    } else {
{'fraction_non_alphanumeric': 0.1271564544913742, 'fraction_numerical': 0.015169541939321832, 'mean_word_length': 3.7060881735479354, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7400331', 'n_tokens_mistral': 2137, 'n_tokens_neox': 1970, 'n_words': 835}