stb-image

OpenGL texture rendering does not match original

允我心安 提交于 2021-02-05 09:16:26
问题 I am trying to render a texture with OpenGL. The texture I am using as a test is a bunch of black rectangles on a white background, as follows: However, when rendering, the texture seem to be duplicated and overlayed multiple times on top of itself: I set the scene up using: std::string vertexSource = ShaderLoader::load("vertexSource.vert"); const char* vsource = vertexSource.c_str(); std::string fragmentSource = ShaderLoader::load("fragmentSource.frag"); const char* fsource = fragmentSource

stb image write issue

你离开我真会死。 提交于 2021-01-29 09:28:59
问题 I am trying to write a simple image file to disk using stb_image_write. I use the simplest test case : a 128 by 128 pixels RGB image. I found this example online, and the guy seems to say that it works fine, plus it looks exactly like what I have been writing for 2 hours : void save_image(int w, int h, int channels_num) { int data[w * h * channels_num]; int index = 0; for (int j = h - 1; j >= 0; --j) { for (int i = 0; i < w; ++i) { float r = (float)i / (float)w; float g = (float)j / (float)h;

自动红眼移除算法 附c++完整代码

ぐ巨炮叔叔 提交于 2020-10-30 03:43:36
说起红眼算法,这个话题非常古老了。 百度百科上的描述: “红眼”一般是指在人物摄影时,当闪光灯照射到人眼的时候,瞳孔放大而产生的视网膜泛红现象。 由于红眼现象的程度是根据拍摄对象色素的深浅决定的,如果拍摄对象的眼睛颜色较深,红眼现象便不会特别明显。 “红眼”也指传染性结膜炎。 近些年好像没有看到摄影会出现这样的情况,毕竟科技发展迅速。 记得最早看到红眼移除算法是在ACDSee 这个看图软件的编辑功能区。 当然,当时ACDSee 也没有能力做到自动去红眼,也需要进行手工操作。 红眼移除不难,其实就是把眼睛区域的颜色修正一下。 但是难就难在修复之后,不要显得太过突兀,或者破坏眼睛周围的颜色 。 这就有点难办了。 当然其实最简单的思路,就是转色域空间处理后再转回RGB。 记得在2015年的时候, 曾经一度想要寻找红眼移除过度自然的算法思路, 当时仅仅是好奇,想要学习之。 直到2016年,在一个Delphi 图像控件的源码里看到了一个红颜移除算法函数。 把代码转写成C之后验证了一下,效果不错,过度很自然。 貌似好像有点暴露年龄了, 俺也曾经是Delphi程序员来的,无比怀念Delphi7。 贴上红眼算法的Delphi源码: procedure _IERemoveRedEyes(bitmap: TIEBitmap; fSelx1, fSely1, fSelx2, fSely2:

stb_image multiple definition of first defined here 多文件包含问题

爷,独闯天下 提交于 2020-07-27 03:52:36
解决办法: 预先定义 STB_IMAGE_IMPLEMENTATION STB_IMAGE_STATIC 两个宏。 首先吐槽一下,网上的其他的一些内容都是瞎写,根本没有指出问题的根本原因,使用时出现异常情况不能自己解决也说明了C语言基础不牢固, 该头文件可以分为两种情况使用(推荐使用办法2,办法1中有解释原因)(任何一种情况都要在使用前 预先定义 STB_IMAGE_IMPLEMENTATION 宏): 1、被当做头文件包含到别的文件中,则其不应该在不同的 .c、.cpp文件中被展开(注意:源文件的头文件会在预处理阶段将其头文件展开,也有可能会变成这种情况),否则相当于在不同的源文件中定义同名的C函数,再编译生成 .o文件时肯定会报重定义的错误。一个解决办法是只在一个源文件(.c .cpp)中展开该项。当然这不是最好的解决办法,C语言中为解决多个源文件包含相同的函数提供了更好的办法,相信你已经猜到了------static关键字,其修饰的函数和全局变量只在本文件中可见,这样就不会和其他文件冲突了,也就是情况2。 2、使用前 预先定义 STB_IMAGE_STATIC ,稍微查看源码即可直到,添加该宏定义以后,函数会被static修改(否则为extern),完美的解决了重定义的问题。推荐大家使用。 来源: oschina 链接: https://my.oschina.net/u

how can I write pixel color data to a bmp image file with stb_image?

半世苍凉 提交于 2019-12-25 02:33:16
问题 I've already opened the bmp file( one channel grayscale) and stored each pixel color in a new line as hex. after some doing processes on the data (not the point of this question), I need to export a bmp image from my data. how can I load the textfile(data) and use stb_image_write ? pixel to image : #include <cstdio> #include <cstdlib> #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" using namespace std; int main() { FILE* datafile ; datafile = fopen("pixeldata.x" , "w");