Transform filter with different input & output media types (crop filter, Delphi)?

Transform filter with different input & output media types (crop filter, Delphi)?

Post by Whone NoNa » Wed, 21 Feb 2007 20:39:57


(Delphi)
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/

I have been trying to create CropFilter in Delphi. So far I managed to
create filter fine but without cropping.

I want to crop right+bottom side of the original video. Zip has example
256x256 video and I want to output it as 246x246 RGB32 video. Pixels are
manipulated along the cropping. Example now draws a opaque gradient colors.

GetMediaType call should return media type of output pin. I copy input
pin format and then change width,height,lSampleSize,biSizeImage attributes.

DecideBufferSize instructs to use a new cropped size for buffers.

Its like .avi videofile or DX resets everything and force pipeline to
use input pin filter.

Problems:
* Input media type and output media type are always identicals even if I
put 10 pixels crop.

Any (delphi) specilists here can help?
 
 
 

Transform filter with different input & output media types (crop filter, Delphi)?

Post by The March » Wed, 21 Feb 2007 23:16:14


Not a Delphi specialist but there is a C++ resize filter with source
provided by Vivek on my Downloads page (see sig.). It should give you some
idea of how to change the media types.

--
Please read this before replying:
1. Dshow & posting help: http://www.yqcomputer.com/
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others: follow up if you are helped or you found a solution

 
 
 

Transform filter with different input & output media types (crop filter, Delphi)?

Post by Nete » Thu, 22 Feb 2007 00:55:50

Is there a more precise and fast algorithm for real-time resizing? RGB
resize works, but the picture quality is badly degraded.
 
 
 

Transform filter with different input & output media types (crop filter, Delphi)?

Post by Chris P » Thu, 22 Feb 2007 01:18:55


It's a function of the algorithm used. For high quality resizing a
bi-cubic (or other high-quality algorithm) method needs to be used. It
needs to be implemented in SSE(2) to be able to achieve realtime
performance, or done in the video hardware.

--
http://www.yqcomputer.com/
[MS MVP for DirectShow / MediaFoundation]
 
 
 

Transform filter with different input & output media types (crop filter, Delphi)?

Post by Whome NoNa » Thu, 22 Feb 2007 21:53:51

> Not a Delphi specialist but there is a C++ resize filter with source

http://www.yqcomputer.com/
http://www.yqcomputer.com/

Some progress, now I can set smaller size to a output pin. Problem was I
made a copy of TVIDEOINFOHEADER struct. But now I update output size
through a PVIDEOINFOHEADER pointer in GetMediaType method.

input : 256x256 RGB32
output: 156x156 RGB32

1) BITF format?
VideoRenderer indeed displays a valid format in "input" tab, but soon as
I have run it once it says "Format: BITF 160x-156, 32 bits".

If I crop to 246x246 size it says "BITF 256x-246, 32 bits".
If I crop to 236x246 size ti says "BITF 240x-236, 32 bits".

What is BITF format and why 160x-156 or similar size?

VideoRenderer canvas is correct size even so renderer "input" tab says a
weird BITF size. SimpleFilter output pin always give a correct format
information.


2) copying from source to destination buffer
output image is broken, its like reading and cutting wrong row offset so
pixel lines are distorted. I cannot find an error.

in size : 256x256
out size: 156x156

This produces a distorted image.
// crop pixels
Inc(pSourceBuffer, (0 * in_w) * bytesPerPixel); // crop_top
for y := 0 to out_h-1 do begin
Inc(pSourceBuffer, (0 * bytesPerPixel)); // crop_left
CopyMemory(pDestBuffer, pSourceBuffer, out_w * bytesPerPixel);
Inc(pDestBuffer, (out_w * bytesPerPixel));
Inc(pSourceBuffer, (in_w * bytesPerPixel));
end;

Any clues?
 
 
 

Transform filter with different input & output media types (crop filter, Delphi)?

Post by Whome NoNa » Tue, 27 Feb 2007 19:51:48

(delphi)
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/


I have found out should handle a stride and downstream alignment issue.
Problem was if I crop 256x256 video to 236x246 size then output video is
distorded. Line alignment clearly did not match.

I put hardcoded +4 to "out_w" during a transformation and image was
fine, although upside down but its ok.

// crop pixels (put +4 to output width to align bytes)
// treat 236x246 crop size as 240x246 size.
Inc(pSourceBuffer, (0 * in_w) * bytesPerPixel); // crop_top
for y := 0 to out_h-1 do begin
Inc(pSourceBuffer, (0 * bytesPerPixel)); // crop_left
CopyMemory(pDestBuffer, pSourceBuffer, (out_w+4) * bytesPerPixel);
Inc(pDestBuffer, ((out_w+4) * bytesPerPixel));
Inc(pSourceBuffer, (in_w * bytesPerPixel));
end;

Any ideas to make stride and alignment issue transparent. If this is
related to a downstream filters and/or renderers then I should not
hardcode anything.