Animated appearance of Photoshop layers - animation

I'm working with a Photoshop document that has over 1,000 layers in it (1052, to be precise). The file itself is a collage and each layer is an individual image within that collage. So, when all layers are visible it's a complex collage of 1052 overlapping images. What I have been trying to do is create an animation of the collage assembly so that, for instance, layer 0 appears and then layer 1, layer 2, etc. and when each layer appears the previous layer also stays visible.
I have been able to make a frame animation, to which I've then added all other layers as frames but in this case the animation I create just makes each new frame/layer visible on its own, and making the previous layer(s) invisible. I've gone through the first several frames, manually keeping the previous layer/frame visible but I'm hoping there's a way to do this more automatically.
Is there an approach or a setting I'm missing that will allow me to automagically create this animation, keeping each frame visible as the next frame also becomes visible?

Basically, the premise of want you want is to go through all layers, switching on and off the viability as you go. Or switch them all off before you start, and get the code to loop through all the layers. Also as you are starting out, get rid of any groups, it'll just be easier. Make a copy of the psd without them if you have to.
In Photoshop scripting, the top most layer is 0. The next one below is 1 etc. It's easier to count backwards over the loop
for (var i = numOfLayers -1; i >= 0; i--)
{
// do stuff here
}
The visibility of each layer is controlled with:
theLayer.visible = true; // visible
thatLayer.visible = false; // not visible
So in short you'll have something like this:
// WITH ALL THE LAYERS VISIBILITY SWITCHED OFF TO START WITH!
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
// call the source document
var srcDoc = app.activeDocument;
// get the number of layers in the PSD
var numOfLayers = srcDoc.layers.length;
var myFolder = "D:\\temp\\";
// main loop
// ignore background
for (var i = numOfLayers -2; i >= 0 ; i--)
{
var docName = "image_" + i + ".jpg";
// get a reference to the layers as you go up
var thisLayer = srcDoc.layers[i];
thisLayer.visible = true;
// duplicate image into new document
duplicate_it(docName);
// active document is now the NEW one!
// flatten it
activeDocument.flatten();
jpeg_it(myFolder + docName, 12);
// close the image WITHOUT saving as we've just saved it
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// make the source document the active document
app.activeDocument = srcDoc;
// switch OFF the layer
thisLayer.visible = false;
}
// function DUPLICATE IT (str)
// --------------------------------------------------------
function duplicate_it(str)
{
// duplicate image into new document
if (arguments.length == 0) str = "temp";
var id428 = charIDToTypeID( "Dplc" );
var desc92 = new ActionDescriptor();
var id429 = charIDToTypeID( "null" );
var ref27 = new ActionReference();
var id430 = charIDToTypeID( "Dcmn" );
var id431 = charIDToTypeID( "Ordn" );
var id432 = charIDToTypeID( "Frst" );
ref27.putEnumerated( id430, id431, id432 );
desc92.putReference( id429, ref27 );
var id433 = charIDToTypeID( "Nm " );
desc92.putString( id433, str ); // name
executeAction( id428, desc92, DialogModes.NO );
}
// function JPEG IT (file path + file name, jpeg quality)
// ----------------------------------------------------------------
function jpeg_it(filePath, jpgQuality)
{
if(! jpgQuality) jpgQuality = 12;
// jpg file options
var jpgFile = new File(filePath);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpgQuality;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

Related

Updating Texture2D frequently causes process to crash (UpdateSubresource)

I am using SharpDX to basically render browser (chromium) output buffer on directX process.
Process is relatively simple, I intercept CEF buffer (by overriding OnPaint method) and write that to a texture2D.
Code is relatively simple:
Texture creation:
public void BuildTextureWrap() {
var oldTexture = texture;
texture = new D3D11.Texture2D(DxHandler.Device, new D3D11.Texture2DDescription() {
Width = overlay.Size.Width,
Height = overlay.Size.Height,
MipLevels = 1,
ArraySize = 1,
Format = DXGI.Format.B8G8R8A8_UNorm,
SampleDescription = new DXGI.SampleDescription(1, 0),
Usage = D3D11.ResourceUsage.Default,
BindFlags = D3D11.BindFlags.ShaderResource,
CpuAccessFlags = D3D11.CpuAccessFlags.None,
OptionFlags = D3D11.ResourceOptionFlags.None,
});
var view = new D3D11.ShaderResourceView(
DxHandler.Device,
texture,
new D3D11.ShaderResourceViewDescription {
Format = texture.Description.Format,
Dimension = D3D.ShaderResourceViewDimension.Texture2D,
Texture2D = { MipLevels = texture.Description.MipLevels },
}
);
textureWrap = new D3DTextureWrap(view, texture.Description.Width, texture.Description.Height);
if (oldTexture != null) {
obsoleteTextures.Add(oldTexture);
}
}
That piece of code is executed at start and when resize is happening.
Now when CEF OnDraw I basically copy their buffer to texture:
var destinationRegion = new D3D11.ResourceRegion {
Top = Math.Min(r.dirtyRect.y, texDesc.Height),
Bottom = Math.Min(r.dirtyRect.y + r.dirtyRect.height, texDesc.Height),
Left = Math.Min(r.dirtyRect.x, texDesc.Width),
Right = Math.Min(r.dirtyRect.x + r.dirtyRect.width, texDesc.Width),
Front = 0,
Back = 1,
};
// Draw to the target
var context = targetTexture.Device.ImmediateContext;
context.UpdateSubresource(targetTexture, 0, destinationRegion, sourceRegionPtr, rowPitch, depthPitch);
There are some more code out there but basically this is only relevant piece. Whole thing works until OnDraw happens frequently.
Apparently if I force CEF to Paint frequently, whole host process dies.
This is happening at UpdateSubresource.
So my question is, is there another, safer way to do this? (Update texture frequently)
Solution to this problem was relatively simple yet not so obvious at the beginning.
I simply moved the code responsible for updating texture inside render loop and just keep internal buffer pointer cached.

Urhosharp Material.FromImage not woking with some jpg files

I'm using Xamarin.Forms with Urhosharp in my project. I'm tring to set a matrial from an image on a sphere, everything is OK in my Android project but in iOS project, when I set material from some jpg files it doesn't work and all I get is a black screen.
Here is the jpg that works correctly:
And here is the other one that doesn't:
This is my code:
var scene = new Scene();
scene.CreateComponent<Octree>();
// Node (Rotation and Position)
var node = scene.CreateChild("room");
node.Position = new Vector3(0, 0, 0);
//node.Rotation = new Quaternion(10, 60, 10);
node.SetScale(1f);
// Model
var modelObject = node.CreateComponent<StaticModel>();
modelObject.Model = ResourceCache.GetModel("CustomModels/SmoothSphere.mdl");
var zoneNode = scene.CreateChild("Zone");
var zone = zoneNode.CreateComponent<Zone>();
zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
zone.AmbientColor = new Color(1f, 1f, 1f);
//get image from byte[]
//var url = "http://www.wsj.com/public/resources/media/0524yosemite_1300R.jpg";
//var wc = new WebClient() { Encoding = Encoding.UTF8 };
//var mb = new MemoryBuffer(wc.DownloadData(new Uri(url)));
var mb = new MemoryBuffer(PanoramaBuffer.PanoramaByteArray);
var image = new Image(Context) { Name = "MyImage" };
image.Load(mb);
//or from resource
//var image = ResourceCache.GetImage("Textures/grave.jpg");
var isFliped = image.FlipHorizontal();
if (!isFliped)
{
throw new Exception("Unsuccessful flip");
}
var m = Material.FromImage("1.jpg");
m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
m.CullMode = CullMode.Cw;
//m.SetUVTransform(Vector2.Zero, 0, 0);
modelObject.SetMaterial(m);
// Camera
var cameraNode = scene.CreateChild("camera");
_camera = cameraNode.CreateComponent<Camera>();
_camera.Fov = 75.8f;
_initialZoom = _camera.Zoom;
// Viewport
Renderer.SetViewport(0, new Viewport(scene, _camera, null));
I already tried to change compression level, ICCC profile and ...
I asked the same question in forums.xamarin.com and someone answered the question and I'll share it here :
In iOS every texture needs to have a power of two resolution, like 256 x 256 or 1024 x 512. Check if that is the issue. Additionally check that your using the latest UrhoSharp version.
Also make sure that the image is set as BundleResource in the iOS project.

How to dynamically change texture of PIXI.Sprite when PIXI.Sprite reaches certain position - Pixi.js?

I have a class which extends PIXI.Sprite. Here i create the sprite initially. The texture i use is a spritesheet and i create sprites from random sections of this spritesheet.png by creating random frames for the texture. There I add 10000 sprites and move them in random directions. Then I add the PIXI.Sprite class in another class which extends PIXI.ParticleContainer 10,000 times.
createTexture() {
this.textureWidth = 2048;
this.rectX = () => {
let number;
while (number % 32 !== 0) number = Math.floor(Math.random() * this.textureWidth) + 0;
return number;
}
this.rectY = () => {
let number;
while (number % 32 !== 0) number = Math.floor(Math.random() * 128) + 0;
return number;
}
this.initialTexture = PIXI.Texture.from(this.resources[assets.images[0].src].name);
this.rectangle = new PIXI.Rectangle(this.rectX(), this.rectY(), 32, 32);
this.initialTexture.frame = this.rectangle;
this.texture = new PIXI.Texture(this.initialTexture.baseTexture, this.initialTexture.frame);
this.texture.requiresUpdate = true;
this.texture.updateUvs();
this.timesChangedVy = 0;
}
When a Sprite hits window borders, i call the method change texture in the class of PIXI.Sprite:
changeTexture() {
let newTexture = PIXI.Texture.from(this.resources[assets.images[0].src].name);
let rectangle = new PIXI.Rectangle(this.rectX(), this.rectY(), 32, 32);
newTexture.frame = rectangle;
// this.texture.frame = rectangle
this.texture = newTexture;
// this.texture = new PIXI.Texture.from(this.resources[assets.images[0].src].name)
// this.texture._frame = rectangle
// this.texture.orig = rectangle
// this._texture = newTexture
// this.texture = new PIXI.Texture(newTexture.baseTexture, rectangle)
this.texture.update()
this.texture.requiresUpdate = true;
this.texture.updateUvs();
}
I tried different approaches. When i console.log the texture after changing it , i see that the frame and origins have been changed, but the new texture is not being rendered.
Does someone know where the problem lies and how i can fix it?
Finally, I found the reason for my sprites not updating on texture change.
It is because I add them as children of Pixi.ParticleContainer, which has less functionality than Pixi.Container and does not update Uvs of children by default.
THE SOLUTION IS TO SET uvs to true when creating PIXI.ParticleContainer.
It looks like this: new PIXI.ParticleContainer(10000, { uvs: true }).
This will solve the problem of changing textures not being updated and uvs will be uploaded and applied.
https://pixijs.download/dev/docs/PIXI.ParticleContainer.html

How to create a stock event in amCharts v4?

Is it possible to indicate events along a series in amCharts v4 similar to the Stock Event in the v3 stock chart?
While I was brought on board specifically for v4 and am not familiar with v3, I'm confident you can simulate some of these features using Bullets.
A bullet is a Container (basically a placeholder parent for whatever visual object or additional Containers that you want), that will appear at every point of data. You can put a label there as well as a line and any other shape, e.g.:
var stockBullet = series.bullets.push(new am4charts.Bullet());
stockBullet.dy = -20;
var circle = stockBullet.createChild(am4core.Circle);
circle.stroke = "#000";
circle.strokeWidth = 1;
circle.radius = 10;
circle.fill = series.fill.brighten(-0.3);
circle.dy = -10;
var line = stockBullet.createChild(am4core.Line);
line.stroke = "#000";
line.strokeWidth = 1;
line.height = 20;
var label = stockBullet.createChild(am4core.Label);
label.fill = am4core.color("#000");
label.strokeWidth = 0;
label.dy = -20;
label.textAlign = "middle";
label.horizontalCenter = "middle"
Since we don't want a bullet to appear at every point of data, only at Stock Events, we can handle that once the bullets are ready on the chart by going through their data, disabling them if need be, otherwise providing text for our label (and maybe tooltipText if need be) (presume there is a property stockEvent in the data):
stockBullet.events.on("inited", function(event) {
if (event.target.dataItem && event.target.dataItem.dataContext && event.target.dataItem.dataContext.stockEvent) {
event.target.children.getIndex(2).text = event.target.dataItem.dataContext.stockEvent.text;
} else {
event.target.disabled = true;
}
});
Getting tooltips of different objects to play well with each other can be tricky depending on your chart, e.g. if it has Chart Cursor enabled there's a cursorTooltipEnabled property to prevent triggering a tooltip over bullets. To simplify things in this case what I did is make an invisible series per unique stock event bullet. For each stock event, use adapters to set its paired series' tooltipText to what's desired, and the base, visible series' tooltipText to "":
series.adapter.add("tooltipText", function(text, target) {
if (target.tooltipDataItem.dataContext.stockEvent) {
return "";
}
return text;
});
// ...
hiddenSeries.adapter.add("tooltipText", function(text, target) {
if (target.tooltipDataItem.dataContext.stockEvent) {
return target.tooltipDataItem.dataContext.stockEvent.description;
}
return "";
});
Here's a demo:
https://codepen.io/team/amcharts/pen/337984f18c6329ce904ef52a0c3eeaaa
Screenshot:

Applescript: Getting list of selected layers on Photoshop

I am creating an AppleScript where I need to do something to the selected layers on Photoshop.
How do I get the list of the selected layers on Photoshop even if the selected layers are inside groups?
I don't have code to show right now because it all starts by having the list of selected layers, sorry.
Selected layers is not a property in JavaScript's artLayer object and selected is not an property of the layer object in AppleScript either. However we can work with AM in PhotoShop and use actions and it's descriptor result to get the selected layers. Because the layers may need to swift depending on whether there is an background layer or not we first create an array with selected indices (code is based on this post) and after that we resolve the names of the layers.
tell application "Adobe Photoshop CS6"
tell document 1
set selectedLayers to paragraphs of (do javascript "
var typeDocument = stringIDToTypeID('document');
var typeItemIndex = stringIDToTypeID('itemIndex');
var typeLayer = stringIDToTypeID('layer');
var typeName = stringIDToTypeID('name');
var typeOrdinal = stringIDToTypeID('ordinal');
var typeProperty = stringIDToTypeID('property');
var typeTarget = stringIDToTypeID('targetEnum');
var typeTargetLayers = stringIDToTypeID('targetLayers');
var selectedLayers = new Array();
var actionRef = new ActionReference();
actionRef.putEnumerated(typeDocument, typeOrdinal, typeTarget);
var actionDesc = executeActionGet(actionRef);
if(actionDesc.hasKey(typeTargetLayers) ){
actionDesc = actionDesc.getList(typeTargetLayers);
var c = actionDesc.count
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push(actionDesc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push(actionDesc.getReference( i ).getIndex()+1 );
}
}
}else{
var actionRef = new ActionReference();
actionRef.putProperty(typeProperty , typeItemIndex);
actionRef.putEnumerated(typeLayer, typeOrdinal, typeTarget);
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(actionRef).getInteger(typeItemIndex)-1);
}catch(e){
selectedLayers.push( executeActionGet(actionRef).getInteger(typeItemIndex));
}
}
var selectedLayerNames = new Array();
for (var a in selectedLayers){
var ref = new ActionReference();
ref.putIndex(typeLayer, Number(selectedLayers[a]) );
var layerName = executeActionGet(ref).getString(typeName);
selectedLayerNames.push(layerName);
}
selectedLayerNames.join('\\n');
")
end tell
end tell

Resources