You are mistaken about the way array
is laid out in memory, as you can find out by declaring img
before the loop and adding this printf
to your inner loop:
printf("%ld %ld %u %u %u
",x,y,pic.offset(x,y,0),pic.offset(x,y,1),pic.offset(x,y,2));
This yields (on my 1920x1200 screen):
0 0 0 2304000 4608000
0 1 1920 2305920 4609920
0 2 3840 2307840 4611840
and so on, indicating that the red/green/blue subimages are kept "together" instead of the three color components of a single pixel being adjacent to each other.
The builtin CImg accessors will make your code work:
pic(x,y,0) = red;
pic(x,y,1) = green;
pic(x,y,2) = blue;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…