• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Recent posts

Pages 1 2 3 4 5 6 7 8 ... 10
41
Help & Questions / Re: Convert png with transpare...
Last post by TimmyG - 20 March 2019, 13:36:19
Quote from: Galfar on 30 November 2018, 23:37:21Well, if you want to get some amazing probiotics for ibs here and replace just one color (classic color keying) then you can use ReplaceColor function from Imaging.pas unit.
I somehow assumed that by transparency you mean full alpha channel.

Can you replace however many colors you want with ReplaceColor function btw, Galfar?
42
Bugs And Other Insects / Re: saving rgb with alpha chan...
Last post by Galfar - 11 February 2019, 00:37:30
Could you please upload your test BMP file here?
43
Bugs And Other Insects / Re: Convertig ifGray8 to float...
Last post by Galfar - 11 February 2019, 00:35:17
Thanks for the report, I'll have a look at this.
44
Bugs And Other Insects / saving rgb with alpha channel ...
Last post by heju - 9 February 2019, 11:31:51
Hi,

somehow, when loading a rgb bitmap with alpha channel and writing it back to bitmap the result is very blueish and the resulting bitmap has no alpha channel, seems as if the alpha channel is interpreted as blue somewhere.

img.CreateFromFile('rgb128alpha.bmp');
img.SaveToFile('out.bmp');


I checked the bytes after creating, here everything seems correct, problem should be in the save procedure.

When trying to save to PNG, the resulting png has alpha, but is blueish as well.

Hope I find some more time to give more detailed description...

Greetings&Bye
45
Bugs And Other Insects / converting rgb bmp with alpha ...
Last post by heju - 9 February 2019, 10:58:32
Hi,

when converting a rgb bmp with alpha channel to ifGray8, I noted that the pixel values in the final image are not as expected.

I think the problem could be here:
The source is read using PColor24Rec(Src), however in memory there is the alpha byte first (not the blue byte). Therefore the alpha channel is interpreted as blue channel. As the Src is incremented by 4 which is correct, the pixels do not get mixed up totally. 


procedure ChannelToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
  DstInfo: PImageFormatInfo);
var
  I: LongInt;
  Pix64: TColor64Rec;
  Alpha: Word;
begin
  // two most common conversions (R8G8B8->Gray8 nad A8R8G8B8->Gray8)
  // are made separately from general conversions to make them faster
  if (SrcInfo.BytesPerPixel in [3, 4]) and (DstInfo.Format = ifGray8) then
    for I := 0 to NumPixels - 1 do
    begin
      Dst^ := Round(GrayConv.R * PColor24Rec(Src).R + GrayConv.G * PColor24Rec(Src).G +
        GrayConv.B * PColor24Rec(Src).B);
      Inc(Src, SrcInfo.BytesPerPixel);
      Inc(Dst, DstInfo.BytesPerPixel);
    end
  else 
[...]
                                 


One ugly workaround which just disregards the alpha channel is to increment Src by one before entering the loop in case we have 4 bytes per pixel, then the RGB values are not mixed up at least.

Greetings & bye
46
Bugs And Other Insects / Convertig ifGray8 to float and...
Last post by heju - 9 February 2019, 10:36:34
Hi,

while converting gray 8bit images to float 32bit and back to gray 8 bit I noted that the intensity values dramatically change:

"in128.bmp" is a grayscale bitmap with pixel values of 128

img.CreateFromFile('in128.bmp');
img.Format:=ifGray8;
img.Format:=ifR32F;
img.Format:=ifGray8;
img.SaveToFile('out.bmp');


Now in the "out.bmp" image the pixel values are only 38.

As this is a bit of a problem for my application, I investigated a bit: The root cause seems to be here:
procedure FloatToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
  DstInfo: PImageFormatInfo);
var
  I: LongInt;
  PixF: TColorFPRec;
  Gray: TColor64Rec;
  Alpha: Word;
begin
  for I := 0 to NumPixels - 1 do
  begin
    FloatGetSrcPixel(Src, SrcInfo, PixF);
    ClampFloatPixel(PixF);

    // alpha is saved from source pixel to Alpha,
    // Gray value is computed and set to highest word of Pix64 so
    // Pix64.Color contains grayscale value scaled to 64 bits
    Alpha := ClampToWord(Round(PixF.A * 65535.0));
    Gray.A := ClampToWord(Round((GrayConv.R * PixF.R + GrayConv.G * PixF.G +
      GrayConv.B * PixF.B) * 65535.0));

    GraySetDstPixel(Dst, DstInfo, Gray, Alpha);
    Inc(Src, SrcInfo.BytesPerPixel);
    Inc(Dst, DstInfo.BytesPerPixel);
  end;
end;


Even the float image is single channel, the RGB-> gray conversion is calculated, reducing the pixel values (there is only intensity in red channel and this gets multiplied with GrayConv.R factor.

I workarounded the behaviour using the following approach (don't know if there are side effects). However now the value after conversion is the same as before:
(sry, you have to scroll down a bit maybe ;) )

procedure FloatToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
  DstInfo: PImageFormatInfo);
var
  I: LongInt;
  PixF: TColorFPRec;
  Gray: TColor64Rec;
  Alpha: Word;
begin
  for I := 0 to NumPixels - 1 do
  begin
    FloatGetSrcPixel(Src, SrcInfo, PixF);
    ClampFloatPixel(PixF);

    // alpha is saved from source pixel to Alpha,
    // Gray value is computed and set to highest word of Pix64 so
    // Pix64.Color contains grayscale value scaled to 64 bits
    Alpha := ClampToWord(Round(PixF.A * 65535.0));
    if SrcInfo.ChannelCount =1 then
      Gray.A := ClampToWord(Round(PixF.R * 65535.0))
    else
      Gray.A := ClampToWord(Round((GrayConv.R * PixF.R + GrayConv.G * PixF.G +
        GrayConv.B * PixF.B) * 65535.0));

    GraySetDstPixel(Dst, DstInfo, Gray, Alpha);
    Inc(Src, SrcInfo.BytesPerPixel);
    Inc(Dst, DstInfo.BytesPerPixel);
  end;
end;


Bye...
47
Bugs And Other Insects / Re: Can't load jpeg image
Last post by Galfar - 21 January 2019, 17:45:19
Quote from: Robaggio on  4 January 2019, 07:54:36
I also have this problem as well.


Please try the latest version from the repository.
48
Help & Questions / Re: fpc compiler warnings in p...
Last post by Galfar - 21 January 2019, 14:50:39
"if entropy^.restarts_to_go >0 then" in imjdhuff.pas is safe.
I had it in Imaging branch used in my Deskew tool for years and probably
forgot to merge it to the main branch.

I also did tests with "ptr2int = ptruInt" for zlib and everything was fine
so I pushed both changes to the repository.
49
Bugs And Other Insects / Re: Problem for 64bit
Last post by Robaggio - 4 January 2019, 07:55:05
Thank you for sharing the information.
50
Bugs And Other Insects / Re: Can't load jpeg image
Last post by Robaggio - 4 January 2019, 07:54:36
I also have this problem as well.
Pages 1 2 3 4 5 6 7 8 ... 10
SMF spam blocked by CleanTalk