FlappBitmap.prototype = {
};
+ FlappBitmap.jpegChunkOffsets = function(jpegData) {
+ var offsetTable = {};
+ var ibit = new FlappIBit();
+ while (ibit.HasNext(2)) {
+ var marker = ibit.ui16be();
+ var offset = ibit.getBytePos();
+ switch (marker) {
+ case 0xFFD8: // SOI
+ case 0xFFD9: // EOI
+ break;
+ case 0xFFDA: // SOS + [RST] + EOI
+ length = ibit.len() - offset;
+ offsetTable[marker] = [offset, length]
+ break;
+ default:
+ length = ibit.ui16be() + 2;
+ offsetTable[marker] = [offset, length]
+
+ break;
+ }
+ }
+ }
+
FlappBitmap.toJpeg = function(swfJpeg, jpegTables) {
- return swfJpeg;
+ var hasDQT = false;
+ var offsetTable = FlappBitmap.jpegChunkOffsets(swfJpeg);
+ if (0xFFDB in offsetTable) {
+ hasDQT = true;
+ }
+ if (hasDQT === false) {
+ var offsetTable2 = FlappBitmap.jpegChunkOffsets(jpegTables);
+ }
+ var jpegArray = [0xFF, 0xD8]; // SOI
+ // APP0, SOF0, DQT, DHT, SOS
+ var jpegOrder = [0xFFE0, 0xFFC0, 0xFFDB, 0xFFC4, 0xFFDA];
+ for (var i = 0, l = jpegOrder; i < l ; i++) {
+ var marker = jpegOrder[i];
+ var swfJpegOffset = (marker in offsetTable)?true:false;
+ if (swfJpegOffset) {
+ var entry = offsetTable[marker];
+ } else {
+ var entry = offsetTable2[marker];
+ }
+ var offset = entry[0];
+ var enfoffset = offset + entry[1];
+ for (j = offset; j < enfoffset ; j++) {
+ if (swfJpegOffset) {
+ jpegArray.join(swfJpeg[j]);
+ } else {
+ jpegArray.join(jpegTables[j]);
+ }
+ }
+ }
+ return FlappString.ArrayToString(jpegArray).join('');
};
FlappBitmap.toPng = function(lossless) {
;