Jump to content
  • Advertisement

Archived

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

Muzlack

Color Modulation

This topic is 5890 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

here is some color modulation code... What is wrong with it? In an example, it turns out a bunch of purple and blue lines.
  
memset(&ddsd,0,sizeof(ddsd));
		ddsd.dwSize=sizeof(ddsd);
	
		pSrcTexture.texture->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);

		unsigned short* data = (unsigned short*) ddsd.lpSurface;
		for(int y1=0; y1<ddsd.dwHeight; y1++ ) {
			for(int x1=0; x1<ddsd.dwWidth; x1++) {
				
				unsigned short color=data[y1*ddsd.lPitch+x1];
				short r1 = color & 0xF800 >> 11;
				short g1 = color & 0x07E0 >> 5;
				short b1 = color  & 0x001F;

				short r2=(r*r1)/255;
				short b2=(b*b1)/255;
				short g2=(g*g1)/255;
				
				
				data[y1*ddsd.dwWidth+x1]=RGB16(r2,b2,g2);
				
				
			}
		}

		pSrcTexture.texture->Unlock(NULL);
  

Share this post


Link to post
Share on other sites
Advertisement
I''ll assume you''re using 16 bit color in DirectX.
I believe one problem is how memory is being addressed with two parts of this code.

unsigned short color=data[y1*ddsd.lPitch+x1]; // Here
short r1 = color & 0xF800 >> 11;
short g1 = color & 0x07E0 >> 5;
short b1 = color & 0x001F;
short r2=(r*r1)/255;
short b2=(b*b1)/255;
short g2=(g*g1)/255;
data[y1*ddsd.dwWidth+x1]=RGB16(r2,b2,g2); // And Here

Because a surface sometimes is formated wider than its width you need to use its pitch to address pixels in it.

Note: Since the pitch is returned in bytes you will have to divide it by the number of bytes per pixel to use for addressing pixels, example - divide by 2 for 16 bit color because there are 2 bytes per pixel

You should have something like this:

color=data[y1*(ddsd.lPitch>>1)+x1];

data[y1*(ddsd.lPitch>>1)+x1]=RGB16(r2,b2,g2);

Hope this helps!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!