Are there alignment bytes added to BGR data ? Not relevant in case if width is a multiple of 4, but in general you can have each row size padded to multiple of 4 (in bytes). For example opencv does that (so size of 6x6 24 bit rgb image is not 108 but 120 bytes, additional 2 padding bytes for each row).I want to get RGB values from a 24 bit BGR data.
Ok sorry I'm probably confusing you, so the problem is this:
you have - [ B1,G1,R1, B2,G2,R2, ..., Bn,Gn,Rn ]
and you want - [ R1,G1,B1, R2,G2,B2, ..., Rn,Gn,Bn ]
?
You can do that conversion in-place, if you have buffered the data from the socket, you can change it without need of another buffer.
As you can see, you can leave the middle byte in each pixel alone, so you can do a simle swap (in case of in-place conversion), or three assignments (in case of copying). No need to have two loop variables btw., you can do that in single pass. This is three-four lines of code but i won't write it. Get a piece of paper and try to first perform this algorithm manually, its not that hard.
Bookmarks