MCPcopy Create free account
hub / github.com/CRVI/OpenCLIPP / FillRandomImg

Function FillRandomImg

Bench/src/RandomImage.cpp:31–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29SSize GetBiggestImage();
30
31void FillRandomImg(CSimpleImage& Image, int ImageNo)
32{
33 static bool Initialized = false;
34 const static int NbImages = 2;
35 static CSimpleImage Images[NbImages];
36 static CImage<float> FloatImages[NbImages];
37
38 //assert(ImageNo >= 0 && ImageNo < NbImages);
39
40 if (!Initialized)
41 {
42 // Random image generation is time consuming
43 // So we do it only once
44
45 std::mt19937 Rand; // Mersenne twister pseudo random number generator
46
47 // Uniform distribution that can set all but the leftmost bit
48 std::uniform_int_distribution<unsigned char> Dist(0, 0xFF);
49
50 SSize Big = GetBiggestImage();
51
52 for (int i = 0; i < NbImages; i++)
53 {
54 Images[i].Create(Big.Width, Big.Height, 1, SImage::S32);
55 uint uByteWidth = Images[i].BytesWidth();
56 for (uint y = 0; y < Images[i].Height; y++)
57 for (uint b = 0; b < uByteWidth; b++)
58 Images[i].Data(y)[b] = Dist(Rand);
59 }
60
61
62 std::normal_distribution<float> FloatDist(0, 1);
63
64 for (int i = 0; i < NbImages; i++)
65 {
66 FloatImages[i].Create(Big.Width, Big.Height, 1, SImage::F32);
67 for (uint y = 0; y < FloatImages[i].Height; y++)
68 for (uint x = 0; x < FloatImages[i].Width; x++)
69 FloatImages[i](x, y) = FloatDist(Rand);
70 }
71
72 Initialized = true;
73 }
74
75 uint uByteWidth = Image.BytesWidth();
76
77 if (Image.Type == Image.F32)
78 {
79 for (uint y = 0; y < Image.Height; y++)
80 memcpy(Image.Data(y), FloatImages[ImageNo].Data(y), uByteWidth);
81
82 return;
83 }
84
85 for (uint y = 0; y < Image.Height; y++)
86 memcpy(Image.Data(y), Images[ImageNo].Data(y), uByteWidth);
87}

Callers 5

CreateMethod · 0.85
CreateMethod · 0.85
CreateMethod · 0.85
CreateMethod · 0.85
mainFunction · 0.85

Calls 4

GetBiggestImageFunction · 0.85
BytesWidthMethod · 0.80
DataMethod · 0.80
CreateMethod · 0.45

Tested by

no test coverage detected