MCPcopy Create free account
hub / github.com/RenderKit/embree / storeSTB

Function storeSTB

tutorials/common/image/stb.cpp:44–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 }
43
44 void storeSTB(const Ref<Image>& img, const FileName& fileName)
45 {
46 std::string ext = toLowerCase(fileName.ext());
47 if (ext != "bmp" && ext != "png" && ext != "jpg") {
48 THROW_RUNTIME_ERROR("Could not store image")
49 return;
50 }
51
52 int width = int(img->width);
53 int height = int(img->height);
54 int channels = 3;
55 std::vector<unsigned char> pixels(width*height*channels);
56 const float maxColor = 255.f;
57 for (int y = 0; y < height; y++)
58 {
59 for (int x = 0; x < width; x++)
60 {
61 Color4 c = img->get(x, y);
62 pixels[(y*img->width+x)*channels+0] = (unsigned char)(clamp(c.r) * maxColor);
63 pixels[(y*img->width+x)*channels+1] = (unsigned char)(clamp(c.g) * maxColor);
64 pixels[(y*img->width+x)*channels+2] = (unsigned char)(clamp(c.b) * maxColor);
65 }
66 }
67
68 if (ext == "bmp" ) { stbi_write_bmp(fileName.str().c_str(), width, height, channels, pixels.data()); return; }
69 if (ext == "png" ) { stbi_write_png(fileName.str().c_str(), width, height, channels, pixels.data(), width * channels); return; }
70 if (ext == "jpg" ) { stbi_write_jpg(fileName.str().c_str(), width, height, channels, pixels.data(), 100); return; }
71 }
72}

Callers 1

storeImageFunction · 0.85

Calls 10

toLowerCaseFunction · 0.85
stbi_write_bmpFunction · 0.85
stbi_write_pngFunction · 0.85
stbi_write_jpgFunction · 0.85
extMethod · 0.80
clampFunction · 0.50
getMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected