473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processing byte arrays

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_ju mp ... byte_offset +
m_i_total_bytes _to_read + m_i_bytes_to_ju mp]
etc.

TIA

Paul

NB: "int" is synonymous with 32 bit unsigned ints

int i_bytes_process ed=0;

byte * pixel;

pixel = image->image_data; // image data is defined as byte *
pixel+=byte_off set; // 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_re ad_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_by tes_processed, calc_result );

i_bytes_process ed++;

pixel+=3;
}

pixel+=m_i_byte s_to_jump; // We might not need to
// start processing
from the first byte of the next row.
}

Jun 28 '06 #1
5 2858
NB: "int" is synonymous with 32 bit unsigned ints

Not in C++, it ain't.
"int" is an abbreviation of "signed int", NOT "unsigned int".
If you want an abbreviation, use "unsigned".

unsigned i = 0;
byte * pixel;

Redudant statement -- does absolutely nothing. Perhaps you meant something
like:

byte *= pixel;
I'd need more context (and a fine-tooth comb) to tell you any more.
--

Frederick Gotham
Jun 28 '06 #2

Frederick Gotham wrote:
NB: "int" is synonymous with 32 bit unsigned ints

Not in C++, it ain't.


I meant within the context of this example.


"int" is an abbreviation of "signed int", NOT "unsigned int".
If you want an abbreviation, use "unsigned".

unsigned i = 0;
byte * pixel;

Redudant statement -- does absolutely nothing. Perhaps you meant something
like:

byte *= pixel;


Don't you mean byte * pixel = image->image_data ?


I'd need more context (and a fine-tooth comb) to tell you any more.

What it does, simply put is
second_array[0] = f( first_array[0,1,2])
second_array[1]=f( first_array[3,4,5])
second_array[2]=f( first_array[6,7,8])
etc., where the function f(...) is just some junk I do on the 3 byte
array elements of the first array

Jun 28 '06 #3
Paul posted:

Don't you mean byte * pixel = image->image_data ?

Think I might have found your error.

Here's a verbatim copy-paste from your original post:

byte * pixel;

pixel = image->image_data; // image data is defined as byte *
You've two problems here.
First of all, let's change it to what you intended:

byte * pixel = image->image_data;
Take out your favourite C++ operator precedence table (
http://www.difranco.net/cop2334/cpp_op_prec.htm ), and you'll see that
multiplication is performed before assignment -- so you're trying to
assign something to an R-value.

And even if you supply the necessary parentheses:

bytes * (pixel = image->image_data);

You're still left with a partly redundant statement, because the result
of the multiplication is discarded.

I'm still not quite sure what you're trying to do.
--

Frederick Gotham
Jun 28 '06 #4

Frederick Gotham wrote:
Paul posted:

Don't you mean byte * pixel = image->image_data ?

Think I might have found your error.

Here's a verbatim copy-paste from your original post:

byte * pixel;

pixel = image->image_data; // image data is defined as byte *
You've two problems here.
First of all, let's change it to what you intended:

byte * pixel = image->image_data;
Take out your favourite C++ operator precedence table (
http://www.difranco.net/cop2334/cpp_op_prec.htm ), and you'll see that
multiplication is performed before assignment -- so you're trying to
assign something to an R-value.

And even if you supply the necessary parentheses:

bytes * (pixel = image->image_data);


Er, I was perhaps a bit glib when I use "byte" I mean, by "byte *
pixel", that pixel is
a pointer to a byte.

Jun 28 '06 #5
Pul posted:

Er, I was perhaps a bit glib when I use "byte" I mean, by "byte *
pixel", that pixel is
a pointer to a byte.

Wups, it's me that's confused! I'm used to having a capital letter at the
start of a type's name, e.g.

Byte *pixel;
When I saw:

byte * pixel;
I (mistakenly) presumed that they were both objects, and that you were
performing a redundant multiplication.
--

Frederick Gotham
Jun 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
461
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
1
7219
by: Eric Hendriks | last post by:
// In an unmanaged DLL the following function must be called: // int VFGeneralize(const BYTE * const * features); // "features" parameter is supposed to be an array of byte arrays. // function is Marshaled as follows: static extern int VFGeneralize(byte features); In C# I have the following: // Allocate memory to store "Count"...
8
3400
by: Ben Terry | last post by:
What's the most efficient way to transfer data from a byte to a struct? The struct is rather complex--contains other structs as well as byte members. I've tried to use Marshal.Copy and an IntPtr to my struct address but I get the following error, perhaps due to the byte members of my struct: Cannot take the address or size of a variable of a...
7
6852
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ASCIIEncoding asciiEncoder = new ASCIIEncoding();
0
1204
by: Claire | last post by:
My application has a thread reading byte arrays from an unmanaged dll(realtime controller monitoring). The array represents an unmanaged struct containing a series of header fields plus a variable sized array of upto 300 structs. Current version of c# doesn't support this sort of struct hence I just pass an array of bytes to the dll. When I...
6
2760
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1) using redim arrays to add to a normal byte array (2) using an ArrayList and finally (3) using a memorystream. These three classes are listed below...
6
4666
by: Vitaly Zayko | last post by:
It's probably simple but I can't find a way how to copy number of bytes from one byte array to another? Just like Array.Copy(SourceArray, SourceIndex, DestArray, DestIndex, Length) does but in my case the arrays have different length. Of course I can copy byte by byte but I guess there should be a function for such task. Thanks! -- Vit...
4
3594
by: Alexis Gallagher | last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if this is a double-post.) Is it possible to do very fast string processing in python? My bioinformatics application needs to scan very large ASCII files (80GB+), compare adjacent lines, and conditionally do some further processing. I believe the disk i/o is the main...
17
7232
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.