# Here’s a tricky one



## Lorand (Aug 8, 2004)

Some time ago I wrote a barcode generator program in Delphi. It uses the canvas to draw and then saves that bitmap as a tiff. It works very well in Win98, but in XP acts strangely: the canvas’ background is black instead of white. But not on every system with XP! The program worked well on a computer, but recently the XP was reinstalled on it after a crash. Now even there the background turned black.
What could be the problem?


----------



## Praetor (Aug 8, 2004)

> the canvas’ background is black instead of white. But not on every system with XP!


(Icon/Desktop)Transparency settings?



> The program worked well on a computer, but recently the XP was reinstalled on it after a crash. Now even there the background turned black.


If you'd like I can take a look at the source/compilation


----------



## Lorand (Aug 8, 2004)

> (Icon/Desktop)Transparency settings?


Already tried every of those (I think), without any luck...
Here's the program: http://www.geocities.com/despartro/codbART.zip
Unfortunately I lost the source files for it  (I have only a backup from very early stages), that's why I hope it's something about settings...


----------



## Praetor (Aug 8, 2004)

Seems to work as expected for me... question: what viewer are u using for images? Some viewers (like irfanview) sometimes default of a specific mask/transparancy color.


----------



## Lorand (Aug 8, 2004)

Here's the result on my computer (and it's the same in every program - Photoshop, Photopaint, QuarkXpress):


----------



## Praetor (Aug 8, 2004)

Any objects/controls/references you used or did you use all-internal commands/calls?


----------



## Lorand (Aug 8, 2004)

Oops, I forgot to mention that there’s more. On some XPs even the eps file created with this program is unreadable (unrecognized format). This is really weird, because the eps file’s preambule is ready made (the program just adds the character string that compose the barcode), only the preview bitmap is attached to it. And even if the preview’s background is black, the bitmap size is the same...
By now I saw 3 different ways the program function in XP:
1. TIF and EPS ok
2. TIF bad, EPS ok
3. TIF and EPS bad


----------



## Praetor (Aug 8, 2004)

> even the eps file created with this program is unreadable (unrecognized format).


Can you post that file? 



> By now I saw 3 different ways the program function in XP:


1. Same problem with W2K?
2. Which is the "problemsome" one? I'm guessing #3

(BTW could it be "Demo" vs "Full")?


----------



## Lorand (Aug 8, 2004)

Here's what I could find in the old source files:

Bitmap:=tbitmap.Create;
bitmap.height:=1432;
bitmap.width:=2832;
bitmap.Monochrome:=true;
Tiffsave.AttachedBitmap:= bitmap;
bitmap.canvas.font.name:='Barcodefont';
bitmap.canvas.Font.size:=180;
bitmap.canvas.textout(125,26,'qrst '+code);
bitmap.canvas.Font.size:=550;
bitmap.canvas.textout(167,400,'<');
bitmap.canvas.textout(393,400,chr(97+ean[2]));
bitmap.canvas.textout(558,400,chr(65+ean[3]));
.....
bitmap.canvas.textout(2440,400,'>');
Tiffsave.Params.dpix:=2400;
Tiffsave.Params.dpiy:=2400;
Tiffsave.Params.Width:=2832;
Tiffsave.Params.Height:=1432;
Tiffsave.Params.SamplesPerPixel:=1;
Tiffsave.Params.BitsPerSample:=1;
Tiffsave.Params.TIFF_PhotometInterpret:=ioTIFF_BLACKISZERO;
Tiffsave.Params.TIFF_Compression:=ioTIFF_LZW;
Tiffsave.SaveToFile(fn);
Tiffsave.Bitmap.Free;

Never tried on a win2000. The demo and full version works exactly the same way...
Unfortunately I can't post a messed-up eps, the XP was reinstalled on that computer too, and now only the tiff is bad when running this program on it.


----------



## Lorand (Aug 8, 2004)

Meantime I discovered the 4th kind of bad output of the program: an eps file that could be imported, printed, but has a corrupted preview (attached).
This program runs perfectly on more than a dozen of computers with Win98 and never had such problems... It could be something about a different internal function of XP. But how come that on some XP-systems it works?  
As you can see, in the messed-up bitmap the characters' bounding boxes have white background, so I think the problem arises from the bitmap creation.


----------



## Praetor (Aug 9, 2004)

Any luck if you run W98-compatability mode?


----------



## Lorand (Aug 9, 2004)

Already tried that, but the result is the same...


----------



## Praetor (Aug 9, 2004)

Try and see if you can get it to work on a W2K system.... I'd really like to know if its just the system core that it's conflicting with.,...


----------



## Lorand (Aug 9, 2004)

Ok, I'll try it. But it's hard to find a computer with W2k (at the office we have Win98 and all my friends have XP). It could take some time to find one. I'll be back with the results...


----------



## Praetor (Aug 9, 2004)

If its absolutely desparate I could reghost back to 2K but I'm too lazy for that .... also too lazy to goto campus  If i'm on campus and remember I'll give it a whirl.


----------



## Lorand (Aug 9, 2004)

Thanks, but I don't want to cause you trouble with that. I'll find somewhere a W2k.


----------



## Praetor (Aug 9, 2004)

Its not all that much trouble (thanks Ghost! ) i'm just lazy


----------



## Lorand (Aug 12, 2004)

I tried the program on two computers with win2000 and it worked fine. But I don't know if it works on every w2k (there are XPs also on which the program runs perfectly)...


----------



## Lorand (Aug 27, 2004)

I noticed something really weird...
The program runs fine on XPs that have multiple users, the black background appears only on XPs that have a single default user.
Could it be a simple coincidence?


----------



## Praetor (Aug 27, 2004)

Does it run ok on all the logins with multiple users? My machine only has a single user and it worked ok


----------



## Lorand (Aug 27, 2004)

So it's only a coincidence...  Still don't know what it could be... 
Interestingly all the computers that produces black background have ZoneAlarm installed. Could this be the problem?


----------



## Lorand (Aug 27, 2004)

Look what I found (so I'm not alone with this problem):

```
// Not clear why this is need to clear whole background to white;
// otherwise -- only sometimes -- part of bitmap is black instead.
RESULT.Canvas.Brush.Color := clWhite;
RESULT.Canvas.FillRect( RESULT.Canvas.ClipRect );
```
This would be the solution, but I can't use it without the source... 
So I'm still hoping there's a windows setting that could solve the problem...


----------



## Praetor (Aug 27, 2004)

> Interestingly all the computers that produces black background have ZoneAlarm installed. Could this be the problem?


Now ur shooting in the dark!  (no worries... been there done that.... still there )

I'll have a look around.. gimme some time ... been busy.


----------



## Lorand (Aug 27, 2004)

*I FIGURED OUT AT LAST!*

At the display settings I changed the color depth from 32 bpp to 16 bpp and the program works fine now!
But what the heck could be the difference between these two video settings?


----------



## Praetor (Aug 28, 2004)

What about 24bit ... oh and btw not to ruin your parade.... mine is on 32bit color and works fine (also works on 16 and 24)


----------



## Lorand (Aug 28, 2004)

I only have 16 or 32 at color depth options (my card is an ATI All-in-wonder), so I can't check what happens at 24 bit...
Could be a video-driver bug that produces that bitmap black-out?


----------



## Praetor (Aug 28, 2004)

Maybe an ATI/nvidia dealy? I wouldnt think so cuz i dont have any problems on my ATi based systems. What driver revisions have you tested on?


----------



## Lorand (Aug 28, 2004)

It's surely not an ATI/Nvidia thing, because on another computer there's an Nvidia and the background is also black.
I'll test that computer's video settings too in a couple of days...


----------



## Praetor (Aug 28, 2004)

> It's surely not an ATI/Nvidia thing


I figured but i guess it was worth a shot in the dark


----------



## Lorand (Aug 29, 2004)

Tested the NVidia too. And it works the same way: 32 bpp -> black, 16 or 24 bpp -> white.
On my computer I had 3 versions of ATI drivers so far, and every time it was a bitmap blackout. But I had the same video card and display settings on Win98 too, and it was ok...

So:
1. Only happens in XP
2. This problem does not affect all systems
3. Not depends on video card manufacturer
4. It's not a driver bug
5. Only happens in 32 bpp
6. Not depends on any other settings (transparencies, etc.)

What could it be then?


----------



## Lorand (Sep 2, 2004)

BTW, what’s the 32 bpp thing?
24 bpp means that there is 1 byte for each colour (R, G, B), thus 256 shades on every channel. This gives a total of 16.777.216 possible colours.
An RGB image saved in 32 bpp colour depth has in fact a 24 bpp RGB colour space combined with 1 byte alpha channel (for transparency). So it has also 16.777.216 possible colours.
But what’s the difference between the 24 bpp and the 32 bpp display setting? What’s the use of that extra byte?


----------



## Praetor (Sep 2, 2004)

> Only happens in 32 bpp


Mine was 32bit and didnt have a problem.

As for 32bit, there IS a reason for it:


> TGA - The real name for this format is just plain "TGA" or "Truevision File Format", but a lot of people call it "Targa", after the Truevision video card that first used it. There's a lot of this name confusion in image file formats. It supports 1 to 32 bit images and professional features like an alpha (mask) channel, gamma settings and a built-in thumbnail image.





> 32 bit textures are typically only tga (Targa) files. A 32 bit texture includes 'built in' transparency via an 8 bit alpha mask, which is laid over a 24 bit true color bitmap. This gives you up to 255 different variations in transparency, which is quite a few.



Mostly image/texture creation and gamedev will have actual use of 32bit color


----------



## Lorand (Sep 4, 2004)

Look what I found:


> Some versions of XP and 2003 do not create 32bpp icons properly in the drivebar.


(This text was listed at some program's bugs.)
Is it possible that we have different versions of XP?


----------



## Praetor (Sep 4, 2004)

Maybe, what build


----------



## Lorand (Sep 4, 2004)

I have XP 5.1.2600 SP1


----------

