public bool extract() { while (true) { if (!this.readLength(out this.length)) { // Debug.WriteLine("Failed in reading length: offsetByte = " + this.offsetBytesCompressed + ", offsetBits = " + this.offsetBitsCompressed); return(false); } // Debug.WriteLine("length=" + this.length.ToString()); while (this.width <= this.posCurrent.x + this.length) { this.setLineSegment(this.posCurrent, this.width - this.posCurrent.x, this.segments); this.length -= this.width - this.posCurrent.x; this.posCurrent.x = 0; this.posCurrent.y++; if (this.height <= this.posCurrent.y) { return(true); } this.segments = this.scanSegmentsActiveNextLine(); } if (0 < this.length) { if (0 <= this.posCurrent.x) { this.setLineSegment(this.posCurrent, this.length, this.segments); } this.posCurrent.x += this.length; } if (!this.readColor(out this.colorCurrent)) { Debug.WriteLine("Failed in reading color: offsetByte = " + this.offsetBytesCompressed + ", offsetBits = " + this.offsetBitsCompressed); return(false); } // Debug.WriteLine("color=" + this.getStrColor(this.colorCurrent)); YanagisawaPicLightning lightning = null; if (!this.readLightning(this.posCurrent, out lightning)) { Debug.WriteLine("Failed in reading lightning: offsetByte = " + this.offsetBytesCompressed + ", offsetBits = " + this.offsetBitsCompressed); return(false); } if (lightning != null) { lightning.color = this.colorCurrent.CloneDeep(); // this.drawLightning(lightning); // debug this.lightnings.Add(lightning); // Debug.WriteLine("lightning size=" + lightning.numOffsets.ToString()); } else { // Debug.WriteLine("lightning none"); } } }
private void drawLightning(YanagisawaPicLightning lightning) { var pos = lightning.posStart.CloneDeep(); this.setPixel(pos, lightning.color); var numOffsets = lightning.numOffsets; for (var index = 0; index < numOffsets; index++) { pos.x += lightning.offsetsX[index]; pos.y++; this.setPixel(pos, lightning.color); } }
private bool readLightning(Pos2 pos, out YanagisawaPicLightning lightning) { lightning = new YanagisawaPicLightning(pos); long value = 0; if (!this.readBitsCompressed(1, out value)) { return(false); } if (value == 0) { return(true); } bool needToExit = false; while (!needToExit) { if (!this.readBitsCompressed(2, out value)) { return(false); } var next = value; switch (next) { case 0x0: if (!this.readBitsCompressed(1, out value)) { return(false); } if (value == 1) { if (!this.readBitsCompressed(1, out value)) { return(false); } var next2 = value; lightning.addOffset(next2 == 0 ? -2 : 2); } else { needToExit = true; } break; case 0x1: lightning.addOffset(-1); break; case 0x2: lightning.addOffset(0); break; case 0x3: lightning.addOffset(1); break; } } return(true); }