• Advertisement

Archived

This topic is now archived and is closed to further replies.

Pixel Operaions In DDraw

This topic is 5936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It seems like that everytime I play with pixels I get burned. It seems this code doesn''t work and it''s really starting to drive me batty.. Someone PLEASE at least look at this code.
  
	// Lock

	m_lpDDSBitmaps[dwTextureId]->Lock( NULL, &m_lpDDSDesc[dwTextureId], DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);

	// Multiply!

	if (g_MainWindow.m_nBpp == 16)
	{
		// Copy Buffer

		USHORT* wBuffer;
		wBuffer = (USHORT*)m_lpDDSDesc[dwTextureId].lpSurface;

		for (UINT i = 0; i < (m_lpDDSDesc[dwTextureId].dwWidth * m_lpDDSDesc[dwTextureId].dwHeight); i++)
		{
			wBuffer[i] = wBuffer[i] * dwNumber;
		}
	

	}
	else
	{
		// Copy Buffer

		ULONG* dwBuffer;
		dwBuffer = (ULONG*)m_lpDDSDesc[dwTextureId].lpSurface;

		for (UINT i = 0; i < (m_lpDDSDesc[dwTextureId].dwWidth * m_lpDDSDesc[dwTextureId].dwHeight); i++)
		{
			dwBuffer[i] = dwBuffer[i] * dwNumber;
		}
	
	}

	// Unlock

	m_lpDDSBitmaps[dwTextureId]->Unlock(m_lpDDSDesc[dwTextureId].lpSurface);
  
I can''t see what I did wrong. dwNumber is a valid pixel color no matter what the BPP. All it''s suppose to do is color non-black pixels.. but it doesn''t! It just colors gray pixels. Thx for the help ------------------------------------------------------------ I wrote the best video game ever, then I woke up... Grandus.Com

Share this post


Link to post
Share on other sites
Advertisement
2 issues. First of all, exactly what effect are you trying to achieve? Since pixels are stored in something like ARGB, multiplying the whole pixel by a constant can cause the bits of one color to "spill" over into the bits of another color. For example, assume format A1R5G5B5 with color bits 0 00000 10000 00001. This should be alpha 0, red 0, green 32, blue 1, which is a bright green. If you multiply the color by 2 you get: 0 0001 0000 0010, which is sort of a dark purple. If you want to add to a color to brighten you need to isolate the individual color channels in the pixel and add to each one individually.

Second, the pitch of a locked surface is not necessarily its width (although it certainly can be). That is that successive horizontal lines are not necessarily in consecutive memory locations because of memory alignment issues. You should advance your pointer by the pitch of the surface (in bytes) after each line. Your code may work on your machine, but it might break on someone else''s.

Share this post


Link to post
Share on other sites
I have a grayscale image I want ot paint shades of whatever color I tell it.

Well, come to think of it.. Your so right about the pitch I should kick myself!

Share this post


Link to post
Share on other sites

  • Advertisement