protected virtual void CodeImageSize(JB2Image ignored) { _lastLeft = 1 + ImageColumns; _lastRowBottom = ImageRows; _lastRowLeft = _lastRight = 0; FillShortList(_lastRowBottom); GotStartRecordP = true; }
public void Code(JB2Image jim) { int rectype = StartOfData; do { rectype = CodeRecordB(rectype, jim, null, null); } while (rectype != EndOfData); if (!_GotStartRecordP) { throw new DjvuFormatException("Image has no start record"); } }
protected override void CodeImageSize(JB2Image jim) { _ImageColumns = CodeNum(0, Bigpositive, _ImageSizeDist); _ImageRows = CodeNum(0, Bigpositive, _ImageSizeDist); if ((_ImageColumns == 0) || (_ImageRows == 0)) { throw new DjvuFormatException("Image with zero size"); } jim.Width = _ImageColumns; jim.Height = _ImageRows; base.CodeImageSize(jim); }
public virtual void Code(JB2Image jim) { int rectype = StartOfData; do { //Console.WriteLine("Jb2D c(i) rectype in: " + rectype); rectype = CodeRecordB(rectype, jim, null, null); //Console.WriteLine("Jb2D c(i) rectype out: " + rectype); } while (rectype != EndOfData); if (!GotStartRecordP) { throw new SystemException("Image no start"); } }
protected override void CodeImageSize(JB2Image jim) { //Console.WriteLine("Jb2D cis(im) image_size_dist: " + image_size_dist.Value); ImageColumns = CodeNum(0, Bigpositive, ImageSizeDist); ImageRows = CodeNum(0, Bigpositive, ImageSizeDist); //Console.WriteLine("Jb2D cis(im) image_columns: " + image_columns); //Console.WriteLine("Jb2D cis(im) image_rows: " + image_rows); //Console.WriteLine("Jb2D cis(im) image_size_dist: " + image_size_dist.Value); if ((ImageColumns == 0) || (ImageRows == 0)) { throw new SystemException("Image zero size"); } jim.Width = ImageColumns; jim.Height = ImageRows; base.CodeImageSize(jim); }
protected virtual int CodeRecordB(int rectype, JB2Image jim, JB2Shape xjshp, JB2Blit xjblt) { Bitmap bm = null; int shapeno = -1; JB2Shape jshp = xjshp; JB2Blit jblt = xjblt; rectype = CodeRecordType(rectype); switch (rectype) { case NewMark: case NewMarkImageOnly: case MatchedRefine: case MatchedRefineImageOnly: case NonMarkData: { if (jblt == null) { jblt = new JB2Blit(); } // fall through } goto case NewMarkLibraryOnly; case NewMarkLibraryOnly: case MatchedRefineLibraryOnly: { if (!_encoding) { jshp = new JB2Shape().Init((rectype == NonMarkData) ? (-2) : (-1)); } else if (jshp == null) { jshp = new JB2Shape(); } bm = jshp.Bitmap; break; } case MatchedCopy: { if (jblt == null) { jblt = new JB2Blit(); } break; } } bool needAddLibrary = false; bool needAddBlit = false; switch (rectype) { case StartOfData: { CodeImageSize(jim); CodeEventualLosslessRefinement(); if (!_encoding) { InitLibrary(jim); } break; } case NewMark: { needAddBlit = needAddLibrary = true; CodeAbsoluteMarkSize(bm, 4); CodeBitmapDirectly(bm); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case NewMarkLibraryOnly: { needAddLibrary = true; CodeAbsoluteMarkSize(bm, 4); CodeBitmapDirectly(bm); break; } case NewMarkImageOnly: { needAddBlit = true; CodeAbsoluteMarkSize(bm, 3); CodeBitmapDirectly(bm); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedRefine: { needAddBlit = true; needAddLibrary = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); // verbose("2.d time="+System.currentTimeMillis()+",rectype="+rectype); CodeBitmapByCrossCoding(bm, cbm, match); // verbose("2.e time="+System.currentTimeMillis()+",rectype="+rectype); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedRefineLibraryOnly: { needAddLibrary = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); break; } case MatchedRefineImageOnly: { needAddBlit = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); CodeBitmapByCrossCoding(bm, cbm, match); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedCopy: { int match = CodeMatchIndex(jblt.ShapeNumber, jim); if (!_encoding) { jblt.ShapeNumber = Convert.ToInt32((Lib2Shape[match])); } bm = jim.GetShape(jblt.ShapeNumber).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; jblt.Left += lmatch.Right; jblt.Bottom += lmatch.Bottom; CodeRelativeLocation(jblt, (1 + lmatch.Top) - lmatch.Bottom, (1 + lmatch.Left) - lmatch.Right); jblt.Left -= lmatch.Right; jblt.Bottom -= lmatch.Bottom; break; } case NonMarkData: { needAddBlit = true; CodeAbsoluteMarkSize(bm, 3); CodeBitmapDirectly(bm); CodeAbsoluteLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case PreservedComment: { jim.Comment = CodeComment(jim.Comment); break; } case RequiredDictOrReset: { if (!GotStartRecordP) { CodeInheritedShapeCount(jim); } else { ResetNumcoder(); } break; } case EndOfData: break; default: throw new ArgumentException("Image unknown type"); } if (!_encoding) { switch (rectype) { case NewMark: case NewMarkLibraryOnly: case MatchedRefine: case MatchedRefineLibraryOnly: case NewMarkImageOnly: case MatchedRefineImageOnly: case NonMarkData: { if (xjshp != null) { jshp = jshp.Duplicate(); } shapeno = jim.AddShape(jshp); Shape2Lib(shapeno, MinusOneObject); if (needAddLibrary) { AddLibrary(shapeno, jshp); } if (needAddBlit) { jblt.ShapeNumber = shapeno; if (xjblt != null) { jblt = (JB2Blit)xjblt.Duplicate(); } jim.AddBlit(jblt); } break; } case MatchedCopy: { if (xjblt != null) { jblt = (JB2Blit)xjblt.Duplicate(); } jim.AddBlit(jblt); break; } } } return(rectype); }
protected virtual int CodeRecordB(int rectype, JB2Image jim, JB2Shape xjshp, JB2Blit xjblt) { Bitmap bm = null; int shapeno = -1; JB2Shape jshp = xjshp; JB2Blit jblt = xjblt; rectype = CodeRecordType(rectype); switch (rectype) { case NewMark: case NewMarkImageOnly: case MatchedRefine: case MatchedRefineImageOnly: case NonMarkData: { if (jblt == null) { jblt = new JB2Blit(); } // fall through } goto case NewMarkLibraryOnly; case NewMarkLibraryOnly: case MatchedRefineLibraryOnly: { if (!_encoding) { jshp = new JB2Shape().Init((rectype == NonMarkData) ? (-2) : (-1)); } else if (jshp == null) { jshp = new JB2Shape(); } bm = jshp.Bitmap; break; } case MatchedCopy: { if (jblt == null) { jblt = new JB2Blit(); } break; } } bool needAddLibrary = false; bool needAddBlit = false; switch (rectype) { case StartOfData: { CodeImageSize(jim); CodeEventualLosslessRefinement(); if (!_encoding) { InitLibrary(jim); } break; } case NewMark: { needAddBlit = needAddLibrary = true; CodeAbsoluteMarkSize(bm, 4); CodeBitmapDirectly(bm); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case NewMarkLibraryOnly: { needAddLibrary = true; CodeAbsoluteMarkSize(bm, 4); CodeBitmapDirectly(bm); break; } case NewMarkImageOnly: { needAddBlit = true; CodeAbsoluteMarkSize(bm, 3); CodeBitmapDirectly(bm); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedRefine: { needAddBlit = true; needAddLibrary = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); // verbose("2.d time="+System.currentTimeMillis()+",rectype="+rectype); CodeBitmapByCrossCoding(bm, cbm, match); // verbose("2.e time="+System.currentTimeMillis()+",rectype="+rectype); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedRefineLibraryOnly: { needAddLibrary = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); break; } case MatchedRefineImageOnly: { needAddBlit = true; int match = CodeMatchIndex(jshp.Parent, jim); if (!_encoding) { jshp.Parent = Convert.ToInt32((Lib2Shape[match])); } Bitmap cbm = jim.GetShape(jshp.Parent).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; CodeRelativeMarkSize(bm, (1 + lmatch.Left) - lmatch.Right, (1 + lmatch.Top) - lmatch.Bottom, 4); CodeBitmapByCrossCoding(bm, cbm, match); CodeRelativeLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case MatchedCopy: { int match = CodeMatchIndex(jblt.ShapeNumber, jim); if (!_encoding) { jblt.ShapeNumber = Convert.ToInt32((Lib2Shape[match])); } bm = jim.GetShape(jblt.ShapeNumber).Bitmap; Rectangle lmatch = (Rectangle)_libinfo[match]; jblt.Left += lmatch.Right; jblt.Bottom += lmatch.Bottom; CodeRelativeLocation(jblt, (1 + lmatch.Top) - lmatch.Bottom, (1 + lmatch.Left) - lmatch.Right); jblt.Left -= lmatch.Right; jblt.Bottom -= lmatch.Bottom; break; } case NonMarkData: { needAddBlit = true; CodeAbsoluteMarkSize(bm, 3); CodeBitmapDirectly(bm); CodeAbsoluteLocation(jblt, bm.ImageHeight, bm.ImageWidth); break; } case PreservedComment: { jim.Comment = CodeComment(jim.Comment); break; } case RequiredDictOrReset: { if (!GotStartRecordP) { CodeInheritedShapeCount(jim); } else { ResetNumcoder(); } break; } case EndOfData: break; default: throw new ArgumentException("Image unknown type"); } if (!_encoding) { switch (rectype) { case NewMark: case NewMarkLibraryOnly: case MatchedRefine: case MatchedRefineLibraryOnly: case NewMarkImageOnly: case MatchedRefineImageOnly: case NonMarkData: { if (xjshp != null) { jshp = jshp.Duplicate(); } shapeno = jim.AddShape(jshp); Shape2Lib(shapeno, MinusOneObject); if (needAddLibrary) { AddLibrary(shapeno, jshp); } if (needAddBlit) { jblt.ShapeNumber = shapeno; if (xjblt != null) { jblt = (JB2Blit)xjblt.Duplicate(); } jim.AddBlit(jblt); } break; } case MatchedCopy: { if (xjblt != null) { jblt = (JB2Blit)xjblt.Duplicate(); } jim.AddBlit(jblt); break; } } } return rectype; }
/// <summary> /// Reads the image which is used to remove the watermark /// </summary> /// <returns></returns> private JB2Image ReadCompressedWatermarkImage() { using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length)) { JB2Image image = new JB2Image(); image.Decode(reader); return image; } }
private JB2Image ReadCompressedImage() { using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length)) { JB2Image image = new JB2Image(); JB2.JB2Dictionary includedDictionary = null; if (Parent is FormChunk) { InclChunk[] includes = ((FormChunk)Parent).IncludedItems; if (includes != null && includes.Count() > 0) { string includeID = includes.FirstOrDefault().IncludeID; var includeItem = Document.GetChunkByID<DjbzChunk>(includeID); if (includeItem != null) { includedDictionary = includeItem.ShapeDictionary; } } } image.Decode(reader, includedDictionary); return image; } }