It is currently Sat Dec 16, 2017 9:59 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: PPU Palette
PostPosted: Sun Sep 03, 2017 10:43 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Im giving a try to Blargg's "nes_ntsc.c" to have a correct pal in my emu.

First i can get image. What i do is to have a buffer of
Code:
 unsigned char nes_frame[256 * 240]
.
My "multiplexer" put NES pixels there and i create an D3D9 offscreen surface of
Code:
g_d3d_hr = d3ddev->CreateOffscreenPlainSurface(NES_NTSC_OUT_WIDTH(256), 240, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &d3d_screen, 0);

Now NES_NTSC_OUT_WIDTH(256) gives me a value grater than 256. Then when it my emu finish putting pixels i call:
Code:
nes_ntsc_blit(ntsc_ntsc, nes_frame, ntsc_image.row_width, 0, NES_NTSC_OUT_WIDTH(ntsc_image.width),
      ntsc_image.height, g_screen_data, d3d_lock_rect.Pitch);

Width = 256, Height = 240.

Anyway to mantain PAR should i stretchblt() to a 292 x 240 surface and apply a Scale2x to make the image better?

The second big question is: how do you do to implement pal emu in your emus? With the above approach my emu doesn't pass full_palette.nes.

And the third is. I remember that someone throws me a link were it was well explain Scale2x algorithm. I have to re-make it and what it says on the net doesn't help too much.

Thxs.

_________________
ANes


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Sun Sep 03, 2017 11:03 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6534
Location: Seattle
Anes wrote:
The second big question is: how do you do to implement pal emu in your emus? With the above approach my emu doesn't pass full_palette.nes.
Super lazy, and not too inaccurate:
Take output of nes_ntsc, decompose into YCbCr, average the Cb and Cr components of each scanline with the one above it, convert back to RGB.


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Sun Sep 03, 2017 11:06 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Christ!! how do i do that??

Do you have some code??

_________________
ANes


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Sun Sep 03, 2017 11:17 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6534
Location: Seattle
Something roughly like
  • make a copy of the pixel buffer
  • in the copy, for all the pixels
  • in the copy, from the buttom scanline and going up (reverse order removes need to make another copy)
    • add the U and V components from the pixel one scanline above, and divide that result by two
  • in the copy, for all the pixels
    • convert each YUV tuple to RGB
  • display the copy


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Sun Sep 03, 2017 11:43 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Code:
convert each RGB tuple to YUV


Is it well to apply this?

Code:
Y = ( (  66 * R + 129 * G +  25 * B + 128) >> 8) +  16
U = ( ( -38 * R -  74 * G + 112 * B + 128) >> 8) + 128
V = ( ( 112 * R -  94 * G -  18 * B + 128) >> 8) + 128

_________________
ANes


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Mon Sep 04, 2017 12:46 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6534
Location: Seattle
Looks good enough.


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Mon Sep 04, 2017 1:31 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
YUV it's a new world for me.
Do i have to pack those values to a 16 bit value? Where Y,V and U goes? I mean what is the standard format in memory layout for YUV??
I know there are many YUV formats, but i ask this becouse i'm new to this.

_________________
ANes


Top
 Profile  
 
 Post subject: Re: PPU Palette
PostPosted: Mon Sep 04, 2017 9:31 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6534
Location: Seattle
If your output method can be easily switched between RGB and YUV, you should be able to look up what memory layout it expects for a YUV444 texture.

Otherwise ... you can do whatever.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: fred and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group