Fixed color transform animations

This commit is contained in:
DataHoarder 2021-12-30 02:09:52 +01:00
parent f10edc70c8
commit 5909f4790e
11 changed files with 28 additions and 24 deletions

View file

@ -30,19 +30,19 @@ class StyleList {
} else if ($node->nodeName === "ClippedBitmap") {
Utils::dump_element($node);
//TODO
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 255 / 2));
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 200));
} else if ($node->nodeName === "ClippedBitmap2") {
Utils::dump_element($node);
//TODO
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 255 / 2));
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 200));
} else if ($node->nodeName === "TiledBitmap") {
//TODO
Utils::dump_element($node);
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 255 / 2));
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 200));
} else if ($node->nodeName === "TiledBitmap2") {
//TODO
Utils::dump_element($node);
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 255 / 2));
$fillStyles[] = new FillStyleRecord(new Color(0, 0, 0, 200));
} else {
Utils::dump_element($node);
throw new \Exception("Unknown style " . $node->nodeName);

View file

@ -19,7 +19,7 @@ class blurEdgesGaussianTag implements ASSStyleTag {
}
public function encode(ASSLine $line, float $frameDurationMs): string {
return "\\blur{$this->strength}";
return "\\blur" . round($this->strength, 4);
}
public static function fromStyleRecord(StyleRecord $record): ?blurEdgesGaussianTag {

View file

@ -20,7 +20,7 @@ class borderTag implements ASSStyleTag {
}
public function encode(ASSLine $line, float $frameDurationMs): string {
return "\\bord{$this->size}";
return "\\bord" . round($this->size, 2);
}
public static function fromStyleRecord(StyleRecord $record): ?borderTag {

View file

@ -4,17 +4,16 @@ namespace swf2ass\ass;
use swf2ass\Color;
use swf2ass\ColorTransform;
use swf2ass\FillStyleRecord;
use swf2ass\Gradient;
use swf2ass\StyleRecord;
use swf2ass\Utils;
abstract class colorTag implements ASSStyleTag, ASSColorTag {
protected Color $color;
protected Color $originalColor;
public function __construct(Color $color) {
public function __construct(Color $color, Color $originalColor) {
$this->color = $color;
$this->originalColor = $originalColor;
}
public static abstract function fromStyleRecord(StyleRecord $record): ?colorTag;
@ -27,7 +26,11 @@ abstract class colorTag implements ASSStyleTag, ASSColorTag {
return $tag instanceof $this and $this->color->equals($tag->color);
}
public function applyColorTransform(?ColorTransform $transform): ?colorTag {
return $transform !== null ? new $this($transform->applyToColor($this->originalColor), $this->originalColor) : $this;
}
public function transitionColor(ASSLine $line, ColorTransform $transform): ?colorTag {
return new $this($transform->applyToColor($this->color));
return $this->applyColorTransform($transform);
}
}

View file

@ -101,11 +101,12 @@ class containerTag implements ASSColorTag, ASSPositioningTag, ASSStyleTag {
public static function fromPathEntry(DrawPath $path, ?Shape $clip, ?ColorTransform $colorTransform, ?MatrixTransform $matrixTransform): containerTag {
$container = new containerTag();
$style = $colorTransform !== null ? $colorTransform->applyToStyleRecord($path->style) : $path->style;
$container->try_append(borderTag::fromStyleRecord($style));
$container->try_append(shadowTag::fromStyleRecord($style));
$container->try_append(lineColorTag::fromStyleRecord($style));
$container->try_append(fillColorTag::fromStyleRecord($style));
$container->try_append(borderTag::fromStyleRecord($path->style));
$container->try_append(shadowTag::fromStyleRecord($path->style));
$container->try_append(lineColorTag::fromStyleRecord($path->style)->applyColorTransform($colorTransform));
$container->try_append(fillColorTag::fromStyleRecord($path->style)->applyColorTransform($colorTransform));
$matrixTransform = $matrixTransform ?? MatrixTransform::identity();
$container->try_append(positionTag::fromMatrixTransform($matrixTransform));

View file

@ -20,9 +20,9 @@ class fillColorTag extends colorTag {
} else {
throw new \Exception("Invalid Fill record");
}
return new fillColorTag($color);
return new fillColorTag($color, $color);
}
return new fillColorTag(new Color(0, 0, 0, 255));
return new fillColorTag(new Color(0, 0, 0, 255), new Color(0, 0, 0, 255));
}
public function encode(ASSLine $line, float $frameDurationMs): string {

View file

@ -10,9 +10,9 @@ use swf2ass\Utils;
class lineColorTag extends colorTag {
public static function fromStyleRecord(StyleRecord $record): ?lineColorTag {
if ($record instanceof LineStyleRecord) {
return new lineColorTag($record->color);
return new lineColorTag($record->color, $record->color);
}
return new lineColorTag(new Color(0, 0, 0, 255));
return new lineColorTag(new Color(0, 0, 0, 255), new Color(0, 0, 0, 255));
}
public function encode(ASSLine $line, float $frameDurationMs): string {

View file

@ -46,7 +46,7 @@ class positionTag implements ASSPositioningTag {
public function encode(ASSLine $line, float $frameDurationMs): string {
//TODO: Maybe time 0,round($line->end * $frameDurationMs)
return ($this->to !== null and ($line->end - $line->start) > 0) ? "\\move({$this->from->x},{$this->from->y},{$this->to->x},{$this->to->y})" : "\\pos({$this->from->x},{$this->from->y})";
return ($this->to !== null and ($line->end - $line->start) > 0) ? "\\move(" . round($this->from->x, 2) ."," . round($this->from->y, 2) ."," . round($this->to->x, 2) ."," . round($this->to->y, 2) .")" : "\\pos({$this->from->x},{$this->from->y})";
}
public function equals(ASSTag $tag): bool {

View file

@ -22,7 +22,7 @@ class rotationTag implements ASSPositioningTag {
}
public function encode(ASSLine $line, float $frameDurationMs): string {
return "\\frx{$this->x}\\fry{$this->y}\\frz{$this->z}";
return "\\frx" . round($this->x, 2) ."\\fry" . round($this->y, 2) ."\\frz" . round($this->z, 2);
}
public function equals(ASSTag $tag): bool {

View file

@ -20,7 +20,7 @@ class scaleTag implements ASSPositioningTag {
}
public function encode(ASSLine $line, float $frameDurationMs): string {
return "\\fscx{$this->scale->x}\\fscy{$this->scale->y}";
return "\\fscx" . round($this->scale->x, 4) ."\\fscy" . round($this->scale->y, 4);
}
public function equals(ASSTag $tag): bool {

View file

@ -20,7 +20,7 @@ class shearingTag implements ASSPositioningTag {
}
public function encode(ASSLine $line, float $frameDurationMs): string {
return "\\fax{$this->shear->x}\\fay{$this->shear->y}";
return "\\fax" . round($this->shear->x, 5) ."\\fay" . round($this->shear->x, 5) ."";
}
public function equals(ASSTag $tag): bool {