Giter Site home page Giter Site logo

Comments (1)

rygorous avatar rygorous commented on July 28, 2024 2

This is the intended behavior. Quoting from the header file:

If req_comp is non-zero, *comp has the number of components that would
have been output otherwise. E.g. if you set req_comp to 4, you will always
get RGBA output, but you can check *comp to easily see if it's opaque.

-Fabian
On Apr 3, 2015 08:51, "Kyle Swanson" [email protected] wrote:

Forcing the number of components per pixel doesn't seem to be working with
stb_image.h. Calling stbi_load() with any number between 0 .. 4 always
results in 3. See code below.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(int argc, char **argv) {
const char *inputFile = argv[1];
const char *outputFile = argv[2];
int x,y,n;
unsigned char *data = stbi_load(inputFile, &x, &y, &n, 1); //This should force just one (gray) component per pixel.

if (!data) {
    fprintf(stderr, "Couldn't load image.\n");
    return (-1);
}

printf("%d\n", n); //This prints `3`, should print 1.

stbi_image_free(data);
return 0;

}


Reply to this email directly or view it on GitHub
#103.

from stb.

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.