Fixed flattening/unflattening BPictures. Unfortunately, this does not fix bug #1014.
Note: endianness is completely ignored. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20084 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku Inc.
|
* Copyright 2001-2007, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -9,15 +9,15 @@
|
|||||||
//! BPicture records a series of drawing instructions that can be "replayed" later.
|
//! BPicture records a series of drawing instructions that can be "replayed" later.
|
||||||
|
|
||||||
|
|
||||||
|
#include <AppServerLink.h>
|
||||||
|
#include <PicturePlayer.h>
|
||||||
|
#include <ServerProtocol.h>
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Picture.h>
|
#include <Picture.h>
|
||||||
|
|
||||||
#include <AppServerLink.h>
|
|
||||||
#include <PicturePlayer.h>
|
|
||||||
#include <ServerProtocol.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -262,59 +262,78 @@ BPicture::Play(void **callBackTable, int32 tableEntries, void *user)
|
|||||||
status_t
|
status_t
|
||||||
BPicture::Flatten(BDataIO *stream)
|
BPicture::Flatten(BDataIO *stream)
|
||||||
{
|
{
|
||||||
|
// TODO: what about endianess?
|
||||||
|
|
||||||
if (!assert_local_copy())
|
if (!assert_local_copy())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
const picture_header header = { 2, 0 };
|
const picture_header header = { 2, 0 };
|
||||||
status_t status = stream->Write(&header, sizeof(header));
|
ssize_t bytesWritten = stream->Write(&header, sizeof(header));
|
||||||
if (status < B_OK)
|
if (bytesWritten < B_OK)
|
||||||
return status;
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)sizeof(header))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
int32 count = extent->CountPictures();
|
int32 count = extent->CountPictures();
|
||||||
if (count > 0) {
|
bytesWritten = stream->Write(&count, sizeof(count));
|
||||||
status = stream->Write(&count, sizeof(count));
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)sizeof(count))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
status_t status = extent->PictureAt(i)->Flatten(stream);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
for (int32 i = 0; i < extent->CountPictures(); i++) {
|
|
||||||
status = extent->PictureAt(i)->Flatten(stream);
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 size = extent->Size();
|
int32 size = extent->Size();
|
||||||
status = stream->Write(&size, sizeof(size));
|
bytesWritten = stream->Write(&size, sizeof(size));
|
||||||
if (status == B_OK)
|
if (bytesWritten < B_OK)
|
||||||
status = stream->Write(extent->Data(), extent->Size());
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)sizeof(size))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
return status;
|
bytesWritten = stream->Write(extent->Data(), size);
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != size)
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPicture::Unflatten(BDataIO *stream)
|
BPicture::Unflatten(BDataIO *stream)
|
||||||
{
|
{
|
||||||
|
// TODO: clear current picture data?
|
||||||
|
|
||||||
picture_header header;
|
picture_header header;
|
||||||
if (stream->Read(&header, sizeof(header)) < (ssize_t)sizeof(header)
|
ssize_t bytesRead = stream->Read(&header, sizeof(header));
|
||||||
|
if (bytesRead < B_OK)
|
||||||
|
return bytesRead;
|
||||||
|
if (bytesRead != (ssize_t)sizeof(header)
|
||||||
|| header.magic1 != 2 || header.magic2 != 0)
|
|| header.magic1 != 2 || header.magic2 != 0)
|
||||||
return B_ERROR;
|
return B_BAD_TYPE;
|
||||||
|
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
status_t status = stream->Read(&count, sizeof(count));
|
bytesRead = stream->Read(&count, sizeof(count));
|
||||||
if (status < B_OK)
|
if (bytesRead < B_OK)
|
||||||
return status;
|
return bytesRead;
|
||||||
|
if (bytesRead != (ssize_t)sizeof(count))
|
||||||
|
return B_BAD_DATA;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
BPicture *pic = new BPicture;
|
BPicture* picture = new BPicture;
|
||||||
status = pic->Unflatten(stream);
|
status_t status = picture->Unflatten(stream);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
extent->AddPicture(pic);
|
extent->AddPicture(picture);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = extent->ImportData(stream);
|
status_t status = extent->ImportData(stream);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user