Home › Forums › TWAIN Classic › Question About ICAP_UNITS
- This topic has 13 replies, 2 voices, and was last updated 16 years, 2 months ago by gabe.
- AuthorPosts
If I were to set ICAP_UNITS to TWUN_PIXELS early on, is it safe to assume/expect that the data source will return values in pixels when querying things like ICAP_XRESOLUTION, ICAP_YRESOLUTION, etc etc?
Thanks,
Torin
The reason I ask is because I have a device where I set the units to pixels, then ask for the x and y resolutions, as well as ICAP_PHYSICALHEIGHT and ICAP_PHYSICALWIDTH. With the resolutions, I’m getting back an enumeration of 50 Fix32 values, some of which are negative, and some are REALLY small. Surely I’m missing something here right?
Thanks,
Torin
If I were to guess (and I’m about to) I’d say your fix32 is off and that you aren’t really getting negative values back from the device.
I’m guessing this because I had the same trouble and it was an error on my part.
For a test – run your code against a Kodak scanning in simulation mode as I am certain that they don’t return negative units.But as to your question, yes. if you set the units to xyx you should be getting responses for pretty much everything in xyx units except where noted otherwise in the spec. There are a couple of triplets that are documented as always returning in one unit or another – no I don’t remember exactly which ones (*should) always return in a certain unit but it’s in the spec.
.
Hard to say if it is correct or not. I have to think my code is correct because the first two values I get back are 800 and 600, and both of these are available in the data source’s UI. The following is the code where I’m enumerating the ICAP_YRESOLUTION values.
TW_CAPABILITY twCapability;
memset(&twCapability, 0, sizeof(twCapability));
twCapability.Cap = ICAP_YRESOLUTION;
twCapability.ConType = TWON_ENUMERATION;
if ((Status = m_Twain.GetCapability(&twCapability)) != STATUS_SUCCESS)
{
return Status;
}
double dLargest = 0.0;
pTW_ENUMERATION pEnum = reinterpret_cast(::GlobalLock(twCapability.hContainer));
if (pEnum->ItemType != TWTY_FIX32)
{
::GlobalUnlock(twCapability.hContainer);
throw STATUS_NSTWAIN_UNSUPPORTED_DATA_TYPE;
}
else
{
double dTemp = 0.0;
pTW_FIX32 pFixResolution = reinterpret_cast(pEnum->ItemList);
TW_FIX32 FixResolution = { 0 };
TW_UINT32 uiItemCounter = 0;
for (uiItemCounter = 0; uiItemCounter < pEnum->NumItems; uiItemCounter++, pFixResolution++)
{
FixResolution = (*pFixResolution);
dTemp = static_cast(FixResolution.Whole) + (static_cast (FixResolution.Frac) / 65536.0);
if (dTemp > dLargest)
{
dLargest = dTemp;
}
}
}
::GlobalUnlock(twCapability.hContainer);
Due note, the negative and tiny values are seen in the FixResolution structure long before I do the conversion in to dTemp.
Thanks,
Torin
Switching to getting a TW_RANGE appears to do what I want (as I only wanted the max and min). Is there documentation that explains how to interpret the results when using TW_ARRAY or TW_ENUMERATION?
Thanks
Torin
if you want to test in the other direction – test the driver, run the twain toolkit against the device/driver. if the toolkit shows negative values then isn’t your code, plus you can compare your code against the toolkit if the toolkit shows positive. when my code had a problem it was as the return value would have approached X.5 – the closer it got to something and a half the further off my code got. but, check the toolkit. what device are you testing with?
.
The device I’m currently using is a Fujitsu fi-4340C, but I also saw similar behavior with a Lanier LD118D.
Torin
interesting, how do they look in the toolkit?
.
Looks like Twacker receives it as a range even when I set it to enumeration or array.
Torin
Wow. Amazing how different devices can be. What I’m trying to do is find the very largest image size in pixels that a device will provide. Yep, first thought is to get ICAP_PHYSICALHEIGHT and ICAP_PHYSICALWIDTH. Unfortunately, at least with the Fujitsu it is returning different values depending on the X/Y Resolution. So I figured I’d enumerate the X/Y Resolutions to find the maximum, set to the maximum, then get the physical height/width. Using Twacker, I can see that the Fujitsu returns bad value when trying to set the resolution with units set to pixels, but if I set units back to the inches that it defaults to, then set the resolutions it works fine. With the Lanier, it will allow me to set the units to pixels, then set the resolutions. What is the point of a spec/standard if no one is going to follow it? 🙂
Torin
Re-reading the spec helped since pixels per TWUN_PIXELS is meaningless.
Torin
but the values, are the values negative in the toolkit?
Well since twacker is returning it as a range, they’re fine. Just like when my code requests them as a range. The problem showed up when requesting as an enumeration and twacker doesn’t return them as an enumeration.
Torin
Doesn’t seem to make sense that you’re getting a different container back for the same triplet with the same Msg,…
What triplet are you sending / which Msg_Get (get,getCurrent or getDefault)?
I can’t tell what Msg_Get* your m_Twain.GetCapability sends.And looking at the code fragment you sent, it doesn’t seem that you’re checking what container you were given, I see that you’re checking for the itemType and if the itemType == Fix or != but I don’t see where you verify the container type,.. is there more code where you switch on conType?
.
- AuthorPosts