C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28630
Number of posts: 94612

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
beginner on image procesing Posted by cacaramba on 28 Apr 2005 at 10:00 AM
hi
i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?

thanks

cacaramba
Report
Re: beginner on image procesing Posted by Gaashius on 28 Apr 2005 at 11:42 AM
: hi
: i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
:
: thanks
:
: cacaramba
:
Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics

If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
http://www.programmersheaven.com/search/Download.asp?FileID=923

An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
int image[100][100]

But, remember that you can also store image in memory.

Or, you could just load the file directly onto the screen.

Hope this lil info helps you out.
****************
Any questions? Just ask!

GAASHIUS


Report
Re: beginner on image procesing Posted by neoalucard on 1 Feb 2006 at 1:21 AM
: : hi
: : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: :
: : thanks
: :
: : cacaramba
: :
: Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
:
: If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: http://www.programmersheaven.com/search/Download.asp?FileID=923
:
: An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
:
: int image[100][100]
: 

: But, remember that you can also store image in memory.
:
: Or, you could just load the file directly onto the screen.
:
: Hope this lil info helps you out.
: ****************
: Any questions? Just ask!
:
: GAASHIUS
:
:
:
i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
Report
Re: beginner on image procesing Posted by MT2002 on 3 Feb 2006 at 6:26 PM
This message was edited by MT2002 at 2006-2-3 18:32:15

: : : hi
: : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : :
: : : thanks
: : :
: : : cacaramba
: : :
: : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: :
: : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : http://www.programmersheaven.com/search/Download.asp?FileID=923
: :
: : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: :
: : int image[100][100]
: : 

: : But, remember that you can also store image in memory.
: :
: : Or, you could just load the file directly onto the screen.
: :
: : Hope this lil info helps you out.
: : ****************
: : Any questions? Just ask!
: :
: : GAASHIUS
: :
: :
: :
: i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
:

Just loop it. Example..
const int iWidth = 100, //image width/height
          iHeight = 100;

char* image;      // your loaded image

int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)


// copy the image
for ( int y = 0; y< iHeight; y++)
   for ( int x=0; x<iWidth; x++)
     pixels [y][x] = image [x+y*iWidth];


The formula x+y*iWidth can be used to retrieve an element
(in this case, pixel) at an x/y location in linear memory.

This will only work if "image" and "pixels" are
the same bit depth. If they are not, you will need to
convert it.

Hope this helps!
~mt2002



Report
Re: beginner on image procesing Posted by neoalucard on 5 Feb 2006 at 11:35 PM
: This message was edited by MT2002 at 2006-2-3 18:32:15

: : : : hi
: : : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : : :
: : : : thanks
: : : :
: : : : cacaramba
: : : :
: : : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: : :
: : : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : : http://www.programmersheaven.com/search/Download.asp?FileID=923
: : :
: : : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: : :
: : : int image[100][100]
: : : 

: : : But, remember that you can also store image in memory.
: : :
: : : Or, you could just load the file directly onto the screen.
: : :
: : : Hope this lil info helps you out.
: : : ****************
: : : Any questions? Just ask!
: : :
: : : GAASHIUS
: : :
: : :
: : :
: : i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
: :
:
: Just loop it. Example..
: const int iWidth = 100, //image width/height
:           iHeight = 100;
: 
: char* image;      // your loaded image
: 
: int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: 
: 
: // copy the image
: for ( int y = 0; y< iHeight; y++)
:    for ( int x=0; x<iWidth; x++)
:      pixels [y][x] = image [x+y*iWidth];

:
: The formula x+y*iWidth can be used to retrieve an element
: (in this case, pixel) at an x/y location in linear memory.
:
: This will only work if "image" and "pixels" are
: the same bit depth. If they are not, you will need to
: convert it.
:
: Hope this helps!
: ~mt2002

:
:
:
i have this code for comaparing two images to see if they are 100% match with each other.
#include<stdio.h>
#include<math.h>

/* definition of both bitmaps height and width */
#define BITMAPX 352
#define BITMAPY 292

/* structure to contain data for one pixel */
typedef struct {
float r,g,b; /* color data varies for each color from 0-255 */
}RGB; /* they are floats just for convinience */

/* two 352x292x24 bit bitmaps containing about to be compared images */
RGB bitmap1[BITMAPX][BITMAPY],bitmap2[BITMAPX][BITMAPY];


/* variables to hold number of pixels, current pixel and match so far */
/* and match for current pixel */
float pixels=BITMAPX*BITMAPY,current_pixel=0;
float match=0,currentmatch=0;


main()
{

/* now we start looping through all pixels in our bitmaps comparing */
/* according pixels to each other */
int posx, posy, currentpixel;
for(posx=0;posx<BITMAPX;posx++){
	for(posy=0;posy<BITMAPY;posy++){
		currentpixel++;

		/* this is where actual comparison takes place */
		/* given that all three basic colors are on different axis */
		/* match between them can be calculated using */
		/* vector length equation */
		currentmatch=sqrt(pow(bitmap1[posx][posy].r-bitmap2[posx][posy].r,2)+pow(bitmap1[posx][posy].g-bitmap2[posx][posy].g,2)+pow(bitmap1[posx][posy].b-bitmap2[posx][posy].b,2));

		match=((match*currentpixel)+currentmatch)/(currentpixel);
		}
	}

match=100-match/2.56;

printf("%f",match);
}


but i cant seem to load the image properly to the two dimensional arrays that I declared. how can I for example load an image named "try.bmp" to bitmap1 and "try1.bmp" to bitmap2. thanks!
Report
Re: beginner on image procesing Posted by MT2002 on 6 Feb 2006 at 5:56 PM
: : This message was edited by MT2002 at 2006-2-3 18:32:15

: : : : : hi
: : : : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : : : :
: : : : : thanks
: : : : :
: : : : : cacaramba
: : : : :
: : : : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : : : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: : : :
: : : : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : : : http://www.programmersheaven.com/search/Download.asp?FileID=923
: : : :
: : : : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: : : :
: : : : int image[100][100]
: : : : 

: : : : But, remember that you can also store image in memory.
: : : :
: : : : Or, you could just load the file directly onto the screen.
: : : :
: : : : Hope this lil info helps you out.
: : : : ****************
: : : : Any questions? Just ask!
: : : :
: : : : GAASHIUS
: : : :
: : : :
: : : :
: : : i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
: : :
: :
: : Just loop it. Example..
: : const int iWidth = 100, //image width/height
: :           iHeight = 100;
: : 
: : char* image;      // your loaded image
: : 
: : int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: : 
: : 
: : // copy the image
: : for ( int y = 0; y< iHeight; y++)
: :    for ( int x=0; x<iWidth; x++)
: :      pixels [y][x] = image [x+y*iWidth];

: :
: : The formula x+y*iWidth can be used to retrieve an element
: : (in this case, pixel) at an x/y location in linear memory.
: :
: : This will only work if "image" and "pixels" are
: : the same bit depth. If they are not, you will need to
: : convert it.
: :
: : Hope this helps!
: : ~mt2002

: :
: :
: :
: i have this code for comaparing two images to see if they are 100% match with each other.
:
: #include<stdio.h>
: #include<math.h>
: 
: /* definition of both bitmaps height and width */
: #define BITMAPX 352
: #define BITMAPY 292
: 
: /* structure to contain data for one pixel */
: typedef struct {
: float r,g,b; /* color data varies for each color from 0-255 */
: }RGB; /* they are floats just for convinience */
: 
: /* two 352x292x24 bit bitmaps containing about to be compared images */
: RGB bitmap1[BITMAPX][BITMAPY],bitmap2[BITMAPX][BITMAPY];
: 
: 
: /* variables to hold number of pixels, current pixel and match so far */
: /* and match for current pixel */
: float pixels=BITMAPX*BITMAPY,current_pixel=0;
: float match=0,currentmatch=0;
: 
: 
: main()
: {
: 
: /* now we start looping through all pixels in our bitmaps comparing */
: /* according pixels to each other */
: int posx, posy, currentpixel;
: for(posx=0;posx<BITMAPX;posx++){
: 	for(posy=0;posy<BITMAPY;posy++){
: 		currentpixel++;
: 
: 		/* this is where actual comparison takes place */
: 		/* given that all three basic colors are on different axis */
: 		/* match between them can be calculated using */
: 		/* vector length equation */
: 		currentmatch=sqrt(pow(bitmap1[posx][posy].r-bitmap2[posx][posy].r,2)+pow(bitmap1[posx][posy].g-bitmap2[posx][posy].g,2)+pow(bitmap1[posx][posy].b-bitmap2[posx][posy].b,2));
: 
: 		match=((match*currentpixel)+currentmatch)/(currentpixel);
: 		}
: 	}
: 
: match=100-match/2.56;
: 
: printf("%f",match);
: }
: 

:
: but i cant seem to load the image properly to the two dimensional arrays that I declared. how can I for example load an image named "try.bmp" to bitmap1 and "try1.bmp" to bitmap2. thanks!
:

Do you have a bitmap loader? If so, load the bitmap to heap
memory, and copy it to the array (as I posted).

If you dont have a loader, making one is easy. The Win32 API
makes it even easier. Im assuming you dont have a loader
(according to your code). If so, check out
http://www.gamedev.net/reference/articles/article1966.asp

Hope this helps!
~mt2002

Report
Re: beginner on image procesing Posted by neoalucard on 7 Feb 2006 at 10:39 PM
: : : This message was edited by MT2002 at 2006-2-3 18:32:15

: : : : : : hi
: : : : : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : : : : :
: : : : : : thanks
: : : : : :
: : : : : : cacaramba
: : : : : :
: : : : : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : : : : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: : : : :
: : : : : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : : : : http://www.programmersheaven.com/search/Download.asp?FileID=923
: : : : :
: : : : : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: : : : :
: : : : : int image[100][100]
: : : : : 

: : : : : But, remember that you can also store image in memory.
: : : : :
: : : : : Or, you could just load the file directly onto the screen.
: : : : :
: : : : : Hope this lil info helps you out.
: : : : : ****************
: : : : : Any questions? Just ask!
: : : : :
: : : : : GAASHIUS
: : : : :
: : : : :
: : : : :
: : : : i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
: : : :
: : :
: : : Just loop it. Example..
: : : const int iWidth = 100, //image width/height
: : :           iHeight = 100;
: : : 
: : : char* image;      // your loaded image
: : : 
: : : int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: : : 
: : : 
: : : // copy the image
: : : for ( int y = 0; y< iHeight; y++)
: : :    for ( int x=0; x<iWidth; x++)
: : :      pixels [y][x] = image [x+y*iWidth];

: : :
: : : The formula x+y*iWidth can be used to retrieve an element
: : : (in this case, pixel) at an x/y location in linear memory.
: : :
: : : This will only work if "image" and "pixels" are
: : : the same bit depth. If they are not, you will need to
: : : convert it.
: : :
: : : Hope this helps!
: : : ~mt2002

: : :
: : :
: : :
: : i have this code for comaparing two images to see if they are 100% match with each other.
: :
: : #include<stdio.h>
: : #include<math.h>
: : 
: : /* definition of both bitmaps height and width */
: : #define BITMAPX 352
: : #define BITMAPY 292
: : 
: : /* structure to contain data for one pixel */
: : typedef struct {
: : float r,g,b; /* color data varies for each color from 0-255 */
: : }RGB; /* they are floats just for convinience */
: : 
: : /* two 352x292x24 bit bitmaps containing about to be compared images */
: : RGB bitmap1[BITMAPX][BITMAPY],bitmap2[BITMAPX][BITMAPY];
: : 
: : 
: : /* variables to hold number of pixels, current pixel and match so far */
: : /* and match for current pixel */
: : float pixels=BITMAPX*BITMAPY,current_pixel=0;
: : float match=0,currentmatch=0;
: : 
: : 
: : main()
: : {
: : 
: : /* now we start looping through all pixels in our bitmaps comparing */
: : /* according pixels to each other */
: : int posx, posy, currentpixel;
: : for(posx=0;posx<BITMAPX;posx++){
: : 	for(posy=0;posy<BITMAPY;posy++){
: : 		currentpixel++;
: : 
: : 		/* this is where actual comparison takes place */
: : 		/* given that all three basic colors are on different axis */
: : 		/* match between them can be calculated using */
: : 		/* vector length equation */
: : 		currentmatch=sqrt(pow(bitmap1[posx][posy].r-bitmap2[posx][posy].r,2)+pow(bitmap1[posx][posy].g-bitmap2[posx][posy].g,2)+pow(bitmap1[posx][posy].b-bitmap2[posx][posy].b,2));
: : 
: : 		match=((match*currentpixel)+currentmatch)/(currentpixel);
: : 		}
: : 	}
: : 
: : match=100-match/2.56;
: : 
: : printf("%f",match);
: : }
: : 

: :
: : but i cant seem to load the image properly to the two dimensional arrays that I declared. how can I for example load an image named "try.bmp" to bitmap1 and "try1.bmp" to bitmap2. thanks!
: :
:
: Do you have a bitmap loader? If so, load the bitmap to heap
: memory, and copy it to the array (as I posted).
:
: If you dont have a loader, making one is easy. The Win32 API
: makes it even easier. Im assuming you dont have a loader
: (according to your code). If so, check out
: http://www.gamedev.net/reference/articles/article1966.asp
:
: Hope this helps!
: ~mt2002

:

btw is there any conflict if i'm going to use this program on a linux platform because im using bmp images. would you recommend using a different image format then?
Report
Re: beginner on image procesing Posted by MT2002 on 8 Feb 2006 at 6:44 PM
: : : : This message was edited by MT2002 at 2006-2-3 18:32:15

: : : : : : : hi
: : : : : : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : : : : : :
: : : : : : : thanks
: : : : : : :
: : : : : : : cacaramba
: : : : : : :
: : : : : : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : : : : : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: : : : : :
: : : : : : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : : : : : http://www.programmersheaven.com/search/Download.asp?FileID=923
: : : : : :
: : : : : : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: : : : : :
: : : : : : int image[100][100]
: : : : : : 

: : : : : : But, remember that you can also store image in memory.
: : : : : :
: : : : : : Or, you could just load the file directly onto the screen.
: : : : : :
: : : : : : Hope this lil info helps you out.
: : : : : : ****************
: : : : : : Any questions? Just ask!
: : : : : :
: : : : : : GAASHIUS
: : : : : :
: : : : : :
: : : : : :
: : : : : i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
: : : : :
: : : :
: : : : Just loop it. Example..
: : : : const int iWidth = 100, //image width/height
: : : :           iHeight = 100;
: : : : 
: : : : char* image;      // your loaded image
: : : : 
: : : : int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: : : : 
: : : : 
: : : : // copy the image
: : : : for ( int y = 0; y< iHeight; y++)
: : : :    for ( int x=0; x<iWidth; x++)
: : : :      pixels [y][x] = image [x+y*iWidth];

: : : :
: : : : The formula x+y*iWidth can be used to retrieve an element
: : : : (in this case, pixel) at an x/y location in linear memory.
: : : :
: : : : This will only work if "image" and "pixels" are
: : : : the same bit depth. If they are not, you will need to
: : : : convert it.
: : : :
: : : : Hope this helps!
: : : : ~mt2002

: : : :
: : : :
: : : :
: : : i have this code for comaparing two images to see if they are 100% match with each other.
: : :
: : : #include<stdio.h>
: : : #include<math.h>
: : : 
: : : /* definition of both bitmaps height and width */
: : : #define BITMAPX 352
: : : #define BITMAPY 292
: : : 
: : : /* structure to contain data for one pixel */
: : : typedef struct {
: : : float r,g,b; /* color data varies for each color from 0-255 */
: : : }RGB; /* they are floats just for convinience */
: : : 
: : : /* two 352x292x24 bit bitmaps containing about to be compared images */
: : : RGB bitmap1[BITMAPX][BITMAPY],bitmap2[BITMAPX][BITMAPY];
: : : 
: : : 
: : : /* variables to hold number of pixels, current pixel and match so far */
: : : /* and match for current pixel */
: : : float pixels=BITMAPX*BITMAPY,current_pixel=0;
: : : float match=0,currentmatch=0;
: : : 
: : : 
: : : main()
: : : {
: : : 
: : : /* now we start looping through all pixels in our bitmaps comparing */
: : : /* according pixels to each other */
: : : int posx, posy, currentpixel;
: : : for(posx=0;posx<BITMAPX;posx++){
: : : 	for(posy=0;posy<BITMAPY;posy++){
: : : 		currentpixel++;
: : : 
: : : 		/* this is where actual comparison takes place */
: : : 		/* given that all three basic colors are on different axis */
: : : 		/* match between them can be calculated using */
: : : 		/* vector length equation */
: : : 		currentmatch=sqrt(pow(bitmap1[posx][posy].r-bitmap2[posx][posy].r,2)+pow(bitmap1[posx][posy].g-bitmap2[posx][posy].g,2)+pow(bitmap1[posx][posy].b-bitmap2[posx][posy].b,2));
: : : 
: : : 		match=((match*currentpixel)+currentmatch)/(currentpixel);
: : : 		}
: : : 	}
: : : 
: : : match=100-match/2.56;
: : : 
: : : printf("%f",match);
: : : }
: : : 

: : :
: : : but i cant seem to load the image properly to the two dimensional arrays that I declared. how can I for example load an image named "try.bmp" to bitmap1 and "try1.bmp" to bitmap2. thanks!
: : :
: :
: : Do you have a bitmap loader? If so, load the bitmap to heap
: : memory, and copy it to the array (as I posted).
: :
: : If you dont have a loader, making one is easy. The Win32 API
: : makes it even easier. Im assuming you dont have a loader
: : (according to your code). If so, check out
: : http://www.gamedev.net/reference/articles/article1966.asp
: :
: : Hope this helps!
: : ~mt2002

: :
:
: btw is there any conflict if i'm going to use this program on a linux platform because im using bmp images. would you recommend using a different image format then?
:

I dont know, but it shouldnt cause any conflict..As long as you
write your loader from scratch (ie; dont use Win32) it should
still be okay.

Report
Re: beginner on image procesing Posted by IDK on 24 Mar 2006 at 1:30 PM
: const int iWidth = 100, //image width/height
:           iHeight = 100;
: 
: char* image;      // your loaded image
: 
: int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: 
: 
: // copy the image
: for ( int y = 0; y< iHeight; y++)
:    for ( int x=0; x<iWidth; x++)
:      pixels [y][x] = image [x+y*iWidth];

:
: The formula x+y*iWidth can be used to retrieve an element
: (in this case, pixel) at an x/y location in linear memory.
:
: This will only work if "image" and "pixels" are
: the same bit depth. If they are not, you will need to
: convert it.
:
: Hope this helps!
: ~mt2002

:
:
Won't it be possible to do something like this:

const int iWidth = 100, //image width/height
          iHeight = 100;

char* image;      // your loaded image

char pixels[iHeight][iWidth];

pixel = image;

Another way would be to copy the whole array. Then you get chars instead if ints, but does that matter?

Happy coding wishes
the one and only
Niklas Ulvinge aka IDK




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.