« first day (1767 days earlier)      last day (1077 days later) » 

1:09 AM
@nwp Thank you so much.
 
1:35 AM
@ThePirate42 instead of splitting in two you split by a factor of 1.6
 
2:27 AM
Folks, I see this kind of struct initialization where members of the struct are initialized by name.
const my_struct my_var = {
      .my_member = 12,
      .my_other_member = 24
};
when I try to write an initialization like that, I get an error "E0029 expected an expression" for each member. Visual Studio.
What may be the cause of these compilation errors?
 
2:52 AM
Come to think of it, does this kind of initialization wort differently in C++ and plain C ?
 
 
1 hour later…
3:54 AM
@NickAlexeev Yes. These are "designated initializers". They were added to C quite a while ago (C99, if memory serves). It was added to C++ much more recently (and some compilers don't implement it yet). Big difference between C and C++ is that in C, order doesn't matter but in C++, the order in an initialization list must match order of declaration.
 
 
2 hours later…
6:20 AM
Say I have a static struct A somewhere in the code, which I need to use in a function f in a different file. Functions f calls many other functions which also require A. I have 2 options : get the instance of A in f and pass it around as a parameter to the other functions, or get the instance of A in each of the functions. Which would you rather use? In C
 
 
3 hours later…
9:28 AM
Anyone on the question above?
 
9:38 AM
@Eminem depends, if you are 100% sure you're never going to do multi-threading and can't imagine that you will ever need more than one instance of that struct in one process ever, then go ahead and get the instance. Otherwise pass it in as a parameter
 
9:58 AM
But I do use multi threading :)
But adding the parameter to hundreds or even thousands of functions calls is probably a bad idea.
 
 
3 hours later…
12:39 PM
uint16_t tmpRes = 0xFF00;
int16_t intPart = *(int16_t*)&tmpRes;

Why `intPat` is `-256`?
 
because sligned overflow is a bitch
wait this is just twos complement of 0xFF00 being -256
 
1:21 PM
hello does somebody know if you have an if statement with functions for example:
if(fun1() || fun2() || fun3()). will this guarantee that all functions are called inside the if or is there a risk of optimization if fun1() is true the rest are not called anymore?
 
1:34 PM
@valer it's guaranteed not to call fun2 and fun3 if fun1() is true
that's why "||" and "&&" are called logical "short-circuit" operators
if they're bools you can just bitwise or them, that doesn't have the "short-circuit" behavior
if(fun1() | fun2() | fun3())
 
@PeterT thank you !
 
1:49 PM
@valer That is as long as the functions return bool or types that convert to bool. If they return a class types which overload operator|| then short-circuiting doesn't happen.
 
 
2 hours later…
3:35 PM
hello, I have a simple question, Imagine that you want to set your 800*800 image as ingame avatar, but If I resize it that much, it look really bad.. unsharp barelly visible pixels. Question is how to scale it to prevent this effect? For example like windows do for in folder images icon view?
I had idea to get average color of grid of pixels from original image, that will represent one pixel at output image. But the code starting to be too complicated to me
and .setSmooth(true); makes no visible differrent
 
@maxif1997 there's a lot of downsampling techniques, one of the easiest is bilinear
 
ah, algorithms, my old enemy, I totally forget to look for some, good point
 
for high-quality downscaling you can use Mitchell or Lanczos
bilinear is really simple, you just look at the pixel neighborhood and mix those colors in proportionally to their position/contribution to the new pixel
 
4:08 PM
in the base the point is still same , right? It actually take original image, disassemble it to pixels, make some logic to calculete new once and return new image at diferrent size
I really dont understand to that math algorithms, but if you say that it check neghbours its starting to make sence to me
 
4:56 PM
The simple version is just something like
for(unsigned long pixelIdx = 0; pixelIdx < newWidth*newHeight; ++pixelIdx ){
int y = pixelIdx /newWidth;
int x = pixelIdx % newWidth;
newImg(x,y) = sample(oldimg,x,y,newWidth,newHeight); // do the sampling inside here
}
 
5:17 PM
thanks, I will save it and try to read it tomorrow. It seems Im too tired now
 
and then a very primitive sampling would be like
pixel sample(Img& source, int x, int y, unsigned newHeight,unsigned newWidth){
unsigned oldHeight = source.height;
unsigned oldWidth = source.width;
pixel newPixel = {};

//calculate the pixel coordinates in the old image closest to the corners of the pixel in the new image
int oldx1 = round((float)oldWidth * (x-0.5f) / newWidth);
int oldy1 = round((float)oldHeight * (y-0.5f) / newHeight);
int oldx2 = round((float)oldWidth * (x+0.5f) / newWidth);
 
ok
 
but there's plenty of libraries out there to do pretty good downsampling for you
if it's just for trying out I'd say go for something like CImg, it's header only so it's easy to integrate
 
For now I solve it with drawing image at required size,. but this downsampling seems like from time to time needed feature, so I will do some algorithm for it.
 
6:15 PM
@PeterT this is going to sound stupid... but IIRC you're better off explicitly casting when working with float because IIRC it gets promoted automatically to double.
 
6:37 PM
yeah, this was just to convey the idea. I think a serious implementation can easily do without any floating point math at all
 
 
2 hours later…
8:57 PM
Does anyone know how this code works? : length(x[x > 10]). It is documented as "creating a vector that contains the subset of values from the original vector that match the condition of being greater than 10". Is x the "original vector" here? what is x[x > 10] doing?
 
9:15 PM
@KeithMadison What are you talking about here? Looks vaguely like Python list comprehension, or possibly something with a std::valarray?
 

« first day (1767 days earlier)      last day (1077 days later) »