All nice answers, thanks for the contribution.
As I said, I wondering if there was something out there for Photoshop.
For documentation purposes here is a little script I wrote:
var doc = app.activeDocument;
var arranger = makeDialog();
arranger .arrange.onClick = function(){
if(isNaN(parseInt(arranger.w.text)) || isNaN(parseInt(arranger.h.text)) || isNaN(parseInt(arranger.c.text)) || isNaN(parseInt(arranger.r.text))){
alert('Yo! Can you feed \' dis dialog some integer numbers ?\n For Real!');
}else{
sliceLayer(parseInt(arranger.w.text),parseInt(arranger.h.text),parseInt(arranger.r.text),parseInt(arranger.c.text));
}
arranger.close();
}
arranger.show();
function sliceLayer(w,h,r,c){
var hw = w * 0.5;
var hh = h * 0.5;
var l0 = doc.activeLayer;
for(var j = 0 ; j < r ; j++){
for(var i = 0 ; i < c; i++){
var x = i * w; //edited
var y = j * h; //here
//select
doc.selection.select([[x,y],[x+w,y],[x+w,y+h],[x,y+h]]);
//new layer via cut
doc.selection.cut();
var layer = doc.artLayers.add();
doc.paste();
//move
//$.writeln('translate x: '+(y)+', y: '+(x));
layer.translate(y,x);
doc.activeLayer = l0;
}
}
l0.remove();//remove original layer(now empty)
}
function makeDialog(){
var dialog = new Window('dialog','Slice and Dice');
dialog.frameLocation = [300,300];
dialog.w = dialog.add('edittext',undefined,'Selection width');
dialog.w.prefferedSize = [200,50];
dialog.h = dialog.add('edittext',undefined,'Selection height');
dialog.h.prefferedSize = [200,50];
dialog.c = dialog.add('edittext',undefined,'Grid Columns(V sections)');
dialog.c.prefferedSize = [200,50];
dialog.r = dialog.add('edittext',undefined,'Grid Rows(H sections)');
dialog.r.prefferedSize = [200,50];
dialog.arrange = dialog.add('button',undefined,'Chop Chop');
return dialog;
}
If you save this in Photoshop/Presets/Scripts, you should be able to access it through Scripts in the File menu.
The problem with the JSX approach is, it is a bit slow for large subdivisions (100x100).
I'm guessing it will be faster to try with MATLAB/Photoshop communication, but I'll skip that for now.
Achieved the same goal in actionscript 3 using copyPixels() and it's pretty fast.