nesdev.com
http://forums.nesdev.com/

PPU Palette
http://forums.nesdev.com/viewtopic.php?f=3&t=16448
Page 1 of 1

Author:  Anes [ Sun Sep 03, 2017 10:43 pm ]
Post subject:  PPU Palette

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.

Author:  lidnariq [ Sun Sep 03, 2017 11:03 pm ]
Post subject:  Re: PPU Palette

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.

Author:  Anes [ Sun Sep 03, 2017 11:06 pm ]
Post subject:  Re: PPU Palette

Christ!! how do i do that??

Do you have some code??

Author:  lidnariq [ Sun Sep 03, 2017 11:17 pm ]
Post subject:  Re: PPU Palette

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

Author:  Anes [ Sun Sep 03, 2017 11:43 pm ]
Post subject:  Re: PPU Palette

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

Author:  lidnariq [ Mon Sep 04, 2017 12:46 am ]
Post subject:  Re: PPU Palette

Looks good enough.

Author:  Anes [ Mon Sep 04, 2017 1:31 am ]
Post subject:  Re: PPU Palette

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.

Author:  lidnariq [ Mon Sep 04, 2017 9:31 am ]
Post subject:  Re: PPU Palette

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.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/