Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/dicomweb-serve/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
90 changes: 90 additions & 0 deletions packages/dicomweb-serve/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('dicomweb-serve:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
16 changes: 16 additions & 0 deletions packages/dicomweb-serve/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "dicomweb-serve",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1"
}
}
8 changes: 8 additions & 0 deletions packages/dicomweb-serve/public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
9 changes: 9 additions & 0 deletions packages/dicomweb-serve/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

module.exports = router;
9 changes: 9 additions & 0 deletions packages/dicomweb-serve/routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});

module.exports = router;
6 changes: 6 additions & 0 deletions packages/dicomweb-serve/views/error.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends layout

block content
h1= message
h2= error.status
pre #{error.stack}
5 changes: 5 additions & 0 deletions packages/dicomweb-serve/views/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends layout

block content
h1= title
p Welcome to #{title}
7 changes: 7 additions & 0 deletions packages/dicomweb-serve/views/layout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
14 changes: 12 additions & 2 deletions packages/static-cs-lite/lib/api/getRenderedBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const canvasImageToBuffer = require("../adapters/canvasImageToBuffer");
* @param {*} metadata
* @param {*} doneCallback Callback method that is invoked once image is rendered
*/
function getRenderedBuffer(transferSyntaxUid, decodedPixelData, metadata, doneCallback) {
function getRenderedBuffer(
transferSyntaxUid,
decodedPixelData,
metadata,
doneCallback,
) {
const { csCore, canvas, context } = setUpEnv();

function doneRendering(customEvent = {}) {
Expand All @@ -32,7 +37,12 @@ function getRenderedBuffer(transferSyntaxUid, decodedPixelData, metadata, doneCa
}

try {
const imageObj = createImage(transferSyntaxUid, decodedPixelData, metadata, canvas);
const imageObj = createImage(
transferSyntaxUid,
decodedPixelData,
metadata,
canvas,
);

canvas.addEventListener(csCore.EVENTS.IMAGE_RENDERED, doneRendering);
csCore.renderToCanvas(canvas, imageObj);
Expand Down
56 changes: 48 additions & 8 deletions packages/static-cs-lite/lib/api/renderToCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ function setContextStyles(ctx, styles, styleKeys) {
}
});
}
function renderTextToCanvas(canvas, text, pos, size, styles = { textStyle: DEFAULT_STYLES.textStyle }) {
function renderTextToCanvas(
canvas,
text,
pos,
size,
styles = { textStyle: DEFAULT_STYLES.textStyle },
) {
const [x, y] = pos;
const ctx = canvas.getContext("2d");
setContextStyles(ctx, styles, ["textStyle"]);
Expand All @@ -39,7 +45,12 @@ function renderTextToCanvas(canvas, text, pos, size, styles = { textStyle: DEFAU
};
}

function renderLinesToCanvas(canvas, points, size, styles = { lineStyle: DEFAULT_STYLES.lineStyle }) {
function renderLinesToCanvas(
canvas,
points,
size,
styles = { lineStyle: DEFAULT_STYLES.lineStyle },
) {
const ctx = canvas.getContext("2d");

if (!points.length || !ctx) {
Expand All @@ -60,7 +71,12 @@ function renderLinesToCanvas(canvas, points, size, styles = { lineStyle: DEFAULT
ctx.stroke();
}

function renderPointToCanvas(canvas, point, size, styles = { pointSyle: DEFAULT_STYLES.pointStyle }) {
function renderPointToCanvas(
canvas,
point,
size,
styles = { pointSyle: DEFAULT_STYLES.pointStyle },
) {
const ctx = canvas.getContext("2d");

if (!point || !ctx) {
Expand All @@ -75,7 +91,13 @@ function renderPointToCanvas(canvas, point, size, styles = { pointSyle: DEFAULT_
ctx.fill();
}

function renderHLineToCanvas(canvas, position, width, height, styles = { lineStyle: DEFAULT_STYLES.lineStyle }) {
function renderHLineToCanvas(
canvas,
position,
width,
height,
styles = { lineStyle: DEFAULT_STYLES.lineStyle },
) {
const points = [
[position[0], position[1]],
[position[0] + width, position[1]],
Expand Down Expand Up @@ -127,7 +149,7 @@ function renderPointsToCanvas(
styles = {
lineStyle: DEFAULT_STYLES.lineStyle,
pointStyle: DEFAULT_STYLES.pointStyle,
}
},
) {
points.forEach((point, index) => {
const useStyles = { ...styles };
Expand Down Expand Up @@ -158,13 +180,31 @@ function renderContentToCanvas(enabledElement, content, styles) {
let result;
switch (content.type) {
case "text":
result = renderTextToCanvas(enabledElement.canvas, content.text, content.position, content.size, styles);
result = renderTextToCanvas(
enabledElement.canvas,
content.text,
content.position,
content.size,
styles,
);
break;
case "hLine":
result = renderHLineToCanvas(enabledElement.canvas, content.position, content.width, content.height * content.size, styles);
result = renderHLineToCanvas(
enabledElement.canvas,
content.position,
content.width,
content.height * content.size,
styles,
);
break;
case "points":
result = renderPointsToCanvas(enabledElement.canvas, content.points, content.strategy, content.size, styles);
result = renderPointsToCanvas(
enabledElement.canvas,
content.points,
content.strategy,
content.size,
styles,
);
break;
default:
throw new Error(`Unknown type ${content.type} in ${content}`);
Expand Down
Loading