Giter Site home page Giter Site logo

you-app / bitmappery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from igorski/bitmappery

1.0 0.0 0.0 2.04 MB

Browser based non-destructive photo editor with layering, masking, customizable brushes and Dropbox integration for all your web based working.

Home Page: https://www.igorski.nl/bitmappery

License: MIT License

JavaScript 57.16% C++ 0.43% HTML 0.20% Vue 39.76% SCSS 2.45%

bitmappery's Introduction

BitMappery

So you are rebuilding Photoshop in the browser ?

No, I'm building a tool that does the bare minimum what I require and what I don't find in other open source tools. That doesn't mean of course that contributions related to Photoshop-esque features aren't welcomed.

The Issue Tracker is your point of contact

Bug reports, feature requests, questions and discussions are welcome on the GitHub Issue Tracker, please do not send e-mails through the development website. However, please search before posting to avoid duplicates, and limit to one issue per post.

Please vote on feature requests by using the Thumbs Up/Down reaction on the first post.

All hand-written ?

Yep, though it helps having worked in the photo software industry for five years, having tackled the problems before. Also, BitMappery is reusing zCanvas under the hood for rendering and bitmap blitting. BitMappery is written on top of Vue using Vuex and VueI18n.

Model

BitMappery works with entities known as Documents. A Document contains several Layers, each of which define their content, transformation, Effects, etc. Each of the nested entity properties has its own factory (see /src/factories/). The Document is managed by the Vuex document-module.js.

Document rendering and interactions

The Document is rendered one layer at a time onto a Canvas element, using zCanvas. Both the rendering and interaction handling is performed by dedicated "Sprite" classes.

All layer rendering and interactions are handled by /src/rendering/canvas-elements/layer_sprite.js. Note that the purpose of the renderer is solely to delegate interactions events to the Layer entity. The renderer should represent the properties of the Layer, the Layer should never reverse-engineer from the onscreen content (especially as different window size and scaling factor will greatly complicate these matters when performed two-way).

Rendering transformations, text and effects is an asynchronous operation handled by /src/services/render-service.js. The purpose of this service is to perform and cache repeated operations and eventually maintain the source bitmap represented by the LayerSprite. The LayerSprite invokes the rendering service.

All interactions that work across layers (viewport panning, layer selection by clicking on non-transparent pixels and selection drawing) is done by a single top level sprite that covers the entire zCanvas area. This is handled by /src/rendering/canvas-elements/interaction-pane.js.

State history

Mutations can be registered in state history (Vuex history-module.js) in order to provide undo and redo of operations. In order to prevent storing a lot of changes of the same property (for instance when dragging a slider), the storage of a new state is deferred through a queue. This is why history states are enqueued by propertyName:

When enqueuing a new state while there is an existing one enqueued for the same property name, the first state is updated so its redo will match that of the newest state, the undo remaining unchanged. The second state will not be added to the queue.

It is good to understand that the undo/redo for an action should be considered separate from the Vue component that is triggering the transaction, the reason being that the component can be unmounted at the moment the history state is changed (and the component is no longer active).

That's why undo/redo handlers should either work on variables in a local scope, or on the Vuex store when mutating store properties. When relying on store state and getters, be sure to cache their values in the local scope to avoid conflicts (for instance in below example we cache activeLayerIndex as it is used by the undo/redo methods to update a specific Layer. activeLayerIndex can change during the application lifetime before the undo/redo handler fires which would otherwise lead to the wrong Layer being updated.

update( propertyName, newValue ) {
    // cache the existing values of the property value we are about to mutate...
    const existingValue = this.getterForExistingValue;
    // ...and the layer index that is used to identify the layer containing the property
    const index = this.activeLayerIndex;
    const store = this.$store;
    // define the method that will mutate the existing value to given newValue
    const commit = () => store.commit( "updateLayer", { index, opts: { newValue } });
    // and perform the mutation directly
    commit();
    // now define and enqueue undo/redo handlers to reverse and redo the commit mutation
    enqueueState( propertyName, {
        undo() {
            store.commit( "updateLayerEffects", { index, opts: { existingValue } });
        },
        redo() {
            commit();
        },
    });
}

Whenever an action (that requires an undo state) can be triggered in multiple locations (for instance inside a component and as a keyboard shortcut in @/src/services/keyboard-service), you can create a custom handler inside @/src/factories/action-factory to avoid code duplication.

Dropbox integration

Requires you to register a client id or access token.

Project setup

The project setup is two-fold. You can get all the dependencies through NPM as usual:

npm install

after which you can run:

  • npm run serve to start a local development server with hot module reload
  • npm run build to compile a production package
  • npm run test to run the unit tests
  • npm run lint to run the linter on the source files

The above will suffice when working solely on the JavaScript side of things.

WebAssembly

BitMappery can also use WebAssembly to increase performance of image manipulation. The source code is C based and compiled to WASM using Emscripten. Because this setup is a little more cumbersome, the repository contains precompiled binaries in the ./public/bin/-folder meaning you can omit this setup if you don't intend to make changes to these sources.

If you do wish to make contributions on this end, to compile the source (/src/wasm/) C-code to WASM, you will first need to prepare your environment (note the last source call does not permanently update your paths):

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

now you can compile all source files to WASM using:

npm run wasm

Benchmarks

On a particular (low powered) configuration, running all filters on a particular source takes:

  • 7000+ ms in JavaScript
  • 558 ms in WebAssembly
  • 484 ms in JavaScript inside a Web Worker
  • 603 ms in WebAssembly inside a Web Worker

Note that the WebAssembly Web Worker takes a performance hit from converting the ImageData buffer to float32 prior to allocating the buffer in the WASM instance's memory. This can benefit from further tweaking to see if it gets closer to the JavaScript Web Worker performance.

WebAssembly filtering is a user controllable feature in the preferences pane.

bitmappery's People

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.