Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*max@home*/
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef NOTE
Toshihiro Shimizu 890ddd
ConvertOneValue2Enum()
Toshihiro Shimizu 890ddd
		potrebbe essere fonte di errore se DCItemSize[one_value.ItemType] > DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di one_value.Item
Toshihiro Shimizu 890ddd
																			ConvertEnumeration2Range()
Toshihiro Shimizu 890ddd
																				potrebbe restituire valori di StepSize non appropriati se
Toshihiro Shimizu 890ddd
																			enumeration.ItemType e TW_FIX32
Toshihiro Shimizu 890ddd
																			potrebbe restituire valori MinValue non corretti se DCItemSize[xxx.ItemType] > DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di xxx.Item
Toshihiro Shimizu 890ddd
																																						   ConvertEnum2OneValue ritorna(ovviamente) solo il valore corrente
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <assert.h></assert.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttwain_capability.h"
Toshihiro Shimizu 890ddd
#include "ttwain_conversion.h"
Toshihiro Shimizu 890ddd
#include "ttwain_error.h"
Toshihiro Shimizu 890ddd
#include "ttwain_state.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttwain_global_def.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka d4642c
/*---------------------------------------------------------------------------*/
Shinya Kitaoka d4642c
static const size_t DCItemSize[13] =
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		sizeof(TW_INT8),
Toshihiro Shimizu 890ddd
		sizeof(TW_INT16),
Toshihiro Shimizu 890ddd
		sizeof(TW_INT32),
Toshihiro Shimizu 890ddd
		sizeof(TW_UINT8),
Toshihiro Shimizu 890ddd
		sizeof(TW_UINT16),
Toshihiro Shimizu 890ddd
		sizeof(TW_UINT32),
Toshihiro Shimizu 890ddd
		sizeof(TW_BOOL),
Toshihiro Shimizu 890ddd
		sizeof(TW_FIX32),
Toshihiro Shimizu 890ddd
		sizeof(TW_FRAME),
Toshihiro Shimizu 890ddd
		sizeof(TW_STR32),
Toshihiro Shimizu 890ddd
		sizeof(TW_STR64),
Toshihiro Shimizu 890ddd
		sizeof(TW_STR128),
Toshihiro Shimizu 890ddd
		sizeof(TW_STR255),
Toshihiro Shimizu 890ddd
}; /* see twain.h */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
#define TWON_TWON(TYPE1, TYPE2) (((TYPE1) << 8) | (TYPE2))
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range);
Toshihiro Shimizu 890ddd
static int ConvertEnumeration2Range(TW_ENUMERATION enumeration, TW_RANGE *range);
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Enum(TW_ONEVALUE one_value, TW_ENUMERATION *tw_enum);
Toshihiro Shimizu 890ddd
static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum, TW_ONEVALUE *one_value);
Toshihiro Shimizu 890ddd
static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems);
Toshihiro Shimizu 890ddd
static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Toshihiro Shimizu 890ddd
								TUINT32 *cont_size);
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_GetCap(TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Toshihiro Shimizu 890ddd
				  TUINT32 *cont_size)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TTWAIN_GetCapability(MSG_GET, cap_id, conType, data, cont_size);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_GetCapCurrent(TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Toshihiro Shimizu 890ddd
						 TUINT32 *cont_size)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TTWAIN_GetCapability(MSG_GETCURRENT, cap_id, conType, data, cont_size);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_GetCapQuery(TW_UINT16 cap_id, TW_UINT16 *pattern)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int rc;
Toshihiro Shimizu 890ddd
	TW_ONEVALUE data;
Toshihiro Shimizu 890ddd
	rc = TTWAIN_GetCapability(MSG_QUERYSUPPORT, cap_id, TWON_ONEVALUE, &data, 0);
Toshihiro Shimizu 890ddd
	if (!rc)
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
	*pattern = (TW_UINT16)data.Item;
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Toshihiro Shimizu 890ddd
								TUINT32 *cont_size)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TW_CAPABILITY cap;
Toshihiro Shimizu 890ddd
	void *pv;
Toshihiro Shimizu 890ddd
	TW_ENUMERATION *my_enum;
Toshihiro Shimizu 890ddd
	TW_ARRAY *my_array;
Toshihiro Shimizu 890ddd
	TW_ONEVALUE *my_one;
Toshihiro Shimizu 890ddd
	TW_RANGE *my_range;
Toshihiro Shimizu 890ddd
	TUINT32 size = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!data && !cont_size)
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) {
Toshihiro Shimizu 890ddd
		TTWAIN_ErrorBox("Attempt to get capability value below State 4.");
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/* Fill in capability structure */
Toshihiro Shimizu 890ddd
	cap.Cap = cap_id;			   /* capability id */
Toshihiro Shimizu 890ddd
	cap.ConType = TWON_DONTCARE16; /* favorite type of container (should be ignored...) */
Toshihiro Shimizu 890ddd
	cap.hContainer = NULL;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, msgType, (TW_MEMREF)&cap) != TWRC_SUCCESS)
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!cap.hContainer)
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (msgType == MSG_QUERYSUPPORT) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	pv = GLOBAL_LOCK(cap.hContainer);
Toshihiro Shimizu 890ddd
	my_enum = (TW_ENUMERATION *)pv;
Toshihiro Shimizu 890ddd
	my_array = (TW_ARRAY *)pv;
Toshihiro Shimizu 890ddd
	my_one = (TW_ONEVALUE *)pv;
Toshihiro Shimizu 890ddd
	my_range = (TW_RANGE *)pv;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (cont_size) {
Toshihiro Shimizu 890ddd
		switch (TWON_TWON(cap.ConType, conType)) {
Shinya Kitaoka d4642c
		case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION):
Shinya Kitaoka d4642c
			*cont_size = GetContainerSize(TWON_ENUMERATION, my_enum->ItemType, my_enum->NumItems);
Shinya Kitaoka d4642c
			break;
Shinya Kitaoka d4642c
		case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION):
Shinya Kitaoka d4642c
			*cont_size = GetContainerSize(TWON_ENUMERATION, my_one->ItemType, 1);
Shinya Kitaoka d4642c
			break;
Shinya Kitaoka d4642c
		case TWON_TWON(TWON_ARRAY, TWON_ARRAY):
Shinya Kitaoka d4642c
			*cont_size = GetContainerSize(TWON_ARRAY, my_array->ItemType, my_array->NumItems);
Shinya Kitaoka d4642c
			break;
Shinya Kitaoka d4642c
		case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE):
Shinya Kitaoka d4642c
			*cont_size = GetContainerSize(TWON_ONEVALUE, my_one->ItemType, 1);
Shinya Kitaoka d4642c
			break;
Shinya Kitaoka d4642c
		case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY):
Shinya Kitaoka d4642c
			*cont_size = GetContainerSize(TWON_ARRAY, my_enum->ItemType, my_enum->NumItems);
Shinya Kitaoka d4642c
			break;
Shinya Kitaoka d4642c
		default:
Toshihiro Shimizu 890ddd
			/*      tmsg_error("Unable to convert type %d to %d (cap 0x%x)\n", cap.ConType, conType,cap_id);*/
Toshihiro Shimizu 890ddd
			assert(0);
Toshihiro Shimizu 890ddd
			GLOBAL_UNLOCK(cap.hContainer);
Toshihiro Shimizu 890ddd
			GLOBAL_FREE(cap.hContainer);
Toshihiro Shimizu 890ddd
			return FALSE;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		GLOBAL_UNLOCK(cap.hContainer);
Toshihiro Shimizu 890ddd
		GLOBAL_FREE(cap.hContainer);
Toshihiro Shimizu 890ddd
		return TRUE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (TWON_TWON(cap.ConType, conType)) {
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION):
Shinya Kitaoka d4642c
		size = GetContainerSize(cap.ConType, my_enum->ItemType, my_enum->NumItems);
Toshihiro Shimizu 890ddd
		memcpy(data, my_enum, size);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ENUMERATION, TWON_RANGE):
Shinya Kitaoka d4642c
		ConvertEnumeration2Range(*my_enum, (TW_RANGE *)data);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ENUMERATION, TWON_ONEVALUE):
Shinya Kitaoka d4642c
		ConvertEnum2OneValue(*my_enum, (TW_ONEVALUE *)data);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ARRAY, TWON_ARRAY):
Shinya Kitaoka d4642c
		size = GetContainerSize(cap.ConType, my_array->ItemType, my_array->NumItems);
Toshihiro Shimizu 890ddd
		memcpy(data, my_array, size);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE):
Shinya Kitaoka d4642c
		memcpy(data, my_one, sizeof(TW_ONEVALUE));
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ONEVALUE, TWON_RANGE):
Shinya Kitaoka d4642c
		ConvertOneValue2Range(*my_one, (TW_RANGE *)data);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION):
Shinya Kitaoka d4642c
		ConvertOneValue2Enum(*my_one, (TW_ENUMERATION *)data);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_RANGE, TWON_RANGE):
Shinya Kitaoka d4642c
		memcpy(data, my_range, sizeof(TW_RANGE));
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY):
Shinya Kitaoka d4642c
		ConvertEnum2Array(*my_enum, (TW_ARRAY *)data);
Shinya Kitaoka d4642c
		break;
Shinya Kitaoka d4642c
	default:
Toshihiro Shimizu 890ddd
		assert(0);
Toshihiro Shimizu 890ddd
		GLOBAL_UNLOCK(cap.hContainer);
Toshihiro Shimizu 890ddd
		GLOBAL_FREE(cap.hContainer);
Toshihiro Shimizu 890ddd
		return FALSE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	GLOBAL_UNLOCK(cap.hContainer);
Toshihiro Shimizu 890ddd
	GLOBAL_FREE(cap.hContainer);
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	range->ItemType = one_value.ItemType;
Toshihiro Shimizu 890ddd
	range->MinValue = one_value.Item;
Toshihiro Shimizu 890ddd
	range->MaxValue = one_value.Item;
Toshihiro Shimizu 890ddd
	range->StepSize = 0;
Toshihiro Shimizu 890ddd
	range->DefaultValue = one_value.Item;
Toshihiro Shimizu 890ddd
	range->CurrentValue = one_value.Item;
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertEnumeration2Range(TW_ENUMERATION enumeration, TW_RANGE *range)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	range->ItemType = enumeration.ItemType;
Toshihiro Shimizu 890ddd
	range->MinValue = enumeration.ItemList[0];
Toshihiro Shimizu 890ddd
	range->MaxValue = enumeration.ItemList[enumeration.NumItems - 1];
Toshihiro Shimizu 890ddd
	range->StepSize = (range->MaxValue - range->MinValue) / enumeration.NumItems;
Toshihiro Shimizu 890ddd
	if (range->MaxValue < range->MinValue) {
Toshihiro Shimizu 890ddd
		range->MaxValue = range->MinValue;
Toshihiro Shimizu 890ddd
		range->StepSize = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	range->DefaultValue = enumeration.ItemList[enumeration.DefaultIndex];
Toshihiro Shimizu 890ddd
	range->CurrentValue = enumeration.ItemList[enumeration.CurrentIndex];
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Enum(TW_ONEVALUE one_value, TW_ENUMERATION *tw_enum)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	tw_enum->ItemType = one_value.ItemType;
Toshihiro Shimizu 890ddd
	tw_enum->NumItems = 1;
Toshihiro Shimizu 890ddd
	tw_enum->CurrentIndex = 0; /* Current value is in ItemList[CurrentIndex] */
Toshihiro Shimizu 890ddd
	tw_enum->DefaultIndex = 0; /* Powerup value is in ItemList[DefaultIndex] */
Toshihiro Shimizu 890ddd
	tw_enum->ItemList[0] = (TW_UINT8)one_value.Item;
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum, TW_ONEVALUE *one_value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned char *base;
Toshihiro Shimizu 890ddd
	TW_UINT32 ofs;
Toshihiro Shimizu 890ddd
	TW_UINT32 itemSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	itemSize = DCItemSize[tw_enum.ItemType];
Toshihiro Shimizu 890ddd
	base = tw_enum.ItemList;
Toshihiro Shimizu 890ddd
	ofs = tw_enum.CurrentIndex * itemSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	one_value->ItemType = tw_enum.ItemType;
Toshihiro Shimizu 890ddd
	one_value->Item = 0;
Toshihiro Shimizu 890ddd
	memcpy(&(one_value->Item), &(base[ofs]), itemSize);
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TW_UINT32 itemSize;
Toshihiro Shimizu 890ddd
	TW_UINT32 listSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	itemSize = DCItemSize[tw_enum.ItemType];
Toshihiro Shimizu 890ddd
	listSize = itemSize * tw_enum.NumItems;
Toshihiro Shimizu 890ddd
	array->ItemType = tw_enum.ItemType;
Toshihiro Shimizu 890ddd
	array->NumItems = tw_enum.NumItems;
Toshihiro Shimizu 890ddd
	memcpy(&(array->ItemList), &(tw_enum.ItemList), listSize);
Toshihiro Shimizu 890ddd
	return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*	      SET CAP							     */
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_SetCap(TW_UINT16 cap_id, TW_UINT16 conType, TW_UINT16 itemType,
Toshihiro Shimizu 890ddd
				  TW_UINT32 *value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int rc = FALSE;
Toshihiro Shimizu 890ddd
	TUINT32 size;
Toshihiro Shimizu 890ddd
	TW_CAPABILITY *capability = 0;
Toshihiro Shimizu 890ddd
	TW_HANDLE capabilityH = 0;
Toshihiro Shimizu 890ddd
	TW_ONEVALUE *container = 0;
Toshihiro Shimizu 890ddd
	TW_HANDLE containerH = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	size = GetContainerSize(conType, itemType, 1);
Toshihiro Shimizu 890ddd
	containerH = GLOBAL_ALLOC(GMEM_FIXED, size);
Toshihiro Shimizu 890ddd
	if (!containerH)
Toshihiro Shimizu 890ddd
		goto done;
Toshihiro Shimizu 890ddd
	container = (TW_ONEVALUE *)GLOBAL_LOCK(containerH);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	container->ItemType = itemType;
Toshihiro Shimizu 890ddd
	container->Item = *value;
Toshihiro Shimizu 890ddd
	capabilityH = GLOBAL_ALLOC(GMEM_FIXED, sizeof(TW_CAPABILITY));
Toshihiro Shimizu 890ddd
	if (!capabilityH) {
Toshihiro Shimizu 890ddd
		GLOBAL_UNLOCK(containerH);
Toshihiro Shimizu 890ddd
		GLOBAL_FREE(containerH);
Toshihiro Shimizu 890ddd
		goto done;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	capability = (TW_CAPABILITY *)GLOBAL_LOCK(capabilityH);
Toshihiro Shimizu 890ddd
	capability->ConType = conType;
Toshihiro Shimizu 890ddd
	capability->hContainer = containerH;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) {
Toshihiro Shimizu 890ddd
		/*TTWAIN_ErrorBox("Setting capability in State < 4.");*/
Toshihiro Shimizu 890ddd
		TTWAIN_OpenSourceManager(0); /* Bring up to state 4 */
Toshihiro Shimizu 890ddd
									 /*goto done;*/
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	capability->Cap = cap_id; /* capability id */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rc = (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF)capability) == TWRC_SUCCESS);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
done:
Toshihiro Shimizu 890ddd
	if (containerH) {
Toshihiro Shimizu 890ddd
		GLOBAL_UNLOCK(containerH);
Toshihiro Shimizu 890ddd
		GLOBAL_FREE(containerH);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (capabilityH) {
Toshihiro Shimizu 890ddd
		GLOBAL_UNLOCK(capabilityH);
Toshihiro Shimizu 890ddd
		GLOBAL_FREE(capabilityH);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return rc;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TUINT32 size;
Toshihiro Shimizu 890ddd
	switch (nFormat) {
Toshihiro Shimizu 890ddd
	case TWON_ONEVALUE:
Toshihiro Shimizu 890ddd
		size = sizeof(TW_ONEVALUE);
Toshihiro Shimizu 890ddd
		if (DCItemSize[twty] > sizeof(TW_UINT32)) {
Toshihiro Shimizu 890ddd
			size += DCItemSize[twty] - sizeof(TW_UINT32);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TWON_RANGE:
Toshihiro Shimizu 890ddd
		size = sizeof(TW_RANGE);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TWON_ENUMERATION:
Toshihiro Shimizu 890ddd
		size = sizeof(TW_ENUMERATION) + DCItemSize[twty] * nItems - sizeof(TW_UINT8);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case TWON_ARRAY:
Toshihiro Shimizu 890ddd
		size = sizeof(TW_ARRAY) + DCItemSize[twty] * nItems - sizeof(TW_UINT8);
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	default:
Toshihiro Shimizu 890ddd
		size = 0;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	} /* switch */
Toshihiro Shimizu 890ddd
	return size;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif