Return a |BaseImageHeader| subclass instance that knows how to parse the
    headers of the image in *stream*.
549002
def _ImageHeaderFactory(stream):
    
    from docx.image import SIGNATURES

    def read_32(stream):
        stream.seek(0)
        return stream.read(32)

    header = read_32(stream)
    for cls, offset, signature_bytes in SIGNATURES:
        end = offset + len(signature_bytes)
        found_bytes = header[offset:end]
        if found_bytes == signature_bytes:
            return cls.from_stream(stream)
    raise UnrecognizedImageError
291770
def _parse_header(cls, header_proto, resource):
        
        header = header_proto()
        try:
            header_bytes = base64.b64decode(resource['header'])
            header.ParseFromString(header_bytes)
        except (KeyError, TypeError, ValueError, DecodeError):
            header = resource.get('header', None)
            LOGGER.error(
                'The validator sent a resource with %s %s',
                'a missing header' if header is None else 'an invalid header:',
                header or '')
            raise errors.ResourceHeaderInvalid()

        resource['header'] = cls._message_to_dict(header)
        return resource
1204853
def get_imagestreamtag_from_image(image):
    
    ret = image

    # Remove the registry part
    ret = strip_registry_from_image(image)

    # ImageStream names cannot contain '/'
    ret = ret.replace('/', '-')

    # If there is no ':' suffix value, add one
    if ret.find(':') == -1:
        ret += ":latest"

    return ret
185811
def header_from_raw_header_data(cls, raw_header):
        
        try:
            header = MessageHeader(*cls.header_struct.unpack(raw_header))
        except struct.error:
            raise Exception("Invalid message header received")
        return header
1271705
def getheader(self, header, default=None):
        '''
        
        '''
        if isinstance(header, str):
            return self.headers.get(header.lower(), default)
        return self.__rawheaders.get(header, default)
1006123
def baseimage(self, new_image):
        
        images = self.parent_images or [None]
        images[-1] = new_image
        self.parent_images = images
208092
def IHDR(self):
        
        match = lambda chunk: chunk.type_name == PNG_CHUNK_TYPE.IHDR  # noqa
        IHDR = self._find_first(match)
        if IHDR is None:
            raise InvalidImageStreamError('no ')
        return IHDR
1183602
def get_image(verbose=False):
  """"""
  base_data = tf.constant(image_data(verbose=verbose))
  base_image = tf.image.decode_image(base_data, channels=3)
  base_image.set_shape((IMAGE_HEIGHT, IMAGE_WIDTH, 3))
  parsed_image = tf.Variable(base_image, name='image', dtype=tf.uint8)
  return parsed_image
1276676
private static ImageFormat getWebpFormat(final byte[] imageHeaderBytes, final int headerSize) {
    Preconditions.checkArgument(WebpSupportStatus.isWebpHeader(imageHeaderBytes, 0, headerSize));
    if (WebpSupportStatus.isSimpleWebpHeader(imageHeaderBytes, 0)) {
      return DefaultImageFormats.WEBP_SIMPLE;
    }

    if (WebpSupportStatus.isLosslessWebpHeader(imageHeaderBytes, 0)) {
      return DefaultImageFormats.WEBP_LOSSLESS;
    }

    if (WebpSupportStatus.isExtendedWebpHeader(imageHeaderBytes, 0, headerSize)) {
      if (WebpSupportStatus.isAnimatedWebpHeader(imageHeaderBytes, 0)) {
        return DefaultImageFormats.WEBP_ANIMATED;
      }
      if (WebpSupportStatus.isExtendedWebpHeaderWithAlpha(imageHeaderBytes, 0)) {
        return DefaultImageFormats.WEBP_EXTENDED_WITH_ALPHA;
      }
      return DefaultImageFormats.WEBP_EXTENDED;
    }

    return ImageFormat.UNKNOWN;
  }
265846
def read_nih_image_header(fh, byteorder, dtype, count, offsetsize):
    """"""
    a = fh.read_record(TIFF.NIH_IMAGE_HEADER, byteorder=byteorder)
    a = a.newbyteorder(byteorder)
    a = recarray2dict(a)
    a['XUnit'] = a['XUnit'][:a['XUnitSize']]
    a['UM'] = a['UM'][:a['UMsize']]
    return a
206176
@Override
    public ImageHeader readHeader(InputStream input) throws IOException
    {
        final long toSkip = 8L;
        final boolean bigEndian = 'M' == input.read();
        checkSkippedError(input.skip(HEADER_SIZE - 1L), HEADER_SIZE - 1);
        final int ifd = readInt(input, 4, bigEndian);
        input.skip(ifd - toSkip);
        // checkSkippedError(skipped, ifd - toSkip); fail when reading from JAR, not needed
        final int entries = readInt(input, 2, bigEndian);

        int width = -1;
        int height = -1;
        for (int i = 1; i <= entries; i++)
        {
            final int tag = readInt(input, 2, bigEndian);
            final int fieldType = readInt(input, 2, bigEndian);
            readInt(input, VAL_OFFSET_BYTES, bigEndian);
            final int valOffset;
            if (VAL_OFFSET_FIELD_1 == fieldType || VAL_OFFSET_FIELD_2 == fieldType)
            {
                valOffset = readInt(input, 2, bigEndian);
                final long skipped = input.skip(2);
                checkSkippedError(skipped, 2);
            }
            else
            {
                valOffset = readInt(input, VAL_OFFSET_BYTES, bigEndian);
            }
            if (TAG_WIDTH == tag)
            {
                width = valOffset;
            }
            else if (TAG_HEIGHT == tag)
            {
                height = valOffset;
            }
            if (-1 != width && -1 != height)
            {
                return new ImageHeaderModel(width, height, ImageFormat.TIFF);
            }
        }
        throw new IOException(ERROR_TIFF);
    }
181154
@Override
    public ImageHeader readHeader(InputStream input) throws IOException
    {
        final int toSkip = 15 + 3;
        long skipped = input.skip(toSkip);
        checkSkippedError(skipped, toSkip);

        final int width = readInt(input, 2, false);
        skipped = input.skip(2);
        checkSkippedError(skipped, 2);

        final int height = readInt(input, 2, false);

        return new ImageHeaderModel(width, height, ImageFormat.BMP);
    }
176536
def from_path(klass, path, header):
        
        path = str(path)
        use_bgzf = False  # we already interpret path
        if path.endswith(".gz"):
            f = bgzf.BgzfWriter(filename=path)
        else:
            f = open(path, "wt")
        return klass.from_stream(f, header, path, use_bgzf=use_bgzf)
309828
def parse_http_header(header_line):
    

    header_line = header_line.decode().strip()
    col_idx = header_line.find(':')

    if col_idx < 1:
        raise BadHttpHeaderError('Bad header: {}'.format(repr(header_line)))

    key = header_line[0:col_idx].strip()
    value = header_line[(col_idx+1):].strip()
    return HttpHeader(key=key, value=value)
647389
def _readStreamHeader(self):
        
        (magic, version) = self._readStruct(">HH")
        if magic != self.STREAM_MAGIC or version != self.STREAM_VERSION:
            raise IOError(
                "The stream is not java serialized object. "
                "Invalid stream header: {0:04X}{1:04X}".format(magic, version)
            )
1112187
def image_to_base64(self, image):
        
        if isinstance(image, file_):
            return base64.b64encode(image.read())
        elif isinstance(image, basestring):
            if image.startswith("http"):
                # it's URL
                return base64.b64encode(requests.get(image).content)
            # it's path
            with open(image) as f:
                return base64.b64encode(f.read())

        raise ValueError("Unrecognizable image param: it must one of"
                         " file object, path or URL, not %s" % type(image))
47380
def parse_header(options = {})
      check_header
      @hdr = parse_basic_header
      @extended_header = parse_extended_header

      # Optional image gathering
      read_image if options[:image]
      get_image_narray(@image_rubyarray, @hdr['dim']) if options[:narray]

      @success = true
    end