docstr: Parse image from file-like object containing ico file data
docstr_tok: ["Parse","image","from","file-like","object","containing","ico","file","data"]
code: def __init__(self, buf):
      """
      Parse image from file-like object containing ico file data
      """
  
      # check magic
      s = buf.read(6)
      if not _accept(s):
          msg = "not an ICO file"
          raise SyntaxError(msg)
  
      self.buf = buf
      self.entry = []
  
      # Number of items in file
      self.nb_items = i16(s, 4)
  
      # Get headers for each item
      for i in range(self.nb_items):
          s = buf.read(16)
  
          icon_header = {
              "width": s[0],
              "height": s[1],
              "nb_color": s[2],  # No. of colors in image (0 if >=8bpp)
              "reserved": s[3],
              "planes": i16(s, 4),
              "bpp": i16(s, 6),
              "size": i32(s, 8),
              "offset": i32(s, 12),
          }
  
          # See Wikipedia
          for j in ("width", "height"):
              if not icon_header[j]:
                  icon_header[j] = 256
  
          # See Wikipedia notes about color depth.
          # We need this just to differ images with equal sizes
          icon_header["color_depth"] = (
              icon_header["bpp"]
              or (
                  icon_header["nb_color"] != 0
                  and ceil(log(icon_header["nb_color"], 2))
              )
              or 256
          )
  
          icon_header["dim"] = (
              icon_header["width"],
              icon_header["height"],
          )
          icon_header["square"] = (
              icon_header["width"] * icon_header["height"]
          )
  
          self.entry.append(icon_header)
  
      self.entry = sorted(self.entry, key=lambda x: x["color_depth"])
      # ICO images are usually squares
      # self.entry = sorted(self.entry, key=lambda x: x['width'])
      self.entry = sorted(self.entry, key=lambda x: x["square"])
      self.entry.reverse()
  
imports: import warnings
  from io import BytesIO
  from math import ceil, log
  from .None import BmpImagePlugin, Image, ImageFile, PngImagePlugin
  from ._binary import i16le
  from ._binary import i32le
  from ._binary import o8
  from ._binary import o16le
  from ._binary import o32le
label_desc: Use image node_id 1 to create a new IcoFile object  with example: obj = IcoFile(buf)