1/*
2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef ICO_H
6#define ICO_H
7
8
9#include <GraphicsDefs.h>
10#include <BufferIO.h>
11#include <TranslatorFormats.h>
12
13class BMessage;
14
15
16namespace ICO {
17
18// All ICO structures are written in little endian format
19
20enum ico_type {
21	kTypeIcon	= 1,
22	kTypeCursor	= 2,
23};
24
25struct ico_header {
26	uint16	reserved;
27	uint16	type;
28	uint16	entry_count;
29
30	bool IsValid() const;
31	void SwapToHost();
32	void SwapFromHost();
33} _PACKED;
34
35struct ico_dir_entry {
36	uint8	width;
37	uint8	height;
38	uint8	color_count;
39	uint8	reserved;
40
41	uint16	planes;
42	uint16	bits_per_pixel;
43	uint32	size;
44	uint32	offset;
45
46	bool IsValid() const { return bits_per_pixel <= 24; }
47	void SwapToHost();
48	void SwapFromHost();
49} _PACKED;
50
51struct ico_bitmap_header {
52	uint32	size;				// size of this structure
53	uint32	width;
54	uint32	height;
55	uint16	planes;
56	uint16	bits_per_pixel;		// 1, 4, 8, 16, or 24 bits per pixel
57	uint32	compression;
58	uint32	image_size;
59	uint32	x_pixels_per_meter;	// aspect ratio
60	uint32	y_pixels_per_meter;
61	uint32	colors_used;		// number of actually used colors
62	uint32	important_colors;	// number of important colors (zero = all)
63
64	bool IsValid() const;
65	void SwapToHost();
66	void SwapFromHost();
67} _PACKED;
68
69
70// More or less accidently, ICO colors are in the same format as
71// the color information in B_RGBA32 bitmaps
72
73struct rgba32_color {
74	uint8	blue;
75	uint8	green;
76	uint8	red;
77	uint8	alpha;
78
79	inline bool
80	operator==(const rgba32_color& other) const
81	{
82		return red == other.red && green == other.green && blue == other.blue;
83	}
84};
85
86extern bool is_valid_size(int32 size);
87extern status_t identify(BMessage *settings, BPositionIO &stream, uint8 &type, int32 &bitsPerPixel);
88extern status_t convert_ico_to_bits(BMessage *settings, BPositionIO &source, BPositionIO &target);
89extern status_t convert_bits_to_ico(BMessage *settings, BPositionIO &source,
90					TranslatorBitmap &bitsHeader, BPositionIO &target);
91
92}	// namespace ICO
93
94#endif	/* ICO_H */
95