Exemplo n.º 1
0
ST_DEV_IO_SIZE PSDHelper::size(StorageDevicePtr device)
{
	return device->size_record(sizeof(m_Record));
}
Exemplo n.º 2
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.º 3
0
ERRORCODE PSDHelper::read(StorageDevicePtr device)
{
	return device->read_record(&m_Record, sizeof(m_Record));
}
Exemplo n.º 4
0
ERRORCODE PSDHelper::write(StorageDevicePtr device)
{
	return device->write_record(&m_Record, sizeof(m_Record));
}
Exemplo n.º 5
0
ERRORCODE HALOHelper::read(StorageDevicePtr device)
{
    return device->read_record(&record, sizeof(record));
}
Exemplo n.º 6
0
ERRORCODE HALOHelper::write(StorageDevicePtr device)
{
    return device->write_record(&record, sizeof(record));
}
Exemplo n.º 7
0
ERRORCODE LayoutElement::read(StorageDevicePtr device)
{
	return device->read(&record, sizeof(record));
}
Exemplo n.º 8
0
ERRORCODE LayoutElement::write(StorageDevicePtr device)
{
	return device->write(&record, sizeof(record));
}
Exemplo n.º 9
0
ST_MAN_SIZE CalendarInfoRecord::SizeofData(StorageDevicePtr device)
{
	return device->size_record(sizeof(record));
}
Exemplo n.º 10
0
ST_MAN_SIZE PatternObject::size_data(StorageDevicePtr device)
{
	return INHERITED::size_data(device) + device->size_record(sizeof(precord));
}
Exemplo n.º 11
0
ERRORCODE CalendarInfoRecord::WriteData(StorageDevicePtr device)
{
	return device->write_record(&record, sizeof(record));
}
Exemplo n.º 12
0
ERRORCODE CalendarInfoRecord::ReadData(StorageDevicePtr device)
{
	return device->read_record(&record, sizeof(record));
}
Exemplo n.º 13
0
ERRORCODE CTIFFInfo::write(StorageDevicePtr device)
{
	return device->write(&m_Info, sizeof(m_Info));
}
Exemplo n.º 14
0
ERRORCODE CTIFFInfo::read(StorageDevicePtr device)
{
	return device->read(&m_Info, sizeof(m_Info));
}
Exemplo n.º 15
0
ST_MAN_SIZE RectangleObject::size_data(StorageDevicePtr device)
{
	return INHERITED::size_data(device) + device->size_record(sizeof(m_RectRecord));
}