Help Wanted

picture i/o in c++? – spade89

spade89

Member

Posts: 561
From: houston,tx
Registered: 11-28-2006
Hi i i am working on a c++ project that converts picture files to NFO'S (ascii art) but i don't know how to read and write from picture files such as bmp's jpg's and gif's so if you know any picture i/o i'd appreciate it if u show me sokmkkek source code.

-----------------------------------------------

"The power to question is the basis of all human progress"-gandhi.

------------------
a real programmer can write assembly code in any language

fearless

Member

Posts: 91
From: Romania, Tg Mures
Registered: 11-26-2005
The method I'll point might be an overkill but that's the only one I'm familiar with.


rslt=D3DXCreateTextureFromResourceEx(pDevice, GetModuleHandle( NULL ), MAKEINTRESOURCE(IDB_ISLAND), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &m_pTextureHeightmap);

D3DLOCKED_RECT lockedrect;
::ZeroMemory(&lockedrect, sizeof(lockedrect));

rslt=m_pTextureHeightmap->LockRect(0, &lockedrect, NULL, 0);
if(FAILED(rslt)) { return D3DError(rslt, __LINE__, __FILE__, "Could not lock heightmap surface"); }

DWORD* pBits=(DWORD*)lockedrect.pBits;
int index=0;

// Display offset (bytes)=((Pitch * y) + x) * Num Bytes per pixel
{
for(int y=0; y<256;y+=2)
{
for(int x=0; x<256; x+=2)
{
m_nHeightArray[y][x]=(getr(pBits[(y*256)+x]))/5;
}
}
}

This is a method used in building Terrain from a height map (grayscale bmp)
Every tutorial dealing with Terrain construction from heghtmaps has a method similar to this.

If you're interested in this method here is some sites for you:

http://www.32bits.co.uk/ (directx 8 tutorilas)

http://www.c-unit.com

http://www.lighthouse3d.com/opengl/terrain/

------------------

My projects page:
http://calinnegru.googlepages.com/projects

'As there are plants which will flourish only in mountain soil, so it appears that Mercy will flower only when it grows in the crannies of the rock of Justice; transplanted to the marshlands of mere Humanitarianism, it becomes a man-eating weed, all the more dangerous because it is still called by the same name as the mountain variety.'
The Humanitarian Theory of Punishment
by C. S. Lewis

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
check out the 'Wotsit' website:
http://www.wotsit.org/

more specifically...
http://www.wotsit.org/search.asp?s=graphics

It's pretty much the same as reading and writing to a binary file really. You just need to know how the data is stored. BMP file is a lot 'nicer' to read from, however if you can, .raw files are even easier (raw colour byte information). JPG might be a bit harder as it is compressed, same with GIF.

I would recommend converting the BMP, JPG and GIF to raw colour byte format (your own data structure), and then just process that structure to calculate the ASCII graphics. That way, you can easily add in new file formats without any change to the core system.

Your structure can be as detailed as you'd like. The core stuff you'll need are:

width // of image
height // of image
data // an array which holds all the colour information (could be an array of a 'colour' structure if you want, or just X bytes between each new colour)

Hope that helps.

------------------
www.auran.com

spade89

Member

Posts: 561
From: houston,tx
Registered: 11-28-2006
thanks a lot that link is really helpful,i know i have been trying to find out i/o routines for lots of files and i couldn't find any.
i am currently trying out the whole bmp i/o thing. and it is much easier than i thought it would be. ^__^

------------------
a real programmer can write assembly code in any language