void printSoundInfo(FILE *f) { int flags = readUInt8(f), nPoints, i; ++gIndent; if(flags&0x40) println("Don't start if already playing"); if(flags&0x80) println("Stop sound"); if(flags&0x01) println("In Point: %i", readUInt32(f)); if(flags&0x02) println("Out Point: %i", readUInt32(f)); if(flags&0x04) println("Loops: %i", readUInt16(f)); if(flags&0x08) { nPoints = readUInt8(f); for(i=0; i<nPoints; ++i) { println("Envelope point %i:", i); println("Mark44: %i", readUInt32(f)); println("Level0: %i", readUInt16(f)); println("Level1: %i", readUInt16(f)); } } --gIndent; }
void printSoundInstance(FILE *f, int id, int soundid){ int e,point,left,right; int flags = readUInt8(f); if (flags & SWFSOUNDINFO_SYNCSTOPSOUND){ printf("\t# stopsound??"); } if (flags & SWFSOUNDINFO_SYNCNOMULTIPLE){ printf("\t$si->setNoMultiple();\n"); } if(flags & SWFSOUNDINFO_HASINPOINT){ int inpoint = readUInt32(f); printf("\t$si->setInPoint(%i);\n", inpoint); } if(flags & SWFSOUNDINFO_HASOUTPOINT){ int outpoint = readUInt32(f); printf("\t$si->setOutPoint(%i);\n", outpoint); } if(flags & SWFSOUNDINFO_HASLOOPS){ int loopcount = readUInt16(f); printf("\t$si->setLoops(%i);\n", loopcount); } if(flags & SWFSOUNDINFO_HASENVELOPE) { int envpoints = readUInt8(f); for (e=0; e<envpoints;e++){ point = readUInt32(f); left = readUInt16(f); left = readUInt16(f); printf("\t$si->addEnvelopePoint(%i,%i,%i);\n", point,left,right); } } }
std::string BinaryInput::readStringNewline() { int64 n = 0; if ((m_pos + m_alreadyRead + n) < (m_length - 1)) { prepareToRead(1); } if ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) && ! isNewline(m_buffer[m_pos + n])) { ++n; while ( ((m_pos + m_alreadyRead + n) < (m_length - 1)) && ! isNewline(m_buffer[m_pos + n])) { prepareToRead(1); ++n; } } const std::string s = readString(n); // Consume the newline char firstNLChar = readUInt8(); // Consume the 2nd newline if (isNewline(m_buffer[m_pos + 1]) && (m_buffer[m_pos + 1] != firstNLChar)) { readUInt8(); } return s; }
void readRGBA(FILE *f, struct RGBA *s) { s->r = readUInt8(f); s->g = readUInt8(f); s->b = readUInt8(f); s->a = readUInt8(f); }
void printRGB(FILE *f) { int r = readUInt8(f); int g = readUInt8(f); int b = readUInt8(f); printf("(%02x,%02x,%02x)", r, g, b); }
void printLineStyleArray(FILE *f, int shapeType) { int count, i; count = readUInt8(f); if(count==255) count = readUInt16(f); for(i=0; i<count; ++i) { print("LineStyle %i: ", i+1); printf("width=%i ", readUInt16(f)); if(shapeType==SWF_DEFINEMORPHSHAPE) printf("width2=%i ", readUInt16(f)); puts("color="); if(shapeType==SWF_DEFINESHAPE3 || shapeType==SWF_DEFINEMORPHSHAPE) printRGBA(f); else printRGB(f); if(shapeType==SWF_DEFINEMORPHSHAPE) { puts("color2="); printRGBA(f); } putchar('\n'); } }
int printButtonRecord(FILE *f, int recordType) { int character, layer; int flags = readUInt8(f); if(flags == 0) return 0; if(flags & 0x08) println("Hit flag: "); if(flags & 0x04) println("Down flag: "); if(flags & 0x02) println("Over flag: "); if(flags & 0x01) println("Up flag: "); character = readUInt16(f); layer = readUInt16(f); println("character: %i, layer %i", character, layer); printMatrix(f); if(recordType == 2) printCXForm(f, true); /* XXX - should be true? */ return 1; }
uint32 BinaryInput::readBits(int numBits) { debugAssert(beginEndBits == 1); uint32 out = 0; const int total = numBits; while (numBits > 0) { if (bitPos > 7) { // Consume a new byte for reading. We do this at the beginning // of the loop so that we don't try to read past the end of the file. bitPos = 0; bitString = readUInt8(); } // Slide the lowest bit of the bitString into // the correct position. out |= (bitString & 1) << (total - numBits); // Shift over to the next bit bitString = bitString >> 1; ++bitPos; --numBits; } return out; }
STDMETHODIMP_(UInt8) CCMIAdapter::readMixer(UInt8 index) { if (mixerCache[index] == 0xFF) { writeUInt8(REG_SBINDEX, index); mixerCache[index] = readUInt8(REG_SBDATA); } return mixerCache[index]; }
void BinaryInput::beginBits() { debugAssert(beginEndBits == 0); beginEndBits = 1; bitPos = 0; debugAssertM(hasMore(), "Can't call beginBits when at the end of a file"); bitString = readUInt8(); }
void printDefineText(FILE *f, int length, int type) /* type 2 allows transparency */ { int glyphBits, advanceBits, end = fileOffset+length; println("character id: %i", readUInt16(f)); print("bounds: "); printRect(f); putchar('\n'); byteAlign(); println("matrix:"); printMatrix(f); glyphBits = readUInt8(f); advanceBits = readUInt8(f); while(fileOffset < end && printTextRecord(f, glyphBits, advanceBits, type)) ; }
void decompileAction(FILE *f, int length, int indent) { if(m_version >= 5) decompile5Action(f, length, indent); else if(m_version > 3) decompile4Action(f, length, indent); else while(--length >= 0) readUInt8(f); }
void printGradient(FILE *f, int shapeType) { int i; int numGrads = readUInt8(f); for(i=0; i<numGrads; ++i) { print("Grad[%i]: ratio=%i, ", i, readUInt8(f)); puts("color="); if(shapeType==SWF_DEFINESHAPE3) printRGBA(f); else printRGB(f); putchar('\n'); } }
void printMorphGradient(FILE *f) { int i; int numGrads = readUInt8(f); for(i=0; i<numGrads; ++i) { print("Shape 1, Grad[%i]: ratio=%i, ", i, readUInt8(f)); puts("color="); printRGBA(f); putchar('\n'); print("Shape 2, Grad[%i]: ratio=%i, ", i, readUInt8(f)); puts("color="); printRGBA(f); putchar('\n'); } }
void readSoundStreamHead(ddMovieClip* p, ddReader* r, int length) { int flags; ddSoundFormat format; int sampleRate; int bitsPerSample; boolean stereo; int samplesPerFrame; int delay = 0; readUInt8(r); // recommended playback settings - ignore flags = readUInt8(r); switch ( (flags & 0xf0) >> 4 ) { case 0: format = DDSOUND_UNCOMPRESSED; break; case 1: format = DDSOUND_ADPCM; break; case 2: format = DDSOUND_MP3; break; case 3: format = DDSOUND_UNCOMPRESSED_LITTLEENDIAN; break; case 6: format = DDSOUND_NELLYMOSER; break; default: dd_warn("Unknown sound format: %i", (flags & 0xf0) >> 4); } switch ( (flags & 0x0c) >> 2 ) { case 0: sampleRate = 5500; break; case 1: sampleRate = 11000; break; case 2: sampleRate = 22000; break; case 3: sampleRate = 44000; break; } bitsPerSample = ((flags & 0x02) != 0) ? 16 : 8; stereo = ((flags & 0x01) != 0) ? DD_TRUE : DD_FALSE; samplesPerFrame = readUInt16(r); if ( format == DDSOUND_MP3 ) delay = readSInt16(r); ddMovieClip_setSoundStreamFormat(p, format, sampleRate, bitsPerSample, stereo, samplesPerFrame, delay); }
void readGradient(FILE *f, struct Gradient *s, Blocktype shapeType) { int i; int numGrads = readUInt8(f); s->nGradients = numGrads; s->colors = malloc(sizeof(struct RGBA)*numGrads); s->ratio = malloc(sizeof(int)*numGrads); for(i=0; i<numGrads; ++i) { s->ratio[i] = readUInt8(f); if(shapeType==DEFINESHAPE3) readRGBA(f, &(s->colors[i])); else readRGB(f, &(s->colors[i])); } }
void printFontInfo(FILE *f, int length) { int namelen, nGlyphs, flags, i; println("FontID: %i", readUInt16(f)); namelen = readUInt8(f); nGlyphs = length-namelen-4; print("Font Name: "); for(; namelen>0; --namelen) putchar((unsigned char)readUInt8(f)); putchar('\n'); flags = readUInt8(f); if(flags & FONTINFO_UNICODE) println("Unicode character codes!"); if(flags & FONTINFO_SHIFTJIS) println("\tShiftJIS character codes!"); if(flags & FONTINFO_ANSI) println("\tANSI character codes!"); if(flags & FONTINFO_ITALIC) println("\tFont is italic!"); if(flags & FONTINFO_BOLD) println("\tFont is bold!"); if(flags & FONTINFO_WIDE) nGlyphs /= 2; for(i=0; i<nGlyphs; ++i) if(flags & FONTINFO_WIDE) println("glyph %i: %i", i, readUInt16(f)); else println("glyph %i: %i", i, readUInt8(f)); }
void printPlaceObject2(FILE *f, int length) { int start = fileOffset; int flags = readUInt8(f); int l; println("Depth: %i", readUInt16(f)); if(flags & PLACE_HASMOVE) println("Has move flag"); if(flags & PLACE_HASCHARACTER) println("Character ID: %i", readUInt16(f)); if(flags & PLACE_HASMATRIX) { println("Matrix:"); printMatrix(f); } if(flags & PLACE_HASCXFORM) { print("CXForm: "); printCXForm(f, true); putchar('\n'); } if(flags & PLACE_HASRATIO) println("Ratio: %i", readUInt16(f)); if(flags & PLACE_HASNAME) println("Name: %s", readString(f)); if(flags & PLACE_HASCLIP) println("ClipDepth: %i", readUInt16(f)); if(flags & PLACE_RESERVED) { println("Mystery number: %04x", readUInt16(f)); flags = readUInt16(f); println("Clip flags: %04x", flags); while((flags = readUInt16(f)) != 0) { println("Flags: %04x", flags); l = readUInt32(f); decompileAction(f, l, 0); } } dumpBytes(f, length-(fileOffset-start)); }
void ReadNodeDefName(char*& buffer, int32* name) { uint32 namelen = readUInt8(buffer); if (namelen >= kSCNodeDefNameByteLen) { std::ostringstream os; os << "node definition name too long (> " << kSCNodeDefNameByteLen - 1 << " chars): " << std::string(buffer, namelen); throw std::runtime_error(os.str()); } memset(name, 0, kSCNodeDefNameByteLen); readData(buffer, (char*)name, namelen); }
ddSoundInstance* readSoundInfo(ddReader* r, int characterid) { int flags = readUInt8(r); ddSoundInstance* sound; if ( (flags & SOUNDINFO_STOP) != 0 ) return NULL; sound = dd_newSoundInstance(characterid); ddSoundInstance_setNoMultipleFlag(sound, (flags & SOUNDINFO_NOMULTIPLE) ? DD_TRUE : DD_FALSE); if ( (flags & SOUNDINFO_HASINPOINT) != 0 ) ddSoundInstance_setInPoint(sound, readUInt32(r)); if ( (flags & SOUNDINFO_HASOUTPOINT) != 0 ) ddSoundInstance_setOutPoint(sound, readUInt32(r)); if ( (flags & SOUNDINFO_HASLOOPS) != 0 ) ddSoundInstance_setLoopCount(sound, readUInt16(r)); if ( (flags & SOUNDINFO_HASENVELOPE) != 0 ) { int count = readUInt8(r); int i; for ( i = 0; i < count; ++i ) { int position = readUInt32(r); float leftLevel = (float)readUInt16(r) / 0xffff; float rightLevel = (float)readUInt16(r) / 0xffff; ddSoundInstance_addEnvelopePoint(sound, position, leftLevel, rightLevel); } } return sound; }
void printJpegStream(FILE *f, int length) { int end = fileOffset+length; int c, l; while(fileOffset < end) { if(readUInt8(f) != JPEG_MARKER) { println("Jpeg marker not found!"); break; } switch(c=readUInt8(f)) { case JPEG_SOI: println("SOI"); break; case JPEG_EOI: println("EOI"); break; case JPEG_JFIF: println("JFIF"); break; case JPEG_QUANT: println("Quantization table"); break; case JPEG_HUFF: println("Huffman table"); break; case JPEG_SOF0: println("Start of frame 0"); break; case JPEG_SOF1: println("Start of frame 1"); break; case JPEG_SOF2: println("Start of frame 2"); break; case JPEG_SOS: println("Start of scan"); break; default: println("Unknown JPEG block: %02x", c); } if(c==JPEG_SOS) break; if(c != JPEG_SOI && c != JPEG_EOI) { l = (readUInt8(f)<<8) + readUInt8(f); skipBytes(f, l-2); } } skipBytes(f, end-fileOffset); }
void readDefineSound(ddMovieClip* p, ddReader* r, int length) { int end = ddReader_getOffset(r) + length; int characterID = readUInt16(r); int flags = readUInt8(r); ddSoundFormat format; int sampleCount; unsigned char* data; int sampleRate; int bitsPerSample; boolean stereo; int delay; int size; ddSound* sound; switch ( (flags & 0xf0) >> 4 ) { case 0: format = DDSOUND_UNCOMPRESSED; break; case 1: format = DDSOUND_ADPCM; break; case 2: format = DDSOUND_MP3; break; case 3: format = DDSOUND_UNCOMPRESSED_LITTLEENDIAN; break; case 6: format = DDSOUND_NELLYMOSER; break; default: dd_warn("Unknown sound format: %i", (flags & 0xf0) >> 4); } sampleCount = readUInt32(r); if ( format == DDSOUND_MP3 ) delay = readSInt16(r); size = end - ddReader_getOffset(r); data = readBlock(r, size); switch ( (flags & 0x0c) >> 2 ) { case 0: sampleRate = 5500; break; case 1: sampleRate = 11000; break; case 2: sampleRate = 22000; break; case 3: sampleRate = 44000; break; } bitsPerSample = ((flags & 0x02) != 0) ? 16 : 8; stereo = ((flags & 0x01) != 0) ? DD_TRUE : DD_FALSE; sound = dd_newSound(format, sampleRate, bitsPerSample, stereo, sampleCount, size, data, delay); ddMovieClip_addCharacter(p, characterID, (ddCharacter*)sound); }
int printButtonRecord(FILE *f, int recordType, int id) { int character, layer; int flags = readUInt8(f); struct Matrix m; int notFirst = 0; if(flags == 0) return 0; character = readUInt16(f); layer = readUInt16(f); printf("\t$s%i->addShape($s%i, ", id, character); readMatrix(f, &m); if(flags & 0x08) { printf("SWFBUTTON_HIT"); notFirst = 1; } if(flags & 0x04) { printf("%sSWFBUTTON_DOWN", (notFirst?" | ":"")); notFirst = 1; } if(flags & 0x02) { printf("%sSWFBUTTON_OVER", (notFirst?" | ":"")); notFirst = 1; } if(flags & 0x01) { printf("%sSWFBUTTON_UP", (notFirst?" | ":"")); notFirst = 1; } printf(");\n"); printf("\t# Button character transforms not implemented, sorry.\n"); if(recordType == 2) { struct CXForm s; readCXForm(f, &s, true); printf("\t# Button cxforms not implemented, either.. \n"); } return 1; }
void printMorphShape(FILE *f, int length) { int offset, start = fileOffset, here; struct Rect r; struct Shape shape1, shape2; int id = readUInt16(f); printf("\n\t### Morph %i ###\n", id); printf("\t$s%i = new SWF::Morph();\n", id); readRect(f, &r); /* bounds 1 */ readRect(f, &r); /* bounds 2 */ offset = readUInt32(f); here = fileOffset+1; memset(&shape1, 0, sizeof(struct Shape)); memset(&shape2, 0, sizeof(struct Shape)); shape1.shapeType = shape2.shapeType = DEFINESHAPE3; readFillStyleArray(f, &shape1, 1); readLineStyleArray(f, &shape1, 1); byteAlign(); shape1.fillBits = shape2.fillBits = readBits(f,4); shape1.lineBits = shape2.lineBits = readBits(f,4); while(fileOffset < here+offset && readShapeRec(f, &shape1)) ; printf("\n\t$s%i_1 = $s%i->getShape1();\n", id, id); printDefineShape(&shape1, id, 0); byteAlign(); readUInt8(f); /* redundant fill/line bits */ while(fileOffset < start+length && readShapeRec(f, &shape2)) ; printf("\n\t$s%i_2 = $s%i->getShape2();\n", id, id); printDefineShape(&shape1, id, 1); }
int printTextRecord(FILE *f, int glyphBits, int advanceBits, int type) { int i, numGlyphs; int flags = readUInt8(f); if(flags == 0) return 0; if(flags & TEXTRECORD_STATECHANGE) { if(flags & TEXTRECORD_HASFONT) println("font id: %i", readUInt16(f)); if(flags & TEXTRECORD_HASCOLOR) { print("color: "); if(type == 2) printRGBA(f); else printRGB(f); putchar('\n'); } if(flags & TEXTRECORD_HASXOFF) println("X Offset: %i", readSInt16(f)); if(flags & TEXTRECORD_HASYOFF) println("Y Offset: %i", readSInt16(f)); if(flags & TEXTRECORD_HASFONT) println("font height: %i", readUInt16(f)); } else { numGlyphs = flags & TEXTRECORD_NUMGLYPHS; for(i=0; i<numGlyphs; ++i) { println("glyph index: %i", readBits(f, glyphBits)); println("glyph x advance: %i", readSBits(f, advanceBits)); } } return 1; }
void printDefineButton2(FILE *f, int length) { int flags, offset, end = fileOffset+length; println("Button id: %i", readUInt16(f)); flags = readUInt8(f); /* flags */ if(flags) println("tracked as menu item (whatever that means..)"); offset = readUInt16(f); /* offset */ println("offset = %i", offset); while(printButtonRecord(f, 2)) ; if(offset>0) while(printButton2ActionCondition(f, end)) ; }
void printFillStyleArray(FILE *f, int shapeType) { int count, i; count = readUInt8(f); if(count==255) count = readUInt16(f); for(i=0; i<count; ++i) { println("FillStyle %i:", i+1); ++gIndent; printFillStyle(f, shapeType); --gIndent; putchar('\n'); } }
void readFillStyle(FILE *f, struct FillStyle *s, Blocktype shapeType, int isMorph) { int type; type = readUInt8(f); s->type = type; if(type==0) /* solid fill */ { if(shapeType==DEFINESHAPE3) readRGBA(f, &(s->fill.color)); else readRGB(f, &(s->fill.color)); if(isMorph) readRGBA(f, &(s->fill2.color)); } else if(type==0x10 || type==0x12) { /* linear (0x10) or radial (0x10) gradient */ readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); readGradient(f, &(s->fill.gradient), shapeType); } else if(type==0x40 || type==0x41) { /* tiled bitmap (0x40) or clipped bitmap (0x41) fill */ s->fill.bitmap = readUInt16(f); readMatrix(f, &(s->matrix)); if(isMorph) readMatrix(f, &(s->matrix2)); } else error("Unknown fill type: %i\n", type); }
void readFillStyleArray(FILE *f, struct Shape *shape, int isMorph) { struct FillStyles *s; int count, i, start; start = shape->fills.nFills; shape->fillOffset = start; count = readUInt8(f); if(count==255) count = readUInt16(f); s = &(shape->fills); s->nFills += count; s->fill = realloc(s->fill, s->nFills * sizeof(struct FillStyle)); for(i=0; i<count; ++i) readFillStyle(f, &(s->fill[start+i]), shape->shapeType, isMorph); }
boolean MePressureSensor::begin(uint8_t mode) { if (mode > BMP180_ULTRAHIGHRES) mode = BMP180_ULTRAHIGHRES; oversampling = mode; Wire.begin(); if (readUInt8(0xD0) != 0x55) return false; ac1 = readUInt16(BMP180_CAL_AC1); ac2 = readUInt16(BMP180_CAL_AC2); ac3 = readUInt16(BMP180_CAL_AC3); ac4 = readUInt16(BMP180_CAL_AC4); ac5 = readUInt16(BMP180_CAL_AC5); ac6 = readUInt16(BMP180_CAL_AC6); b1 = readUInt16(BMP180_CAL_B1); b2 = readUInt16(BMP180_CAL_B2); mb = readUInt16(BMP180_CAL_MB); mc = readUInt16(BMP180_CAL_MC); md = readUInt16(BMP180_CAL_MD); return true; }