xref: /haiku/src/add-ons/translators/wonderbrush/WonderBrushImage.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright 2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "WonderBrushImage.h"
10 
11 #include "Canvas.h"
12 
13 WonderBrushImage::WonderBrushImage()
14 	: fArchive((uint32)0)
15 {
16 }
17 
18 
19 WonderBrushImage::~WonderBrushImage()
20 {
21 }
22 
23 
24 status_t
25 WonderBrushImage::SetTo(BPositionIO* stream)
26 {
27 	if (!stream)
28 		return B_BAD_VALUE;
29 
30 	// try to load the stream as a BMessage and probe it
31 	// to see whether it might be a WonderBrush image
32 	fArchive.MakeEmpty();
33 	status_t status = fArchive.Unflatten(stream);
34 	if (status < B_OK)
35 		return status;
36 
37 	if (fArchive.HasMessage("layer") && fArchive.HasRect("bounds"))
38 		return B_OK;
39 
40 	return B_ERROR;
41 }
42 
43 
44 BBitmap*
45 WonderBrushImage::Bitmap() const
46 {
47 	Canvas canvas(BRect(0.0, 0.0, -1.0, -1.0));
48 
49 	if (canvas.Unarchive(&fArchive) < B_OK)
50 		return NULL;
51 
52 	return canvas.Bitmap();
53 }
54 
55 
56