Hi guys,
I'm trying to write a program that will read in a series of files and
create a 3D array from the files read in for converting 2D images to 3D
objects. The values read in will be considered as pixel colours and the
size that 1 pixel occupies will depend on an input from the user when
running the program. How can I dynamically change the data type of my 3D
array at runtime. eg. 3D array was defined as type unsigned char in the
code but the file to be read requires the array to be type unsigned short.
I've tried using
typedef unsigned char pixeltype; // assuming data is unsigned char
in my header file and then writing all my functions using the type
pixeltype.
I've tried casting the pointer to the array to a variable of type
unsigned short but it didn't really work. Googling also didn't produce
anything fruitful. Thanks and best regards.
Yogi 3 1848
"yogi" <le******@tarta rus.uwa.edu.au> wrote How can I dynamically change the data type of my 3D array at runtime.
unsigned char *image; /* your raw data */
int pixelsize; /* size of each pixel, in bytes */
int redoffset; /* offset of the start of the red channel from pixel
beginning */
int redbits; /* number of bits used for the red channel */
For extra brownie points, you can have a big / little endian flag.
yogi <le******@tarta rus.uwa.edu.au> wrote: I'm trying to write a program that will read in a series of files and create a 3D array from the files read in for converting 2D images to 3D objects. The values read in will be considered as pixel colours and the size that 1 pixel occupies will depend on an input from the user when running the program. How can I dynamically change the data type of my 3D array at runtime. eg. 3D array was defined as type unsigned char in the code but the file to be read requires the array to be type unsigned short.
That's not really possible. If you've only allocated memory for a
certain number of chars, however are you going to fit the same number of
shorts in there? It would mean that sizeof(short) <= sizeof(char), and
that is only very rarely true on desktop computers. (And where it is, of
course, sizeof(short) == sizeof(char) == 1, and CHAR_BIT >= 16.)
If you know the maximum size of your elements, going the other way
(allocating memory for an array of the largest possible data type, and
then possibly filling it with a smaller type) is possible, but may cost
a lot of memory.
Richard
Yeah... I guess I might have to do it that way by using unsigned short
in my code and then cast it to chars as I need to. Thanks for the help.
Cheers!
Richard Bos wrote: yogi <le******@tarta rus.uwa.edu.au> wrote:
I'm trying to write a program that will read in a series of files and create a 3D array from the files read in for converting 2D images to 3D objects. The values read in will be considered as pixel colours and the size that 1 pixel occupies will depend on an input from the user when running the program. How can I dynamically change the data type of my 3D array at runtime. eg. 3D array was defined as type unsigned char in the code but the file to be read requires the array to be type unsigned short.
That's not really possible. If you've only allocated memory for a certain number of chars, however are you going to fit the same number of shorts in there? It would mean that sizeof(short) <= sizeof(char), and that is only very rarely true on desktop computers. (And where it is, of course, sizeof(short) == sizeof(char) == 1, and CHAR_BIT >= 16.)
If you know the maximum size of your elements, going the other way (allocating memory for an array of the largest possible data type, and then possibly filling it with a smaller type) is possible, but may cost a lot of memory.
Richard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric |
last post by:
How can I dynamically assign an event to an element?
I have tried :
(myelement is a text input)
document.getElementById('myelement').onKeyUp =
"myfnc(param1,param2,param3)";
document.getElementById('myelement') = new
Function("myfnc(param1,param2,param3)");
|
by: sirsean |
last post by:
Hi all. I'm trying to dynamically build menus and objects after my page
loads. Data is stored in an XML file and is parsed at runtime into
Javascript objects. At the moment, I'm working on creating menu items
from these objects. The parsing works fine (using Sarissa), and Firefox
builds the menu no problem. IE, however, does not. The functionality of
the menu will be a single onclick event. It seems that Firefox allows
me to set the...
|
by: Kevin Little |
last post by:
#!/usr/bin/env python
'''
I want to dynamically add or replace bound methods in a class. I want
the modifications to be immediately effective across all instances,
whether created before or after the class was modified. I need this
to work for both old ('classic') and new style classes, at both 2.3
and 2.4. I of course want to avoid side effects, and to make the
solution as light-weight as possible.
|
by: cjl |
last post by:
Hey all:
I've searched the newsgroup, and googled, but I'm stuck. I want to be
able to 'dynamically' add a .js file to a web page after the page has
loaded, based on user interaction.
For example, the user make a choice by clicking on an item called
20050928, and as a result a file named "20050928/case.js" is
"included", and the data contained within is available.
|
by: RobG |
last post by:
I have a function whose parameter is a reference the element that called it:
function someFunction(el)
{
...
}
The function is assigned to the onclick event of some elements in the
HTML source:
| |
by: Marcus |
last post by:
I have a problem maybe one of you could help me with. I've created a data
entry screen with lots of dynamically-created client-side controls. I
create HTML texboxes client-side by assigning a value to the td.innerHTML
property. The UI is done, and I now want to post back the user's changes
and update my business object in .NET. But when I postback, I can't see any
of my dynamically created HTML controls in VB .NET. How do I make them...
|
by: pmclinn |
last post by:
I was wondering if it is possible to dynamically create a structure.
Something like this:
public sub main
sql = "Select Col1, Col2 from Table a"
dim al as new arraylist
al = LoadOracleData(sql)
'____Do amazing things
|
by: skumar434 |
last post by:
Hi everybody,
I am faceing problem while assigning the memory dynamically to a array
of structures .
Suppose I have a structure
typedef struct hom_id{
int32_t nod_de;
int32_t hom_id;
|
by: lucindaa |
last post by:
Hi EveryBody,
i have a problem in setting the column type of datagrid dynamically in C# .Net Windows App.
i am generating the grid automatically by assigning datasource of a datatable
the columns are dynamicallygenerated when i do like this all the columns are generated as textbox but i want some of the column should be in combo box, Checkbox
so Please help me to set column type of datagrid dynamically in C# .Net Windows App
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |