vendredi 12 juillet 2024

Red Image datatype

REBOL/View 1.3

In REBOL/View 1.3 it was necessary to redesign the image datatype in order to make image operations more consistent and less system dependent.The image datatype is structured as a standard REBOL series. It has a head, a tail, and can be positioned to any point in-between. In additional, the new image datatype allows two dimensional positioning and sizing through the use of an X Y pair. (http://www.rebol.com/docs/image.html#section-1). Attention: first pixel coordinates is 0x0 and first pixel index is 1!

Red

In Red, image datatype is a series-like. This means that some series functions are not working. 

Making images

img1: make image! reduce [200x100 red]         :--REBOL/View and Red

With transparency

img3: make image! reduce [50x50 blue 128]                 :--REBOL/View

img3: make image! reduce [50x50 blue + 0.0.0.128]    ;--Red

Copy images

The COPY function works in the standard way as it does with all series, making an exact copy of the image provided.

i1: make image! reduce [200x100 red]

i2: copy i1 ;--REBOL/View and Red

i2: copy/part i1 5x5                 ;--REBOL/View and Red

i2: copy/part skip i1 4x4 5x5                 ;--REBOL/View and Red

i2: copy/part skip i1 2x2 (i1/size - 4x4)                         ;--REBOL/View and Red

Traversing Images (Indexing) 

You can use all the standard series functions to index to any position within an image series. The functions include: HEAD, TAIL, NEXT, BACK, SKIP, AT, and others. 

i2: next i2 ; move to next pixel                                         ;--REBOL/View and Red

i2: back i2 ; move to prior pixel                                        ;--REBOL/View and Red

i2: head i2 ; move to first pixel                                         ;--REBOL/View and Red 

i2: tail i2 ; move just past the last pixel                            ;--REBOL/View and Red

i2: back tail i2 ; move to the last pixel                             ;--REBOL/View and Red

Modifying Images 

Images can be modified in two ways. They can be modified as individual pixels (with poke function) or they can be modified as a series of pixels. 

 change at img1 1x1 img2                                                   --REBOL/View and Red

change/dup at img1 10x20 blue 40x30                               ; --REBOL/View

append img1 img2 ; uses insert ;                                         ;--REBOL/View

remove/part img1 img1/size/x                                             ;--REBOL/View

remove/part tail img1 negate img1/size/x                            ;--REBOL/View

 insert/part img1 blue img1/size/x                                        ;--REBOL/View


Searching Images

pos: find img1 red             ;--REBOL/View


Image Comparison

The EQUAL?, NOT-EQUAL?, and SAME? series comparison functions work for images in the same way as they do for other series datatypes.

ANDing, ORing, and XORing Images

Partially supported by Red, but supported by redCV

img1 AND img2 ;--REBOL/View

img1/rgb AND img2/rgb ;--Red


Aucun commentaire:

Enregistrer un commentaire