Git Product home page Git Product logo

stbipp's Introduction

Stbipp

  • master : master
  • develop : develop

Stbipp is a cross-platform small sized image I/O library based on stb_image and stb_image_write, developed in C++11.

It brings an abstract layer between the features of stb_image and the developer, and CMake files to easily incorporate the library into your projects.

The initial idea was to create a library to easily load and write images, and convert those into different formats. Edit the images without having the overhead of a big library.

The supported load format are the same as stb_image :

JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)

PNG 1/2/4/8/16-bit-per-channel

TGA (not sure what subset, if a subset)

BMP non-1bpp, non-RLE

PSD (composited view only, no extra channels, 8/16 bit-per-channel)

GIF (*comp always reports as 4-channel)

HDR (radiance rgbE format)

PIC (Softimage PIC)

PNM (PPM and PGM binary only)

Also the supported export format are the same as stb_image_write :

  • JPEG
  • PNG
  • BMP
  • HDR
  • TGA

Requirements

Really few requirements are needed :

  • A C++ compiler compatible with the C++11 standard.
  • CMake

Install

Just clone the project and build/ install it where you want

git clone https://github.com/Rodousse/stbipp.git
cd stbipp
mkdir build
cd build
cmake ..
make

Example

#include <stbipp/Image.hpp>
#include <stbipp/ImageExporter.hpp>
#include <stbipp/ImageImporter.hpp>

int main()
{
    // Load Image
    stbipp::Image image{};
    // Load image as an RGB image with 8 bits per channel
    if(!stbipp::loadImage(std::string(RESOURCE_PATH) + "/example.jpeg", image, stbipp::ImageFormat::RGB8))
    {
        return 1;
    }

    // Create an image with the given dimensions
    stbipp::Image save(image.width(), image.height());

    // Fill the image
    for(auto y = 0; y < save.height(); ++y)
    {
        for(auto x = 0; x < save.width(); ++x)
        {
            using namespace stbipp;
            save(x, y) = Color4f{static_cast<float>(x)/save.width(), 
                                 static_cast<float>(y)/save.height(), 
                                 0.0f, 
                                 0.0f};
        }
    }

    // Clone image in a different format (e.g : RGB with 16 bits per channel)
    auto castedImage = save.castData<stbipp::Color3us>();

    // Export the created image as a grayscale with alpha image
    if(!stbipp::saveImage("test.png", save, stbipp::ImageSaveFormat::LUMA))
    {
        return 1;
    }

    return 0;
}

stbipp's People

Contributors

rodousse avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

stbipp's Issues

[test] Implement tests

Is your feature request related to a problem? Please describe.
Well this is pretty clear... Let's implement some tests!

[Image] Add a sampling operator for floating point coordinates

Is your feature request related to a problem? Please describe.
The sampling is made as follow :

auto color = image(1,20) ;
auto sameColor = image(1.01,20.1) ; // equivalent to 'image(int(1.01), int(20.1))'

The color returned in both case will be the same.

Describe the solution you'd like
Using floating point in pixel accessor would perform a linear sampling, a nearest pixel sampling, or a custom made sampler.

Describe alternatives you've considered
A convenient way would be to use a functor to sample the image as follow :

auto color = image.at<LinearSamplingFunctor>(10.01,20.1);

[build] Add CI to the project

Is your feature request related to a problem? Please describe.
To insure that the project builds on all platforms and at any time, it is now time to implement a continuous integration that perform build operations, and later launch the tests (when implemented).

Describe the solution you'd like
A classic github action implementation will do the trick. Test on PR and add the little label in the readme (it's kinda cool imo)

[Color] Add some clear template parameters for SFINAE

Is your feature request related to a problem? Please describe.
The Color class uses a lot the SFINAE principle in maybe too verbose way

Describe the solution you'd like
Make some type traits that are meaningful to the developer such as :

template<class DataType, class ODataType>
struct is_float_to_integer_cast
{
    static const bool value = (std::is_floating_point<DataType>::value && std::is_integral<ODataType>::value) &&
                              !std::is_same<DataType, ODataType>::value;
};

[Exporter] Crop value greater than 1.0 for non hdr format

Describe the bug
When saving an image to a non HDR format, and having channel color values greater than 1.0, the saved image looks... Let's say wrong. If you look at the result image from the example, the fractal patterns shall be using gray shades.

Expected behavior
As the title of the issue let suppose... Crop value greater than 1.0 for non hdr format

Screenshots
test

[Image] Set at runtime Image data underlying type

Is your feature request related to a problem? Please describe.
The same way OpenCV is doing it, we can change at runtime the "Color" underlying type.
For the moment it is fixed to Color<float,4>. But what if we want it to be encoded with 3 unsigned chars, or 26 doubles...

It would get rid of the castData() templated member function and will come very handy in some cases.

[Color] Add rvalue operator optimization

Is your feature request related to a problem? Please describe.
The color code handles only lvalues, except for the basic operations such as move assignment and move construction.
But when it comes to Color instantiated only in calculus... Well it is not that optimized.
Let's take a concrete example:

stbipp::Color4f col{0.0f};
col += 1.0f + stbipp::Color4f{1.0f, 2.0f, 3.0f, 4.0f} / 2.0f;

This gives us the right computation result on line 2, although the way the calculus is achieved:

  1. Instantiate Color4f and initialize with parameters {1.0f, 2.0f, 3.0f, 4.0f}
  2. Create a temporary Color4f that stores the result of the division by 2.0f and return it
  3. Create a temporary Color4f that stores the result of the previous operation and add 1.0f to it, then return it.
  4. Add the result to col.

As we can see there are 2 temporary allocation that are avoidable in steps 2 and 3.

Describe the solution you'd like
Well we can use the C++ wonderful rvalue feature, and have operator specialized when we manipulate rvalues in such operations (ref-qualified member functions):

stbipp::Color operator/(Real val) &&
{
  for(auto& val: m_data)
  {
    val /= 2.0;
  }
  return std::move(*this);
}

Et voila, no copy, no useless allocation!

[doc] Add a short documentation file

Description

A document relating all the features of the library as part of the README or a separate file would be much appreciate for new comers.

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.