Note how in the FOR loop Npixel is incremented by 1, when npixel = 0 it works like you think, but note when npixel = 1 then "r" will have the value you placed in "g" in prior interations, and so on. Instead using "npixel" for your array index you need to use a index that is incremented by 3.
thnx , i haven't see this bug

i need to copy the whole block pixel per pixel , in case of a trensparent texture
i've to set alpha channel also while looping .

@NecroDOME , thnx for the code , but didn't work