Example #1
0
        public static Gdk.Pixbuf ToPixbuf(ArtworkFormat format, byte[] data)
        {
            Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, format.Width, format.Height);
            Gdk.Pixbuf rotated = null;

            switch (format.PixelFormat) {
            case PixelFormat.Rgb565:
                UnpackRgb565 (data, pixbuf, false);
                break;
            case PixelFormat.Rgb565BE:
                UnpackRgb565 (data, pixbuf, true);
                break;
            case PixelFormat.IYUV:
                UnpackIYUV (data, pixbuf);
                break;
            default:
                throw new ApplicationException ("Unknown pixel format: " + format.PixelFormat);
            }

            if (format.Rotation > 0) {
                rotated = Rotate (pixbuf, format.Rotation);
                pixbuf.Dispose ();
                pixbuf = rotated;
            }

            return pixbuf;
        }
Example #2
0
        public static Gdk.Pixbuf ToPixbuf(ArtworkFormat format, byte[] data)
        {
            Gdk.Pixbuf pixbuf  = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, format.Width, format.Height);
            Gdk.Pixbuf rotated = null;

            switch (format.PixelFormat)
            {
            case PixelFormat.Rgb565:
                UnpackRgb565(data, pixbuf, false);
                break;

            case PixelFormat.Rgb565BE:
                UnpackRgb565(data, pixbuf, true);
                break;

            case PixelFormat.IYUV:
                UnpackIYUV(data, pixbuf);
                break;

            default:
                throw new ApplicationException("Unknown pixel format: " + format.PixelFormat);
            }

            if (format.Rotation > 0)
            {
                rotated = Rotate(pixbuf, format.Rotation);
                pixbuf.Dispose();
                pixbuf = rotated;
            }

            return(pixbuf);
        }
Example #3
0
        public static byte[] ToBytes(ArtworkFormat format, Gdk.Pixbuf pixbuf, out short horizontalPadding,
                                     out short verticalPadding)
        {
            horizontalPadding = 0;
            verticalPadding   = 0;

            bool disposePixbuf = false;

            if (format.Rotation > 0)
            {
                pixbuf        = Rotate(pixbuf, format.Rotation);
                disposePixbuf = true;
            }

            if (pixbuf.Height != format.Height || pixbuf.Width != format.Width)
            {
                int        padX, padY;
                Gdk.Pixbuf scaled = Scale(pixbuf, format.Width, format.Height, out padX, out padY);

                horizontalPadding = (short)padX;
                verticalPadding   = (short)padY;

                if (disposePixbuf)
                {
                    pixbuf.Dispose();
                }

                pixbuf        = scaled;
                disposePixbuf = true;
            }

            byte[] data = null;

            switch (format.PixelFormat)
            {
            case PixelFormat.Rgb565:
                data = PackRgb565(pixbuf, false);
                break;

            case PixelFormat.Rgb565BE:
                data = PackRgb565(pixbuf, true);
                break;

            case PixelFormat.IYUV:
                data = PackIYUV(pixbuf);
                break;

            default:
                throw new ApplicationException("Unknown pixel format: " + format.PixelFormat);
            }

            if (disposePixbuf)
            {
                pixbuf.Dispose();
            }

            return(data);
        }
Example #4
0
        public void RemoveCoverArt(ArtworkFormat format)
        {
            Thumbnail thumbnail = GetThumbnail(format, false);

            if (thumbnail != null)
            {
                coverPhoto.RemoveThumbnail(thumbnail);
            }
        }
Example #5
0
        public void SetCoverArt(ArtworkFormat format, byte[] data)
        {
            Thumbnail thumbnail = GetThumbnail(format, true);

            thumbnail.SetData(data);

            record.HasArtwork   = true;
            record.ArtworkCount = 1; // this is actually for artwork in mp3 tags, but it seems to be needed anyway
        }
Example #6
0
 internal string GetThumbPath(ArtworkFormat format)
 {
     if (isPhoto)
     {
         return(String.Format("{0}{2}Photos{2}Thumbs{2}F{1}_1.ithmb", device.VolumeInfo.MountPoint, format.CorrelationId, Path.DirectorySeparatorChar));
     }
     else
     {
         return(String.Format("{0}{2}Artwork{2}F{1}_1.ithmb", device.ControlPath, format.CorrelationId, Path.DirectorySeparatorChar));
     }
 }
Example #7
0
        public Thumbnail LookupThumbnail(ArtworkFormat format)
        {
            foreach (Thumbnail thumbnail in thumbnails)
            {
                if (thumbnail.Format.Equals(format))
                {
                    return(thumbnail);
                }
            }

            return(null);
        }
Example #8
0
        public byte[] GetCoverArt(ArtworkFormat format)
        {
            Thumbnail thumbnail = GetThumbnail(format, false);

            if (thumbnail == null)
            {
                return(null);
            }
            else
            {
                return(thumbnail.GetData());
            }
        }
Example #9
0
        public override bool Equals(object right)
        {
            ArtworkFormat a = right as ArtworkFormat;

            return
                (a != null &&
                 a.Usage == this.Usage &&
                 a.Width == this.Width &&
                 a.Height == this.Height &&
                 a.CorrelationId == this.CorrelationId &&
                 a.Size == this.Size &&
                 a.PixelFormat == this.PixelFormat &&
                 a.Rotation == this.Rotation);
        }
Example #10
0
        public static byte[] ToBytes(ArtworkFormat format, Gdk.Pixbuf pixbuf, out short horizontalPadding,
                                      out short verticalPadding)
        {
            horizontalPadding = 0;
            verticalPadding = 0;

            bool disposePixbuf = false;

            if (format.Rotation > 0) {
                pixbuf = Rotate (pixbuf, format.Rotation);
                disposePixbuf = true;
            }

            if (pixbuf.Height != format.Height || pixbuf.Width != format.Width) {
                int padX, padY;
                Gdk.Pixbuf scaled = Scale (pixbuf, format.Width, format.Height, out padX, out padY);

                horizontalPadding = (short) padX;
                verticalPadding = (short) padY;

                if (disposePixbuf) {
                    pixbuf.Dispose ();
                }

                pixbuf = scaled;
                disposePixbuf = true;
            }

            byte[] data = null;

            switch (format.PixelFormat) {
            case PixelFormat.Rgb565:
                data = PackRgb565 (pixbuf, false);
                break;
            case PixelFormat.Rgb565BE:
                data = PackRgb565 (pixbuf, true);
                break;
            case PixelFormat.IYUV:
                data = PackIYUV (pixbuf);
                break;
            default:
                throw new ApplicationException ("Unknown pixel format: " + format.PixelFormat);
            }

            if (disposePixbuf) {
                pixbuf.Dispose ();
            }

            return data;
        }
Example #11
0
        private void FindThumbnails(IList <ImageItemRecord> items, List <ImageNameRecord> existingNames,
                                    List <ImageNameRecord> newNames, List <ImageNameRecord> removedNames,
                                    ArtworkFormat format)
        {
            foreach (ImageItemRecord item in items)
            {
                if (existingNames != null)
                {
                    foreach (ImageNameRecord name in item.Names)
                    {
                        if (name.CorrelationId == format.CorrelationId)
                        {
                            existingNames.Add(name);
                        }
                    }
                }

                if (newNames != null)
                {
                    foreach (ImageNameRecord name in item.NewNames)
                    {
                        if (name.CorrelationId == format.CorrelationId)
                        {
                            newNames.Add(name);
                        }
                    }
                }

                if (removedNames != null)
                {
                    foreach (ImageNameRecord name in item.RemovedNames)
                    {
                        if (name.CorrelationId == format.CorrelationId)
                        {
                            removedNames.Add(name);
                        }
                    }
                }
            }
        }
Example #12
0
        private Thumbnail GetThumbnail(ArtworkFormat format, bool createNew)
        {
            FindCoverPhoto();

            if (coverPhoto == null)
            {
                if (!createNew)
                {
                    return(null);
                }


                if (db.ArtworkDatabase != null)
                {
                    coverPhoto = db.ArtworkDatabase.CreatePhoto();
                    coverPhoto.Record.TrackId = record.DatabaseId;
                    record.RightSideArtworkId = coverPhoto.Id;
                }
            }

            if (coverPhoto == null)
            {
                return(null);
            }

            Thumbnail thumbnail = coverPhoto.LookupThumbnail(format);

            if (thumbnail == null && createNew)
            {
                thumbnail        = coverPhoto.CreateThumbnail();
                thumbnail.Format = format;
                thumbnail.Width  = format.Width;
                thumbnail.Height = format.Height;
            }

            return(thumbnail);
        }
Example #13
0
 public byte[] GetCoverArt(ArtworkFormat format)
 {
     Thumbnail thumbnail = GetThumbnail (format, false);
     if (thumbnail == null)
         return null;
     else
         return thumbnail.GetData ();
 }
Example #14
0
        private void SaveThumbnails(List <ImageNameRecord> existingNames, List <ImageNameRecord> newNames,
                                    List <ImageNameRecord> removedNames, ArtworkFormat format)
        {
            string thumbPath = GetThumbPath(format);

            int fileLength = 0;

            if (existingNames.Count > 0)
            {
                ImageNameRecord last = Peek(existingNames);
                fileLength = last.ThumbnailOffset + last.ImageSize;
            }

            string thumbDir = Path.GetDirectoryName(thumbPath);

            if (!Directory.Exists(thumbDir))
            {
                Directory.CreateDirectory(thumbDir);
            }

            using (FileStream stream = File.Open(thumbPath, FileMode.OpenOrCreate)) {
                // process the removals, filling the gaps with new or existing records when possible
                foreach (ImageNameRecord removal in removedNames)
                {
                    // try to replace it with a new one
                    ImageNameRecord replacement = Pop(newNames);

                    if (replacement == null)
                    {
                        // no new ones, try to replace it with an existing one from the end of the file
                        ImageNameRecord record = Peek(existingNames);
                        if (record != null && record.ThumbnailOffset > removal.ThumbnailOffset)
                        {
                            replacement = record;

                            // it was the last one in the file, so we can reduce the file length
                            fileLength -= replacement.ImageSize;
                        }
                    }

                    if (replacement != null)
                    {
                        // write the replacement chunk into the old one's spot
                        byte[] data = GetNameData(replacement, stream);
                        replacement.ThumbnailOffset = removal.ThumbnailOffset;
                        replacement.SetData(stream, data);
                        replacement.Dirty = false;

                        existingNames.Sort(new ImageNameRecordSorter());
                    }
                    else if (fileLength > removal.ThumbnailOffset)
                    {
                        // we can't fill the gap, but it's ok to reduce the file length
                        fileLength = removal.ThumbnailOffset;
                    }
                }

                // process the additions by appending them to the file
                foreach (ImageNameRecord addition in newNames)
                {
                    byte[] data = GetNameData(addition, stream);
                    addition.ThumbnailOffset = fileLength;
                    addition.SetData(stream, data);
                    addition.Dirty = false;

                    fileLength += addition.ImageSize;
                }

                // lastly, flush any dirty existing records
                foreach (ImageNameRecord existing in existingNames)
                {
                    if (existing.Dirty)
                    {
                        byte[] data = GetNameData(existing, stream);
                        existing.SetData(stream, data);
                    }
                }

                stream.SetLength(fileLength);
            }
        }
Example #15
0
 public static byte[] ToBytes(ArtworkFormat format, Gdk.Pixbuf pixbuf)
 {
     short a, b;
     return ToBytes (format, pixbuf, out a, out b);
 }
Example #16
0
        public Thumbnail LookupThumbnail(ArtworkFormat format)
        {
            foreach (Thumbnail thumbnail in thumbnails) {
                if (thumbnail.Format.Equals (format)) {
                    return thumbnail;
                }
            }

            return null;
        }
Example #17
0
        private Thumbnail GetThumbnail(ArtworkFormat format, bool createNew)
        {
            FindCoverPhoto ();

            if (coverPhoto == null) {
                if (!createNew)
                    return null;

                if (db.ArtworkDatabase != null) {
                    coverPhoto = db.ArtworkDatabase.CreatePhoto ();
                    coverPhoto.Record.TrackId = record.DatabaseId;
                    record.RightSideArtworkId = coverPhoto.Id;
                }
            }

            if (coverPhoto == null) {
                return null;
            }

            Thumbnail thumbnail = coverPhoto.LookupThumbnail (format);
            if (thumbnail == null && createNew) {
                thumbnail = coverPhoto.CreateThumbnail ();
                thumbnail.Format = format;
                thumbnail.Width = format.Width;
                thumbnail.Height = format.Height;
            }

            return thumbnail;
        }
Example #18
0
        public void SetCoverArt(ArtworkFormat format, byte[] data)
        {
            Thumbnail thumbnail = GetThumbnail (format, true);
            thumbnail.SetData (data);

            record.HasArtwork = true;
            record.ArtworkCount = 1; // this is actually for artwork in mp3 tags, but it seems to be needed anyway
        }
Example #19
0
 public void RemoveCoverArt(ArtworkFormat format)
 {
     Thumbnail thumbnail = GetThumbnail (format, false);
     if (thumbnail != null) {
         coverPhoto.RemoveThumbnail (thumbnail);
     }
 }
Example #20
0
 public bool HasCoverArt(ArtworkFormat format)
 {
     return GetThumbnail (format, false) != null;
 }
Example #21
0
        public static byte[] ToBytes(ArtworkFormat format, Gdk.Pixbuf pixbuf)
        {
            short a, b;

            return(ToBytes(format, pixbuf, out a, out b));
        }
Example #22
0
 public bool HasCoverArt(ArtworkFormat format)
 {
     return(GetThumbnail(format, false) != null);
 }