weizhenye / ass-compiler

Parses and compiles ASS subtitle format to easy-to-use data structure
https://ass.js.org/ass-compiler/
MIT License
107 stars 18 forks source link

Long integer colors #2

Closed majg0 closed 5 years ago

majg0 commented 5 years ago

Greetings!

First of all, thank you for your ASS libraries!

I have found a minor error; Colors should, according to spec, be able to be specified as long integers (I'm guessing long here means "at least 32-bit", like in C).

Spec states:

A long integer BGR (blue-green-red) value. ie. the byte order in the hexadecimal equivelent of this number is BBGGRR

...

The color format contains the alpha channel, too. (AABBGGRR)

The integer should be considered a signed integer, as seen in the test file:

[Script Info]
; Comment 1
; Comment 2
Title: SSA test
Original Script: asticode
Script Updated By: version 2.8.01
ScriptType: v4.00
Collisions: Normal
PlayResY: 600
PlayDepth: 0
Timer: 100,0000

[Unknown]
Unknown

[V4 Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: 1,f1,20,65535,65535,65535,-2147483640,-1,0,7,1,4,7,1,4,7,0.1,0
Style: 2,f2,20,15724527,65535,65535,986895,-1,0,8,2,5,8,2,5,8,0.2,1
Style: 3,f3,20,&H00B4FCFC,&H00B4FCFC,&H00000008,&H00000008,0,0,9,3,6,9,3,6,9,0.3,2

[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: Marked=0,0:00:01.00,0:00:01.99,1,Cher,0000,0000,0000,test,{\pos(400,570)}(deep rumbling)
Dialogue: Marked=1,0:00:02.00,0:00:03.04,1,Cher,0000,0000,0000,test,{\pos(400,570)}(deep rumbling)
Dialogue: Marked=1,0:00:03.16,0:00:04.20,3,autre,0000,0000,0000,,This place is horrible.
Dialogue: Marked=1,0:00:04.24,0:00:05.28,1,autre,0000,0000,0000,,Smells like balls.
Dialogue: Marked=1,0:00:05.32,0:00:06.36,2,autre,0000,0000,0000,,We don't belong\nin this shithole.
Dialogue: Marked=1,0:00:06.40,0:00:07.44,3,autre,0000,0000,0000,,(computer playing\nelectronic melody)

You can see the error using your fantastic online viewer 👍

majg0 commented 5 years ago

I wrote this function which may help you;

function getColorComponents(x) {
  let y = x
  const RR = y & 0xFF
  y >>= 8
  const GG = y & 0xFF
  y >>= 8
  const BB = y & 0xFF
  y >>= 8
  const AA = ((x << 8) - 1) & 0xFF
  return [RR, GG, BB, AA || 255]
}
majg0 commented 5 years ago

You can .map(x => ('0' + x.toString(16).toUpperCase()).slice(-2)).join('')

$ getColorComponents(-2147483640)
  .map(x => ('0' + x.toString(16).toUpperCase()).slice(-2))
  .join('')
> "080000FF"
weizhenye commented 5 years ago

@martingronlund Thanks for your report and codes, but after testing several edge cases in Aegisub with libass renderer, I found it's not an intuitive thing. You can check ce8d33d for details.

weizhenye commented 5 years ago

@martingronlund BTW, currently ass-compiler doesn't support SSA format, I'll support it someday.

majg0 commented 5 years ago

@weizhenye wow, great job with the extensive suite. Thank you very much for your diligence.

I'm closing this issue. Ofc, feel free to reopen if you disagree.