QTMovieCurrentSizeAttribute and QTMovieSizeDidChangeNotification replacements - quicktime

Does anyone know the correct way to replace old QTMovieCurrentSizeAttribute and QTMovieSizeDidChangeNotification tasks? I'm trying to clean out old deprecated code.
I've found that QTMovieNaturalSizeDidChangeNotification is not a replacement for QTMovieSizeDidChangeNotification. Likewise QTMovieNaturalSizeAttribute is not a replacement for QTMovieCurrentSizeAttribute. Natural Size refers to the QTMovie's native resolution, while Current Size refer to the resolution at which a QTMovie is being displayed (this may also be the resolution to which the movie is being decoded, which can resize from native). For example, if the source was anamorphic or had non-square pixels, then Natural and Current Sizes will not be the same. The difference is easily seen in the Movie Inspector Window of the QuickTime 7 Player.
As near as I can tell, QuickTime X allows multiple views into the same QTMovie, so the notion of Current Size needed to be replaced by something new. (Perhaps the Current Size functionality was moved into QTMovieView? Or a decoder query?) Can anyone refer me to documentation or sample code for the new way?
Any sample code of a Movie Inspector Window that has been updated to show Natural and Current ('Actual') Sizes, without using deprecated code, would be ideal. This has been very confusing to tackle, so far.

Is this useful? http://opensource.apple.com/source/WebCore/WebCore-955.66/platform/graphics/mac/MediaPlayerPrivateQTKit.mm
IntSize MediaPlayerPrivate::naturalSize() const
{
if (!metaDataAvailable())
return IntSize();
// In spite of the name of this method, return QTMovieNaturalSizeAttribute transformed by the
// initial movie scale because the spec says intrinsic size is:
//
// ... the dimensions of the resource in CSS pixels after taking into account the resource's
// dimensions, aspect ratio, clean aperture, resolution, and so forth, as defined for the
// format used by the resource
NSSize naturalSize = [[m_qtMovie.get() attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
return IntSize(naturalSize.width * m_scaleFactor.width(), naturalSize.height * m_scaleFactor.height());
}

Related

OpenCV is there a way to resize the showed image to the screen automatically?

I am using opencv to show an image. The problem is that the image is large so it is bigger than my huge display.
Is there a way to show this image AUTOMATICALLY resized to fit in my screen?
Please note that many of the answers to similar questions here fall under two categories:
They suggest the use of an option in the namedWindow function, but this does not solve the question (I tried and also read carefully the documentation, it never claim it does solve this question)
Use resize to manually resize the image. Not automatically. But then how can I know the values to resize?
EDIT: I have been asked to report my claim that WINDOW_NORMAL does not solve the problem. I have right in front of me a script in which first I just do
cv.imshow("window",image)
cv.waitKey()
and then the same script with
cv.namedWindow("window", cv.WINDOW_NORMAL)
#image = cv.resize(image, (960, 540))
#image = cv.resize(image, (1280, 800))
cv.imshow("window",image)
cv.waitKey()
The results are the same. The window is as Huge as always.
Now let's see the docs
Parameters:
name – Name of the window in the window caption that may be used as a window identifier.
flags –
Flags of the window. The supported flags are:
WINDOW_NORMAL If this is set, the user can resize the window (no constraint).
WINDOW_AUTOSIZE If this is set, the window size is automatically adjusted to fit the displayed image (see imshow() ), and you cannot change the window size manually.
WINDOW_OPENGL If this is set, the window will be created with OpenGL support.
As you can see it clearly says the user can resize the window (no constraint) and in no part it says AUTOMATICALLY
so it does not address the problem of this question
You can try and use the following library to obtain the X and Y values of your display:
import pyautogui #pip install pyautogui
x = pyautogui.size()[0] # getting the width of the screen
y = pyautogui.size()[1] # getting the length of the screen
print(x,y)
Similar to what Dimitar Veljanovski posted (Thanks!) I did this like this. It is not automatic and it does not occupy the whole screen but I have not received an answer to this
h, w, c = image.shape
cv.namedWindow("window",cv.WINDOW_NORMAL)
image=cv.resize(image, (w//3,h//3))
cv.imshow("window",image)

Scale/Zoom bigger 3D models

I am currently working on ARCore for android. our use case is to load a bigger model in ARCore which is with the size of a building with more than two floors. this single big model will be extended to several floors in the building.
when we load the big model it is scaled to a smaller size by default and we could not zoom out to map/match the model for different floors.
when we tried to set node.getScaleController().setMaxScale(50f); the model gets zoomed and hides at certain point.
AnchorNode anchorNode = new AnchorNode(anchor);
TransformableNode node = new TransformableNode(fragment.getTransformationSystem());
node.getScaleController().setMinScale(0.01f);
node.getScaleController().setMaxScale(50f);
node.getScaleController().setSensitivity(0.1f);
node.setParent(anchorNode);
node.setRenderable(renderable);
node.select();
fragment.getArSceneView().getScene().addChild(anchorNode);
we found a youtube link which is similar to our use case, unfortunately, this is in ARKit and by using models with .scn formats.
https://www.youtube.com/watch?v=FG5SztPF2uY
Can someone please suggest whether this is feasible in Arcore.
Sharing some code snippets to scale this bigger model would be very helpful.
Note: our models are in .obj formats and converted to .sfa and .sfb for using in ARCore.
Hope after setting the max and min scale value you are using
public void setLocalScale (Vector3 scale)
Sets the scale of this node relative to its parent (local-space). If isTopLevel() is true, then this is the same as setWorldScale(Vector3).

What does kCIInputCenterKey parameter control in CIPixellate filter?

The only doc I can find doesn't say much:
A CIVector object whose attribute type is CIAttributeTypePosition and
whose display name is Center.
I did some experiment. I can see it shift some "center". But I want to know what exactly it controls in the underlining pixelation algorithm so that I can use it in a knowledgeable way instead of blindly fumbling.
I think it shifts where the initial sampling point is taken, so that combined with the scale parameter will adjust which pixels are pulled out for the pixelate.
You can try it out in QuartzComposer (or even Acorn (an app written by myself)) and futz around with the parameters to get a good idea as to what it does.

What is the secret behind "contentScaleFactor" of UIView when used with CATiledLayer?

Greetings,
I'm working on an application inspired by the "ZoomingPDFViewer" example that comes with the iOS SDK. At some point I found the following bit of code:
// to handle the interaction between CATiledLayer and high resolution
// screens, we need to manually set the tiling view's
// contentScaleFactor to 1.0. (If we omitted this, it would be 2.0
// on high resolution screens, which would cause the CATiledLayer
// to ask us for tiles of the wrong scales.)
pageContentView.contentScaleFactor = 1.0;
I tried to learn more about contentScaleFactor and what it does. After reading everything of Apple's documentation that mentioned it, I searched Google and never found a definite answer to what it actually does.
Here are a few things I'm curious about:
It seems that contentScaleFactor has some kind of effect on the graphics context when a UIView's/CALayer's contents are being drawn. This seems to be relevant to high resolution displays (like the Retina Display). What kind of effect does contentScaleFactor really have and on what?
When using a UIScrollView and setting it up to zoom, let's say, my contentView; all subviews of contentView are being scaled, too. How does this work? Which properties does UIScrollView modify to make even video players become blurry and scale up?
TL;DR: How does UIScrollView's zooming feature work "under the hood"? I want to understand how it works so I can write proper code.
Any hints and explanation is highly appreciated! :)
Coordinates are expressed in points not pixels. contentScaleFactor defines the relation between point and pixels: if it is 1, points and pixels are the same, but if it is 2 (like retina displays ) it means that every point has two pixels.
In normal drawing, working with points means that you don't have to worry about resolutions: in iphone 3 (scaleFactor 1) and iphone4 (scaleFactor 2 and 2x resolution), you can use the same coordinates and drawing code. However, if your are drawing a image (directly, as a texture...) and just using normal coordinates (points), you can't trust that pixel to point map is 1 to 1. If you do, then every pixel of the image will correspond to 1 point but 4 pixels if scaleFactor is 2 (2 in x direction, 2 in y) so images could became a bit blurred
Working with CATiledLayer you can have some unexpected results with scalefactor 2. I guess that having the UIView a contentScaleFactor==2 and the layer a contentScale==2 confuse the system and sometimes multiplies the scale. Maybe something similar happens with Scrollview.
Hope this clarifies it a bit
Apple has a section about this on its "Supporting High-Resolution Screens" page in the iOS dev documentations.
The page says:
Updating Your Custom Drawing Code
When you do any custom drawing in your application, most of the time
you should not need to care about the resolution of the underlying
screen. The native drawing technologies automatically ensure that the
coordinates you specify in the logical coordinate space map correctly
to pixels on the underlying screen. Sometimes, however, you might need
to know what the current scale factor is in order to render your
content correctly. For those situations, UIKit, Core Animation, and
other system frameworks provide the help you need to do your drawing
correctly.
Creating High-Resolution Bitmap Images Programmatically If you
currently use the UIGraphicsBeginImageContext function to create
bitmaps, you may want to adjust your code to take scale factors into
account. The UIGraphicsBeginImageContext function always creates
images with a scale factor of 1.0. If the underlying device has a
high-resolution screen, an image created with this function might not
appear as smooth when rendered. To create an image with a scale factor
other than 1.0, use the UIGraphicsBeginImageContextWithOptions
instead. The process for using this function is the same as for the
UIGraphicsBeginImageContext function:
Call UIGraphicsBeginImageContextWithOptions to create a bitmap
context (with the appropriate scale factor) and push it on the
graphics stack.
Use UIKit or Core Graphics routines to draw the content of the
image.
Call UIGraphicsGetImageFromCurrentImageContext to get the bitmap’s
contents.
Call UIGraphicsEndImageContext to pop the context from the stack.
For example, the following code snippet
creates a bitmap that is 200 x 200 pixels. (The number of pixels is
determined by multiplying the size of the image by the scale
factor.)
UIGraphicsBeginImageContextWithOptions(CGSizeMake(100.0,100.0), NO, 2.0);
See it here: Supporting High-Resolution Screens

How to adjust GLCamera to show entire GLScene

I have a GLScene object of varying (but known) size. It is completely surrounded by a TGLDummyCube.
I want to position the GLCamera (with CameraStyle: glPerspective) so that the object is completely visible on screen. I got this running basically - the object is visible, but the distance is sometimes too far, or the object is larger than the screen and clipped.
How can I do that? I suppose that this can be done by a clever combination of camera distance and focal length, but I have not been successful so far.
This seems to be different in GLScene compared to OpenGL. I'm using GLScene and Delphi 2007.
Although varying the camera distance and focal length will change the object's visual size, it has the drawback of also changing the perspective, thus leading to a somewhat distorted view. I suggest to use the camera's SceneScale property instead.
Alas, I have no valid steps to calculate the correct value for that. In my case I have to scale to a cube with varying size, while the window size of the viewer is constant. So I placed two dummycubes at the position of the target cube, each sized to fit either the width or the height of the viewer with appropriate values for SceneScale, camera distance and FocalLength. During runtime I calculate the new SceneScale by the ratio of the target cube size in respect to the dummycube sizes. This works quite well in my case.
Edit: Here is some code I make for the calculations.
ZoomRefX and ZoomRefY are those DummyCubes
TargetDimX and TargetDimY give the size of the current object
DesignWidth and DesignHeight are the size of MyGLView at design time
DesignSceneScale is the camera's SceneScale at design time
The calculation code:
ScaleX := (ZoomRefX.CubeSize*MyGLView.Width)/(DesignWidth*TargetDimX);
ScaleY := (ZoomRefY.CubeSize*MyGLView.Height)/(DesignHeight*TargetDimY);
NewSceneScale := Min(ScaleX, ScaleY)*DesignSceneScale;
The DummyCubes ZoomRefX and ZoomRefY are sized so that they have a small margin to either the left-right or top-bottom edges of the viewing window. The are both positioned so that the front faces match. Also the target object is positioned to match its front face with those of these DummyCubes.
The formulas above allow the window size to be different from design time, but I actually didn't test this feature.
#Andreas if you've been playing with SceneScale (as you mentioned in comments) that means that you are looking for a proper way to fit object within camera view by either changing camera distance/focal length or by resizing object. If so, the easiest way to resize single object to fit the screen is to use its BoundingSphereRadius property like this:
ResizeMultiplier := 2; //play with it, it depends on your camera params
GLFreeForm1.Scale.Scale(ResizeMultiplier / GLFreeForm1.BoundingSphereRadius);
You can add GLDummyCube as root object for all other scene objects and then resize GLDummyCube with method mentioned above.

Resources