About graphic system

 Kirikiri has a graphic display mechanism using layers.
 Each layer has transparency superimposition by alpha blending and hierarchical structure management function. In addition, it has a mechanism (focus) for receiving input from the user so that the layer can be operated as a GUI part (widget).

 The superimposed layers are drawn in the window using a mechanism called a drawing device. By default, a device called BasicDrawDevice is used that simply draws the output of the layer into the window. The drawing device can be freely replaced by manipulating the Window.drawDevice property, and the user can define his own rendering effects etc. (in the form of a plug-in) according to the application. Kirikiri Z has only the above-mentioned BasicDrawDevice.

Readable and writable image formats

 In the standard state Kirikiri, the format that can be read into the layer with Layer.loadImages and can be written to the layer is as follows.

BMP
 Windows standard bitmap format. A 32 bpp BMP is considered a bitmap with an alpha channel.
 RLE compressed bitmaps cannot be read.
PNG
 Portable Network Graphic format can be read. You can also import bitmap PNGs with an alpha channel.
JPEG
 JPEG format can be read. Arithmetic-compressed or lossless-compressed ones cannot be read, but I rarely see them in the first place.
TLG5
 Kirikiri is a unique lossless compression format. The extension is .tlg. You can also load those with an alpha channel. The compression ratio is not very high, but the feature is that it can be expanded at high speed. This format cannot be used for mask images (_m) or region images (_p). Only full color images without alpha channel or full color images with alpha channel can be handled.
TLG6
 Kirikiri is a unique lossless compression format. The extension is .tlg like TLG5. TLG6 features a high compression ratio. Decompression speed is slightly less than twice as fast as TLG5, but it can still be decompressed more than twice as fast as PNG, and its size is 2-40% smaller than PNG.
JPEG XR
 JPEG XR format can be read. It is lossy but has higher quality than JPEG and supports alpha channel.
 Compressing with priority on image quality makes it difficult to distinguish from lossless compressed images, and is useful when the size is important because the file size is small.
 Supported from Ver 1.1.0, currently only supports reading.
 Ver. 1.3.0 also supports saving.
Main / mask separation format
 The main / mask separation format is a format in which the color information image (main) and the alpha channel (mask) image are separated, and the mask image is the main image file name with _m appended (abc_m.jpeg for abc.jpeg).
 The format of the main / mask image can be different.

 In addition, you can increase the number of image formats that can be loaded using Susie Plug-in. Susie plug-in can be read by Plugins.link method.
 If a 32bpp bitmap is passed from Susie Plug-in, it is considered a bitmap with an alpha channel.

Layer type

 The Kirikiri layer can be displayed in various composite modes (layer types).
 The following compositing modes are available, and layer type constants starting with lt can be specified in the Layer.type property.
 In the formula, result is the result, dest is the luminance of the image to be superimposed, src is the luminance of the image to be superimposed, α is the alpha value for each pixel of the image to be superimposed, and the range of all values is 0.0 to 1.0.
 In addition, the following functions are defined here for explanation.

ltOpaque (ltCoverRect)
 ltOpaque is a display without transparency. The entire rectangle of the layer is always fully opaque (not limited to this layer type, but if Layer.opacity is used to reduce opacity).

Formula: result = src

Note
The same is true for ltCoverRect, but it is an older name before 2.23 beta 2.

ltAlpha (ltTransparent)
 ltAlpha performs alpha compositing. This is the most basic type when performing transmission. The following equation is also used for alpha channel input from BMP and Susie plug-in.

Formula: result = blend(dest, src, α)

Note
ltTransparent has the same meaning, but is an older name before 2.23 beta 2.

ltAddAlpha
 ltAddAlpha performs additive alpha compositing.
 Image format converter can output images suitable for this format. You can also convert from ltAlpha to this format with the Layer.convertType method.
 The ltAddAlpha layer will not display properly if it is a direct child of the ltAlpha layer.

Formula: result = min(1.0, dest ( 1.0 - α ) + src)
ltAdditive
 ltAdditive performs additive composition. Suitable for expressing glow. Dodge (linear) in Photoshop, but if you want to get the same effect as Photoshop, use ltPsAdditive described later. Unlike ltPsAdditive, α is ignored in ltAdditive.
 Neutral colors (colors that do not change when superimposed) are black.

Formula: result = min(1.0, dest + src)
ltSubtractive
 ltSubtractive performs subtractive composition. α is ignored.
 Neutral color is white.

Formula: result = max(0.0, dest + src - 1.0)

Note
 The only difference from result = dest - src is whether src is inverted or not.

ltMultiplicative
 ltMultiplicative performs multiplicative synthesis. α is ignored.
 Neutral color is white.

Formula result = dest src
ltDodge
 ltDodge performs "dodging" compositing. Suitable for expressing objects illuminated by light. α is ignored.
 Neutral color is black.

Formula: result = min(1.0, dest ( 1.0 - src ) )
ltLighten
 ltLighten performs "comparison (light)" synthesis. α is ignored.
 Neutral color is black.

Formula: result = max(dest, src)
ltDarken
 ltDarken performs a "compare (dark)" synthesis. α is ignored.
 Neutral color is white.

Formula: result = min(dest, src)
ltScreen
 ltLighten performs "screen multiplication" synthesis. α is ignored.
 Neutral color is black.

Formula: result = 1.0 - ( 1.0 - dest ) ( 1.0 - src )
ltPsNormal
 ltPsNormal has the same effect as ltAlpha. For historical reasons, it has a different routine and name than ltAlpha.
ltPsAdditive
 ltPsAdditive performs Photoshop-compatible "dodging (linear)" synthesis (additional synthesis). Unlike ltAdditive, α is not ignored.
 Neutral color is black.

Formula: result = blend(dest, min(1.0, dest + src), α)
ltPsSubtractive
 ltPsSubtractive performs Photoshop-compatible "burn-in (linear)" synthesis (subtraction synthesis). Unlike ltSubtractive, α is not ignored.
 Neutral color is white.

Formula: result = blend(dest, max(0.0, dest + src - 1.0), α)
ltPsMultiplicative
 ltPsMultiplicative provides Photoshop compatible "multiply" compositing. Unlike ltMultiplicative, α is not ignored.
 Neutral color is white.

Formula: result = blend(dest, dest src, α)
ltPsScreen
 ltPsScreen provides Photoshop compatible "screen" compositing. Unlike ltScreen, α is not ignored.
 Neutral color is black.

Formula: result = blend(dest, 1.0 - (1.0 - dest) (1.0 - src), α)
ltPsOverlay
 ltPsOverlay provides Photoshop compatible "overlay" compositing.
 Neutral color is 50% gray.

Formula: result = blend(dest, overlay(dest, src), α)
Where overlay(a, b) =
 a b 2.0 ( When a < 0.5 )
 1.0 - (1.0 - a) (1.0 - b) 2.0 (At other times)
ltPsHardLight
 ltPsHardLight provides Photoshop compatible "hard light" compositing.
 Neutral color is 50% gray.

Formula: result = blend(dest, hardlight(dest, src), α)
Where hardlight(a, b) =
 a b 2.0 ( When b < 0.5 )
 1.0 - (1.0 - a) (1.0 - b) 2.0 (At other times)
ltPsSoftLight
 ltPsSoftLight provides Photoshop compatible "soft light" compositing.
 Neutral color is 50% gray.

Formula: result = blend(dest, softlight(dest, src), α)
When softlight(a, b) =
 a(0.5 b) ( When b > 0.5 )
 a((1.0 - b) 2) (At other times)
ltPsColorDodge
 ltPsColorDodge provides Photoshop compatible "dodge color" compositing. Unlike ltDodge, α is not ignored.
 Neutral color is black.

Formula: result = blend(dest, min(1.0, dest ( 1.0 - src ) ), α)
ltPsColorDodge5
 ltPsColorDodge provides "dodging color" compositing compatible with Photoshop versions 5.x and below. The formula is slightly different from ltPsColorDodge.
 Neutral color is black.

Formula: result = min(1.0, dest ( 1.0 - src α) )
ltPsColorBurn
 ltPsColorBurn provides Photoshop compatible "burn-in color" compositing.
 Neutral color is white.

Formula: result = blend(dest, max(0.0, 1.0 - (1.0 - dest) src), α)
ltPsLighten
 ltPsLighten performs Photoshop-compatible "comparison (light)" compositing. Unlike ltLighten, α is not ignored.
 Neutral color is black.

Formula: result = blend(dest, max(dest, src), α)
ltPsDarken
 ltPsDarken performs Photoshop-compatible "compare (dark)" compositing. Unlike ltDarken, α is not ignored.
 Neutral color is white.

Formula: result = blend(dest, min(dest, src), α)
ltPsDifference
 ltPsDifference provides Photoshop compatible "absolute difference" compositing.
 Neutral color is black.

Formula: result = blend(dest, abs(dest - src), α)
ltPsDifference5
 ltPsDifference5 provides "absolute difference" compositing compatible with Photoshop versions 5.x and below. The formula is slightly different from ltPsDifference.
 Neutral color is black.

Formula: result = abs(dest - src α)
ltPsExclusion
 ltPsExclusion performs Photoshop-compatible "exclusion" compositing.
 Neutral color is black.

Formula: result = blend(dest, dest + src - 2.0 src dest, α)

Alpha compositing and additive alpha compositing

 Kirikiri has two alpha compositing modes.
Alpha compositing
Specifying ltAlpha in the Layer.type property makes this display type.
ltAlpha is an alpha compositing mode used by many graphic software. This mode is suitable for directly reading data output by other graphic software.
Additive alpha synthesis
Specifying ltAddAlpha in the Layer.type property makes this display type.
 This format has the following advantages and disadvantages compared to alpha compositing.
  • Since the formula is simpler than alpha compositing, it can be displayed quickly and many drawing methods can draw fast.
  • Additive composition can be expressed together with alpha composition
  • Few graphics software support this format

Graphic software that supports the same composition mode as ltAddAlpha does not think so, so to handle the output of other software in this format with Kirikiri, output this type of image with Image format converter or use the Layer.convertType method. You need to convert from ltAlpha to this format.
 The image format converter can accept a combined input of a "normal" layer and a "dodging (linear)" layer in Photoshop format as an input for additive alpha compositing images.

Layer type, drawing method and calculation mode

 Kirikiri has a layer type (specified with a constant starting with lt), a drawing method (specified with a constant starting with df), and a calculation mode (specified with a constant starting with om).
 Although each has a similar name, the uses are divided as follows.
Layer type
 The layer type is a value specified by the Layer.type property, which specifies how the layer is displayed.
Drawing method
 The drawing method is the value specified by the Layer.face property, and specifies how to draw on the layer. If dfAuto is specified, the appropriate drawing method will be determined according to the layer type. You can also draw with a different drawing method than the best drawing method for the layer type.
 Methods that copy between layers, such as Layer.copyRect methods, are also used to select which information to copy. dfBoth (or dfAlpha or dfAddAlpha) copies both the main and the mask. For dfMain (or dfOpaque), only the main is copied. For dfMask, only the mask is copied; for dfProvince, only the area image is copied.
 Similarly, Layer.fillRect methods are used to select which information to fill. dfBoth (or dfAlpha or dfAddAlpha) fills both the main and the mask. In the case of dfMain (or dfOpaque), only the main is copy filled. For dfMask, only the mask is filled, and for dfProvince, only the area image is filled.
Calculation mode
 The calculation mode is a value specified by an argument such as the Layer.operateRect method, and a value that specifies how to handle the calculation source (layer to be overlaid). If omAuto is specified, the appropriate mode is determined according to the layer type of the calculation source.

Alpha channel protection

 If the drawing method specified by the Layer.face property is dfOpaque, the Layer.holdAlpha property can specify whether to protect the alpha channel of the drawing destination (the layer on which the method is to be executed).
 Protecting the alpha channel protects the alpha channel (opacity) and leaves transparent areas transparent.
 If you do not protect the alpha channel, the alpha channel (opacity) will be destroyed. Destruction means that you don't know what state it will be in.
 However, if the Layer.type property is not ltAlpha or ltAddAlpha, the layer's alpha channel is not used, so setting the Layer.holdAlpha property to false is usually fine. If false, many methods will draw faster than true.