Skip to content

Commit 7de58ef

Browse files
authored
Merge pull request #32 from ilija139/master
Default Tensor type fix
2 parents 4129d39 + f918e52 commit 7de58ef

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ function M.configure(config)
6060
end
6161

6262
function M.image(img, opts)
63+
64+
local defaultType = torch.getdefaulttensortype()
65+
-- the image package expects this to be DoubleTensor
66+
-- if CudaTensor then clampImage from package image will attempt to index field 'image' (a nil value) of the CudaTensor
67+
torch.setdefaulttensortype('torch.DoubleTensor')
68+
6369
-- options:
6470
opts = opts or {}
6571

@@ -82,6 +88,7 @@ function M.image(img, opts)
8288
local inmem_img = image.compressJPG(img)
8389
local imgdata = 'data:image/jpg;base64,' .. mime.b64(ffi.string(inmem_img:data(), inmem_img:nElement()))
8490

91+
torch.setdefaulttensortype(defaultType)
8592

8693
return pane('image', opts.win, opts.title, { src=imgdata, labels=opts._labels, width=opts.width })
8794
end

static/panes.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ function Pane(id) {
117117
cloneButton.innerHTML = 'o';
118118
cloneButton.title = 'disconnect';
119119

120-
var saveButton = document.createElement('a');
121-
saveButton.innerHTML = '⤓';
122-
saveButton.title = 'save';
123-
saveButton.download = 'untitled_image.jpg';
124-
saveButton.href = '';
125-
126120
var title = document.createElement('div');
127121
title.className = 'title';
128122

@@ -135,14 +129,12 @@ function Pane(id) {
135129
this.grip = grip;
136130
this.title = title;
137131
this.content = content;
138-
this.saveButton = saveButton;
139132

140133
el.appendChild(grip);
141134
el.appendChild(bar);
142135
el.appendChild(content);
143136
bar.appendChild(closeButton);
144137
bar.appendChild(cloneButton);
145-
bar.appendChild(saveButton);
146138
bar.appendChild(title);
147139
body.appendChild(el);
148140

@@ -196,7 +188,6 @@ function Pane(id) {
196188
Pane.prototype = {
197189
setTitle: function(title) {
198190
this.title.innerHTML = title;
199-
this.saveButton.download = title.replace(/\s+/g, '_') + '.jpg';
200191
},
201192

202193
focus: function() {
@@ -343,6 +334,12 @@ function ImagePane(id) {
343334
var self = this
344335
, content = this.content;
345336

337+
var saveButton = document.createElement('a');
338+
saveButton.innerHTML = '⬇';
339+
saveButton.title = 'save';
340+
saveButton.download = 'untitled_image.jpg';
341+
saveButton.href = '';
342+
346343
var image = document.createElement('img');
347344
image.className = 'content-image';
348345
content.appendChild(image);
@@ -351,6 +348,10 @@ function ImagePane(id) {
351348
labels.className = 'labels';
352349
content.appendChild(labels);
353350

351+
352+
this.bar.appendChild(saveButton);
353+
354+
this.saveButton = saveButton;
354355
this.content = image;
355356
this.labels = labels;
356357
this.width = 0;
@@ -379,8 +380,6 @@ function ImagePane(id) {
379380

380381
on(image, 'load', function(ev) {
381382
if ((image.naturalWidth != self.width) || (image.naturalHeight != self.height)) {
382-
self.width = image.naturalWidth;
383-
self.height = image.naturalHeight;
384383
self.reset();
385384
}
386385
});
@@ -487,10 +486,13 @@ ImagePane.prototype = extend(Object.create(Pane.prototype), {
487486
},
488487

489488
setContent: function(content) {
489+
490+
this.saveButton.href = content.src;
491+
this.saveButton.download = this.title.innerHTML.replace(/\s+/g, '_') + '.jpg';
492+
490493
// Hack around unexpected behavior. Setting .src resets .style (except 'position: absolute').
491494
var oldCss = this.content.style.cssText;
492495
this.content.src = content.src;
493-
this.saveButton.href = content.src;
494496
this.content.style.cssText = oldCss;
495497
if (this.content.style.cssText != oldCss) {
496498
this.content.style.cssText = oldCss;

0 commit comments

Comments
 (0)