Exemplo n.º 1
0
ERRORCODE SplitArray::read_new_data(StorageDevicePtr device)
{
    ERRORCODE error = ERRORCODE_None;

    SHORT nStoredElemSize;

    if ((error = device->read(&nStoredElemSize, sizeof (nStoredElemSize))) != ERRORCODE_None)
    {
        return error;
    }

    Array NewArray(nStoredElemSize);
    if ((error = NewArray.read(device)) != ERRORCODE_None)
    {
        return error;
    }

    if (NewArray.count() != count())
    {
        return ERRORCODE_TypeMismatch;
    }

    LPBYTE lpSrcData, lpDestData;
    lpDestData = (LPBYTE)data + OldSize();
    lpSrcData = (LPBYTE)NewArray.get_element(0);

    for (int i = 0; i < count(); i++)
    {
        memcpy(lpDestData, lpSrcData, nStoredElemSize);
        lpDestData += NewSize();
        lpSrcData += nStoredElemSize;
    }
    return error;
}
Exemplo n.º 2
0
ERRORCODE Array::read(StorageDevicePtr device)
{
	ERRORCODE error;

/* Free the data if there is any. */

	if (data != NULL)
	{
		system_heap->free(data);
		data = NULL;
	}

/* Read the element count. */

	if ((error = device->read(&element_count, sizeof(element_count))) != ERRORCODE_None)
	{
		element_count = 0;
		return error;
	}

/* Read the block. */
	
	if (element_count != 0)
	{
		if ((error = device->read_block(array_byte_size(), &data)) != ERRORCODE_None)
		{
			element_count = 0;
		}
	}

	m_nBlockCount = element_count;

	return error;
}
Exemplo n.º 3
0
ERRORCODE ObjectLayoutRecord::ReadData(StorageDevicePtr device)
{
	SHORT count;
	ERRORCODE error;

	if ((error = device->read(&record, sizeof(record))) == ERRORCODE_None
			&& (error = device->read_cstring(m_csName)) == ERRORCODE_None
			&& (error = device->read(&count, sizeof(count))) == ERRORCODE_None)
	{
		LayoutElement element;		/* For transfer. */

	/* Read the elements. */

		elements.empty();

		while (count-- > 0)
		{
			LayoutElementPtr pelement;

		/* Make sure we can read the element before allocating. */

			if ((error = element.read(device)) != ERRORCODE_None)
			{
				return error;
			}

		/* Create a new layout element. */

			if ((pelement = new LayoutElement) == NULL)
			{
				return ERRORCODE_Memory;
			}
			pelement->record = element.record;

		/* Add it to the end of the list. */

			elements.append(pelement);
		}
	}
	return error;
}
Exemplo n.º 4
0
ERRORCODE WMFHelper::init(GRAPHIC_CREATE_STRUCT_PTR gcs)
{
	ERRORCODE error = ERRORCODE_None;

/* We need a file to read. */

	StorageDevicePtr pSource;
	ReadOnlyFile file;

	if (gcs == NULL || (pSource = gcs->pSourceDevice) == NULL)
	{
	/* Go directly to disk. */
		file.set_name(graphic->m_csFileName);
		pSource = &file;
	}

/* Read the header. */

	ALDUS_WMF_HEADER header;

	if ((error = pSource->read(&header, sizeof(header))) != ERRORCODE_None)
	{
		return error;
	}

	// Fill out the header.
	if (header.key == ALDUS_WMF_KEY)
	{
		graphic->record.x_size = header.bbox.right - header.bbox.left;
		graphic->record.y_size = header.bbox.bottom - header.bbox.top;
		graphic->record.x_resolution = \
			graphic->record.y_resolution = header.inch;
	}
	else
	{
		graphic->record.x_size = 300*2;
		graphic->record.y_size = 300*2;
		graphic->record.x_resolution = \
			graphic->record.y_resolution = 300;
	}

	graphic->record.storage = GRAPHIC_STORAGE_FILE;

	record.m_type = 0;

	return error;
}
Exemplo n.º 5
0
ERRORCODE near HALOHelper::read_halo_header(StorageDevicePtr file,
        LPWORD dots, LPWORD lines,
        LPWORD x_res, LPWORD y_res)
{
    HALO_HEADER header;
    ERRORCODE error;

    if ((error = file->read(&header, sizeof(header))) == ERRORCODE_None)
    {
        *dots = header.xsize;
        *lines = header.ysize;

        *x_res = halo_x_resolution;
        *y_res = halo_y_resolution;
    }
    return error;
}
Exemplo n.º 6
0
ERRORCODE PSDHelper::init(GRAPHIC_CREATE_STRUCT_PTR gcs)
{
	ERRORCODE error = ERRORCODE_None;

/* We need a file to read. */

	StorageDevicePtr pSource;
	ReadOnlyFile file;

	if (gcs == NULL || (pSource = gcs->pSourceDevice) == NULL)
	{
	/* Go directly to disk. */
		file.set_name(graphic->m_csFileName);
		file.set_read_buffer(4096);
		pSource = &file;
	}

/* Read the header. */

	PSDHeader Header;
	TRY
	{
		if ((error = pSource->read(&Header, sizeof(Header))) != ERRORCODE_None)
		{
			ThrowErrorcodeException(error);
		}

		// Swap everything.
		swap_word(&Header.m_wChannels);
		swap_dword(&Header.m_dwRows);
		swap_dword(&Header.m_dwColumns);
		swap_word(&Header.m_wDepth);
		swap_word(&Header.m_wMode);

		// Validate that we support this number of channels.
		if (Header.m_wChannels > MAX_CHANNELS)
		{
			ThrowErrorcodeException(ERRORCODE_IllegalType);
		}

		// Fill out the header.
		graphic->record.x_size = (USHORT)Header.m_dwColumns;
		graphic->record.y_size = (USHORT)Header.m_dwRows;
		graphic->record.x_resolution = 200;		// Default for now...
		graphic->record.y_resolution = 200;		// ...read later
		graphic->record.storage = GRAPHIC_STORAGE_FILE;

		// Fill out our info.
		m_Record.m_wChannels = Header.m_wChannels;
		m_Record.m_wDepth = Header.m_wDepth;
		m_Record.m_wMode = Header.m_wMode;

		// Initialize the start of line variables.

#if 0
      for (int i = 0; i < 9; i++)
		{
			m_Record.m_Lines[i].line = MulDiv((int)Header.m_dwRows, i, 8);
			m_Record.m_Lines[i].offset = 0L;
		}
#endif

		DWORD dwSize;

		//
		// Process the color mode data section.
		//
		// Read the section size.
		if ((error = pSource->read(&dwSize, sizeof(dwSize))) != ERRORCODE_None)
		{
			ThrowErrorcodeException(error);
		}
		swap_dword(&dwSize);

		pSource->tell(&m_Record.m_lColorDataSection);

		// Skip to the next section.
		pSource->seek(m_Record.m_lColorDataSection + (ST_DEV_POSITION)dwSize, ST_DEV_SEEK_SET);

		//
		// Process the image resources section.
		//
		// Read the section size.
		if ((error = pSource->read(&dwSize, sizeof(dwSize))) != ERRORCODE_None)
		{
			ThrowErrorcodeException(error);
		}
		swap_dword(&dwSize);

		pSource->tell(&m_Record.m_lImageResourcesSection);

		// Skip to the next section.
		pSource->seek(m_Record.m_lImageResourcesSection + (ST_DEV_POSITION)dwSize, ST_DEV_SEEK_SET);

		//
		// Process the layer and mask section.
		//
		// Read the section size.
		if ((error = pSource->read(&dwSize, sizeof(dwSize))) != ERRORCODE_None)
		{
			ThrowErrorcodeException(error);
		}
		swap_dword(&dwSize);

		pSource->tell(&m_Record.m_lLayerMaskSection);

		//
		// Read the image resources we care about.
		//

		// Read the resolution information.
		ReadResolution(pSource);

		// Skip to the next section.
		pSource->seek(m_Record.m_lLayerMaskSection + (ST_DEV_POSITION)dwSize, ST_DEV_SEEK_SET);

		//
		// Process the image data section.
		//

		pSource->tell(&m_Record.m_lImageDataSection);

		// Read the compression value.
		if ((error = pSource->read(&m_Record.m_wCompression, sizeof(m_Record.m_wCompression))) != ERRORCODE_None)
		{
			ThrowErrorcodeException(error);
		}

		//
		// Compute the sizes of all data channels.
		//

		if (m_Record.m_wCompression)
		{
			//
			// Compression requires special handling.
			//

			// We are compressed; read the compression counts.
			LPWORD pCounts = NULL;		// Needs to be NULL at start.
			if ((error = ReadCompressionCounts(pSource, pCounts)) != ERRORCODE_None)
			{
				ThrowErrorcodeException(error);
			}

			// Run through all channels and compute compressed sizes.
			LPWORD p = pCounts;
			int nRows = graphic->record.y_size;
			for (WORD wChannel = 0; wChannel < m_Record.m_wChannels; wChannel++)
			{
				// Compute the size of this channel.
				long	lChannelSize = 0;
				for (int nRow = 0; nRow < nRows; nRow++)
				{
					lChannelSize += *p++;
				}

				// Save the channel size in the record.
				m_Record.m_lChannelSizes[wChannel] = lChannelSize;
			}
			// Free the count data.
			GlobalFreePtr(pCounts);
		}
		else
		{
			//
			// Not compressed. All channels are the same size.
			//

			DWORD dwChannelSize = Header.m_dwColumns * Header.m_dwRows;

			// Set them all to the same size.
			for (WORD wChannel = 0; wChannel < m_Record.m_wChannels; wChannel++)
			{
				m_Record.m_lChannelSizes[wChannel] = (long)dwChannelSize;
			}
		}
	}
	CATCH(CErrorcodeException, e)
	{
		error = e->m_error;
	}
	AND_CATCH_ALL(e)
	{
		error = ERRORCODE_IntError;
	}
	END_CATCH_ALL

	return error;
}
Exemplo n.º 7
0
ERRORCODE LayoutElement::read(StorageDevicePtr device)
{
	return device->read(&record, sizeof(record));
}
Exemplo n.º 8
0
ERRORCODE CTIFFInfo::read(StorageDevicePtr device)
{
	return device->read(&m_Info, sizeof(m_Info));
}