Log in

View Full Version : MuxMan 0.13pc, Color Palette


gm901
26th March 2005, 10:13
Hi,

One question concerning the SubPictures palette

My original IFO is
PGC 1
Color 0 Y Cr Cb: 10 80 80 108080
Color 1 Y Cr Cb: 2B 80 80 2b8080
Color 2 Y Cr Cb: EB 80 80 eb8080
Color 3 Y Cr Cb: 10 80 80 108080
Color 4 Y Cr Cb: 7D 80 80 7d8080
Color 5 Y Cr Cb: B4 80 80 b48080
Color 6 Y Cr Cb: A9 10 A5 a910a5
Color 7 Y Cr Cb: 6A DD CA 6addca
Color 8 Y Cr Cb: EB 80 80 eb8080
Color 9 Y Cr Cb: 1C 76 B8 1c76b8
Color 10 Y Cr Cb: 50 50 5A 50505a
Color 11 Y Cr Cb: 30 B8 6D 30b86d
Color 12 Y Cr Cb: 5D 47 92 5d4792
Color 13 Y Cr Cb: 3D AF A5 3dafa5
Color 14 Y Cr Cb: 71 89 47 718947
Color 15 Y Cr Cb: EB 80 80 eb8080

Color 0=16, 128, 128
Color 1=43, 128, 128
Color 2=235, 128, 128
Color 3=16, 128, 128
Color 4=125, 128, 128
Color 5=180, 128, 128
Color 6=169, 16, 165
Color 7=106, 221, 202
Color 8=235, 128, 128
Color 9=28, 118, 184
Color 10=80, 80, 90
Color 11=48, 184, 109
Color 12=93, 71, 146
Color 13=61, 175, 165
Color 14=113, 137, 71
Color 15=235, 128, 128

Passing these values to MuxMan 0.13pc, the multiplexed output becomes

Color 0 Y Cr Cb: 61 4F 90 614f90
Color 1 Y Cr Cb: 68 5B 8C 685b8c
Color 2 Y Cr Cb: 99 AE 71 99ae71
Color 3 Y Cr Cb: 61 4F 90 614f90
Color 4 Y Cr Cb: 7D 7F 80 7d7f80
Color 5 Y Cr Cb: 8B 96 79 8b9679
Color 6 Y Cr Cb: 53 B8 AA 53b8aa
Color 7 Y Cr Cb: AE 4F 88 ae4f88
Color 8 Y Cr Cb: 99 AE 71 99ae71
Color 9 Y Cr Cb: 64 54 AA 6454aa
Color 10 Y Cr Cb: 55 80 84 558084
Color 11 Y Cr Cb: 83 4A 74 834a74
Color 12 Y Cr Cb: 59 84 9D 59849d
Color 13 Y Cr Cb: 88 4F 8C 884f8c
Color 14 Y Cr Cb: 79 7B 67 797b67
Color 15 Y Cr Cb: 99 AE 71 99ae71


Color 0=97, 79, 144
Color 1=104, 91, 140
Color 2=153, 174, 113
Color 3=97, 79, 144
Color 4=125, 127, 128
Color 5=139, 150, 121
Color 6=83, 184, 170
Color 7=174, 79, 136
Color 8=153, 174, 113
Color 9=100, 84, 170
Color 10=85, 128, 132
Color 11=131, 74, 116
Color 12=89, 132, 157
Color 13=136, 79, 140
Color 14=121, 123, 103
Color 15=153, 174, 113

Is it something that I haven’t taken into account?

Thanks

mpucoder
26th March 2005, 16:24
Color values in mxp or scp files are RGB values, while the values stored in the ifo are YCbCr. Most sub rippers will give you the values you need. The reason RGB is used is that you can set any of the components to any value between 0 and 255 without creating out-of-range values. The same is not true for YCbCr, about half the values are outside the acceptable range.

gm901
26th March 2005, 21:04
Well…
Thought that would be easy :)to find the formula to convert between YcbCr to RGB (cause I’m trying to make the whole process more automated).

But that’s not the case.:(
Found lots of formulas. Some look different, others look almost the same, but some coefficient(s) is slightly different etc.
An example
B = 1.164 Y + 2.017 Cb + 0.0 Cr, :rolleyes:
B = 1.164(Y - 16) + 2.018(Cr - 128) :eek:
B = Y + ROUND(1.77200*Cb) :confused:
B = Y + 1.772 (Cb-128) :mad:
And then take care of the 0-255 limits …:angry:

So, since the web does not agree, I presume the only foolproof formula is to read the YcbCr values of the original and write them to MuxMan’s output IFO, leaving alone the Color Palette settings. :devil:

mpucoder
26th March 2005, 21:44
Y = (Y-16) * 255 / 219;
red = round(Y + (Cr-128)*1.596);
red = min(max(red,0),255);
green = round(Y - (Cb-128) * 0.391 - (Cr-128)*0.813);
green = min(max(green,0),255);
blue = round(Y + (Cb-128) * 2.018);
blue = min(max(blue,0),255);

gm901
26th March 2005, 21:53
Thanks :D

D3s7
27th March 2005, 00:22
These are the values that are used in ScenAid which yeilds a YUV value that's w/ in 1 or 2


r = Round(1.164 * (y - 16) + 1.596 * (U - 128), 0)
G = Round(1.164 * (y - 16) - 0.813 * (U - 128) - 0.391 * (V - 128), 0)
B = Round(1.164 * (y - 16) + 2.018 * (V - 128), 0)

manusse
5th November 2006, 20:53
Hi everybody,

I am reactivating this thread because I have a question that is exactly related to this problem.

I am currently adding the VobSub (sub/idx) subtitles'support to SubtitleCreator. I have quite finished the job and am currently looking at some small remaining issues before we can release it.

In the idx files, there is some room for the palette of the DVD. This palette is retrieved by VsRip from the IFO file (YCrCb values) of the DVD. As I want to read the YCrCb values from the IFO to write a correct idx file, which uses RGB values for the palette I have to use some formulas to convert YUV to RGB.

I had a look at VobSub sources and found that the formulas used are the following:

VobSubFile.cpp
BYTE y, u, v, tmp;

f.Read(&tmp, 1);
f.Read(&y, 1);
f.Read(&u, 1);
f.Read(&v, 1);

y = (y-16)*255/219;

m_orgpal[i].rgbRed = (BYTE)min(max(1.0*y + 1.4022*(u-128), 0), 255);
m_orgpal[i].rgbGreen = (BYTE)min(max(1.0*y - 0.3456*(u-128) - 0.7145*(v-128), 0), 255);
m_orgpal[i].rgbBlue = (BYTE)min(max(1.0*y + 1.7710*(v-128), 0) , 255);

Y = (Y-16)*255/219;

R = Y + 1.4022 (U-128)
G = Y – 0.3456 (U-128) – 0.7145 (V-128)
B = Y + 1.7710 (V-128)

These equations use exactly the same coefficients as the JPEG equations (http://www.fourcc.org/fccyvrgb.php)except that on the G equation used in JPEG, U and V are inverted compared to the equation above. Also those equations are not the same as the one given by mpucoder and D3s7.

I was wondering if somebody had explanations about that (Gabest, mpucoder, some others?). I mean where do those equations come from and which ones are the ones to use, VobSub's or mpucoder's ones?

Thanks in advance for your help.
Cheers

Manusse
:thanks:

manusse
10th November 2006, 22:43
Hi,

As nobody is giving advice, let me explain what I've currently decided for the sub/idx import/export function of SubtitleCreator.
SubtitleCreator uses internally mpucoder's equation to analyze the YUV IFO palette (ie when loading an IFO file) and stores it in RGB.
When importing a sub/idx file, it will first read the RGB palette from the idx file, then convert the read palette from RGB to YUV using VobSub's reverse equation:

Y = 0.1283 R + 0.5205 G + 0.21 B
Cb = - 0,0843 R - 0,3422 G + 0,4266 B
Cr = 0,6066 R - 0,4322 G - 0,1744 B

Then convert it again to RGB using mpucoder's equations.

When writing an idx file, SubtitleCreator will use VobSub's equation to be coherent with it (First convert its internal palette values back to YUV and then convert them to RGB using VobSubFile.cpp's formulas).
Any remarks or advice are welcome.

Cheers
Manusse

Zeul
11th November 2006, 08:26
In DVDPlanner i use the following to convert from RGB to YUV when writing out the IFOs.

n(0) = (257 * r + 504 * g + 98 * b + 16500) / 1000 'Y
n(1) = (439 * r - 368 * g - 71 * b + 128500) / 1000 'Cr
n(2) = (-148 * r - 291 * g + 439 * b + 128500) / 1000 'Cb
If n(0) < 16 Then n(0) = 16
If n(0) > 235 Then n(0) = 235

manusse
11th November 2006, 11:28
Thanks for your answer Zeul,

These are the reverse equations from those given by mpucoder. They are the ones SC will use when it will first convert its internal palette values back to YUV before using VobSub's formulas to write the idx file.

Cheers
Manusse