mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Fixed whitespace and formatting in util.SimpleFlvWriter
This commit is contained in:
parent
3ca6d42232
commit
9ae4614595
1 changed files with 267 additions and 282 deletions
|
@ -61,19 +61,16 @@ public class SimpleFlvWriter {
|
|||
private var bmp:BitmapData;
|
||||
|
||||
|
||||
public static function getInstance():SimpleFlvWriter
|
||||
{
|
||||
if(SimpleFlvWriter._instance == null)
|
||||
public static function getInstance():SimpleFlvWriter {
|
||||
if(SimpleFlvWriter._instance == null) {
|
||||
SimpleFlvWriter._instance = new SimpleFlvWriter(new SingletonEnforcer());
|
||||
}
|
||||
return SimpleFlvWriter._instance;
|
||||
}
|
||||
|
||||
public function SimpleFlvWriter(singletonEnforcer:SingletonEnforcer)
|
||||
{
|
||||
}
|
||||
public function SimpleFlvWriter(singletonEnforcer:SingletonEnforcer) {}
|
||||
|
||||
public function createFile(bytes:ByteArray, pWidth:int, pHeight:int, pFramesPerSecond:Number, pDurationInSeconds:Number=0):void
|
||||
{
|
||||
public function createFile(bytes:ByteArray, pWidth:int, pHeight:int, pFramesPerSecond:Number, pDurationInSeconds:Number=0):void {
|
||||
/*
|
||||
Parameters:
|
||||
|
||||
|
@ -100,16 +97,14 @@ public class SimpleFlvWriter {
|
|||
fs.writeBytes(flvTagOnMetaData());
|
||||
}
|
||||
|
||||
public function saveFrame(pBitmapData:BitmapData):void
|
||||
{
|
||||
public function saveFrame(pBitmapData:BitmapData):void {
|
||||
// bitmap dimensions should of course match parameters passed to createFile()
|
||||
bmp = pBitmapData;
|
||||
fs.writeUnsignedInt(previousTagSize);
|
||||
fs.writeBytes(flvTagVideo());
|
||||
}
|
||||
|
||||
private function header():ByteArray
|
||||
{
|
||||
private function header():ByteArray {
|
||||
var ba:ByteArray = new ByteArray();
|
||||
ba.writeByte(0x46) // 'F'
|
||||
ba.writeByte(0x4C) // 'L'
|
||||
|
@ -120,8 +115,7 @@ public class SimpleFlvWriter {
|
|||
return ba;
|
||||
}
|
||||
|
||||
private function flvTagVideo():ByteArray
|
||||
{
|
||||
private function flvTagVideo():ByteArray {
|
||||
var tag:ByteArray = new ByteArray();
|
||||
var dat:ByteArray = videoData();
|
||||
var timeStamp:uint = uint(1000/frameRate * iteration++);
|
||||
|
@ -140,8 +134,7 @@ public class SimpleFlvWriter {
|
|||
return tag;
|
||||
}
|
||||
|
||||
private function videoData():ByteArray
|
||||
{
|
||||
private function videoData():ByteArray {
|
||||
var v:ByteArray = new ByteArray;
|
||||
|
||||
// VIDEODATA 'header'
|
||||
|
@ -163,23 +156,19 @@ public class SimpleFlvWriter {
|
|||
var xRemainder:int = frameWidth % blockWidth;
|
||||
if (xRemainder > 0) xMax += 1;
|
||||
|
||||
for (var y1:int = 0; y1 < yMax; y1++)
|
||||
{
|
||||
for (var x1:int = 0; x1 < xMax; x1++)
|
||||
{
|
||||
for (var y1:int = 0; y1 < yMax; y1++) {
|
||||
for (var x1:int = 0; x1 < xMax; x1++) {
|
||||
// create block
|
||||
var block:ByteArray = new ByteArray();
|
||||
|
||||
var yLimit:int = blockHeight;
|
||||
if (yRemainder > 0 && y1 + 1 == yMax) yLimit = yRemainder;
|
||||
|
||||
for (var y2:int = 0; y2 < yLimit; y2++)
|
||||
{
|
||||
for (var y2:int = 0; y2 < yLimit; y2++) {
|
||||
var xLimit:int = blockWidth;
|
||||
if (xRemainder > 0 && x1 + 1 == xMax) xLimit = xRemainder;
|
||||
|
||||
for (var x2:int = 0; x2 < xLimit; x2++)
|
||||
{
|
||||
for (var x2:int = 0; x2 < xLimit; x2++) {
|
||||
var px:int = (x1 * blockWidth) + x2;
|
||||
var py:int = frameHeight - ((y1 * blockHeight) + y2); // (flv's save from bottom to top)
|
||||
var p:uint = bmp.getPixel(px, py);
|
||||
|
@ -198,8 +187,7 @@ public class SimpleFlvWriter {
|
|||
return v;
|
||||
}
|
||||
|
||||
private function flvTagOnMetaData():ByteArray
|
||||
{
|
||||
private function flvTagOnMetaData():ByteArray {
|
||||
var tag:ByteArray = new ByteArray();
|
||||
var dat:ByteArray = metaData();
|
||||
|
||||
|
@ -282,8 +270,7 @@ public class SimpleFlvWriter {
|
|||
return b;
|
||||
}
|
||||
|
||||
private function writeUI24(stream:*, p:uint):void
|
||||
{
|
||||
private function writeUI24(stream:*, p:uint):void {
|
||||
var byte1:int = p >> 16;
|
||||
var byte2:int = p >> 8 & 0xff;
|
||||
var byte3:int = p & 0xff;
|
||||
|
@ -292,14 +279,12 @@ public class SimpleFlvWriter {
|
|||
stream.writeByte(byte3);
|
||||
}
|
||||
|
||||
private function writeUI16(stream:*, p:uint):void
|
||||
{
|
||||
stream.writeByte( p >> 8 )
|
||||
private function writeUI16(stream:*, p:uint):void {
|
||||
stream.writeByte(p >> 8);
|
||||
stream.writeByte(p & 0xff);
|
||||
}
|
||||
|
||||
private function writeUI4_12(stream:*, p1:uint, p2:uint):void
|
||||
{
|
||||
private function writeUI4_12(stream:*, p1:uint, p2:uint):void {
|
||||
// writes a 4-bit value followed by a 12-bit value in two sequential bytes
|
||||
|
||||
var byte1a:int = p1 << 4;
|
||||
|
@ -310,8 +295,8 @@ public class SimpleFlvWriter {
|
|||
stream.writeByte(byte1);
|
||||
stream.writeByte(byte2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
class SingletonEnforcer {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue