func LoadCUR(cur io.ReadSeeker) (*Cursor, error) {
	hdr := cursorDirHeader{}
	if err := binaryRead(cur, &hdr); err != nil {
		return nil, err
	}

	if hdr.Type != 2 || hdr.Reserved != 0 {
		return nil, errors.New(errNotCUR)
	}

	entries := make([]cursorFileDirEntry, hdr.Count)
	if err := binaryRead(cur, entries); err != nil {
		return nil, err
	}

	cursor := &Cursor{}
	for _, e := range entries {
		// Arbitrary limit: no more than 10MB per image, so we can blindly allocate bytes and try to read them.
		if e.BytesInRes > 0xA00000 {
			return nil, errors.New(errImageLengthTooBig)
		}
		if _, err := cur.Seek(int64(e.ImageOffset), io.SeekStart); err != nil {
			return nil, err
		}
		img := make([]byte, e.BytesInRes)
		if err := readFull(cur, img); err != nil {
			return nil, err
		}

		planes, bitCount, err := readDIBBitCount(img)
		if err != nil {
			return nil, err
		}

		cursor.images = append(cursor.images, cursorImage{
			info: cursorInfo{
				Width:      uint16(e.Width-1) + 1,
				Height:     uint16(e.Height-1) + 1,
				Planes:     planes,
				BitCount:   bitCount,
				BytesInRes: e.BytesInRes,
			},
			hotSpot: HotSpot{
				X: e.XHotSpot,
				Y: e.YHotSpot,
			},
			image: img,
		})
	}

	return cursor, nil
}
// LoadCUR loads a CUR file and returns a cursor, ready to embed in a resource set.
LoadCUR loads a CUR file and returns a cursor, ready to embed in a resource set.
// LoadCUR loads a CUR file and returns a cursor ready to embed in a resource set .
func LoadCUR(cur io.ReadSeeker) (*Cursor, error) {
	hdr := cursorDirHeader{}
	if err := binaryRead(cur, &hdr); err != nil {
		return nil, err
	}
	if hdr.Type != 2 || hdr.Reserved != 0 {
		return nil, errors.New(errNotCUR)
	}
	entries := make([]cursorFileDirEntry, hdr.Count)
	if err := binaryRead(cur, entries); err != nil {
		return nil, err
	}
	cursor := &Cursor{}
	for _, e := range entries {
		if e.BytesInRes > 0xA00000 {
			return nil, errors.New(errImageLengthTooBig)
		}
		if _, err := cur.Seek(int64(e.ImageOffset), io.SeekStart); err != nil {
			return nil, err
		}
		img := make([]byte, e.BytesInRes)
		if err := readFull(cur, img); err != nil {
			return nil, err
		}
		planes, bitCount, err := readDIBBitCount(img)
		if err != nil {
			return nil, err
		}
		cursor.images = append(cursor.images, cursorImage{
			info: cursorInfo{
				Width:      uint16(e.Width-1) + 1,
				Height:     uint16(e.Height-1) + 1,
				Planes:     planes,
				BitCount:   bitCount,
				BytesInRes: e.BytesInRes,
			},
			hotSpot: HotSpot{
				X: e.XHotSpot,
				Y: e.YHotSpot,
			},
			image: img,
		})
	}
	return cursor, nil
}
func LoadCUR ( cur io . ReadSeeker ) ( * Cursor , error ) { hdr := cursorDirHeader { } if err := binaryRead ( cur , & hdr ) ; err != nil { return nil , err } if hdr . Type != 2 || hdr . Reserved != 0 { return nil , errors . New ( errNotCUR ) } entries := make ( [ ] cursorFileDirEntry , hdr . Count ) if err := binaryRead ( cur , entries ) ; err != nil { return nil , err } cursor := & Cursor { } for _ , e := range entries { if e . BytesInRes > 0xA00000 { return nil , errors . New ( errImageLengthTooBig ) } if _ , err := cur . Seek ( int64 ( e . ImageOffset ) , io . SeekStart ) ; err != nil { return nil , err } img := make ( [ ] byte , e . BytesInRes ) if err := readFull ( cur , img ) ; err != nil { return nil , err } planes , bitCount , err := readDIBBitCount ( img ) if err != nil { return nil , err } cursor . images = append ( cursor . images , cursorImage { info : cursorInfo { Width : uint16 ( e . Width - 1 ) + 1 , Height : uint16 ( e . Height - 1 ) + 1 , Planes : planes , BitCount : bitCount , BytesInRes : e . BytesInRes , } , hotSpot : HotSpot { X : e . XHotSpot , Y : e . YHotSpot , } , image : img , } ) } return cursor , nil }
LoadCUR loads a CUR file and returns a cursor, ready to embed in a resource set.
LoadCUR loads a CUR file and returns a cursor ready to embed in a resource set .
// Arbitrary limit: no more than 10MB per image, so we can blindly allocate bytes and try to read them.