P
paul
Hi all,
Could some kind soul peruse the following code and see if there is
anything wrong with it?
Its producing output, but its only occupying the first third of the
output array; to give an example, think of a TV screen where only the
top third shows anything, and what is does show is repeated 3 times.
The code should skip through an array of bytes, taking them in groups
of three, and then writing the results of a calculation on the three
bytes to a third array, so that
second array[0] = results of calculation on first array[ array elements
0,1,2]
second array[1] = results of calculation on first array[ array elements
3,4,5]
- in essence converting 24 bit colour to 8 bit greyscale.
There are elements in the code to allow jumping over redundant elements
in the first array;
for instance, you might only want to scan through the array elements
array[byte_offset ... byte_offset + m_i_total_bytes_to_read]
and then array[byte_offset + m_i_bytes_to_jump ... byte_offset +
m_i_total_bytes_to_read + m_i_bytes_to_jump]
etc.
TIA
Paul
NB: "int" is synonymous with 32 bit unsigned ints
int i_bytes_processed=0;
byte * pixel;
pixel = image->image_data; // image data is defined as byte *
pixel+=byte_offset; // We might not have to start at
(0,0) in the image
// total bytes to read is 3*original
data width x height - 24 bit colour,
// ditto for "bytes_to_read_per_row"
for( int bytes_read = 0; bytes_read < m_i_total_bytes_to_read;
bytes_read+=m_i_bytes_to_read_per_row)
{
for(int i=0; i< m_i_bytes_to_read_per_row; i+=3)
{
byte red = pixel[2]; // last 8 bits is red data
byte green = pixel[1]; // middle 8 bits is green data
byte blue = pixel[0]; // first 8 bits is blue data
// Do some
processing on the values (omitted)
// Write out to the array -
this is a linked list
//
containing bytes elements
m_image_average_b_w.SetAt(i_bytes_processed, calc_result );
i_bytes_processed++;
pixel+=3;
}
pixel+=m_i_bytes_to_jump; // We might not need to
// start processing
from the first byte of the next row.
}
Could some kind soul peruse the following code and see if there is
anything wrong with it?
Its producing output, but its only occupying the first third of the
output array; to give an example, think of a TV screen where only the
top third shows anything, and what is does show is repeated 3 times.
The code should skip through an array of bytes, taking them in groups
of three, and then writing the results of a calculation on the three
bytes to a third array, so that
second array[0] = results of calculation on first array[ array elements
0,1,2]
second array[1] = results of calculation on first array[ array elements
3,4,5]
- in essence converting 24 bit colour to 8 bit greyscale.
There are elements in the code to allow jumping over redundant elements
in the first array;
for instance, you might only want to scan through the array elements
array[byte_offset ... byte_offset + m_i_total_bytes_to_read]
and then array[byte_offset + m_i_bytes_to_jump ... byte_offset +
m_i_total_bytes_to_read + m_i_bytes_to_jump]
etc.
TIA
Paul
NB: "int" is synonymous with 32 bit unsigned ints
int i_bytes_processed=0;
byte * pixel;
pixel = image->image_data; // image data is defined as byte *
pixel+=byte_offset; // We might not have to start at
(0,0) in the image
// total bytes to read is 3*original
data width x height - 24 bit colour,
// ditto for "bytes_to_read_per_row"
for( int bytes_read = 0; bytes_read < m_i_total_bytes_to_read;
bytes_read+=m_i_bytes_to_read_per_row)
{
for(int i=0; i< m_i_bytes_to_read_per_row; i+=3)
{
byte red = pixel[2]; // last 8 bits is red data
byte green = pixel[1]; // middle 8 bits is green data
byte blue = pixel[0]; // first 8 bits is blue data
// Do some
processing on the values (omitted)
// Write out to the array -
this is a linked list
//
containing bytes elements
m_image_average_b_w.SetAt(i_bytes_processed, calc_result );
i_bytes_processed++;
pixel+=3;
}
pixel+=m_i_bytes_to_jump; // We might not need to
// start processing
from the first byte of the next row.
}