From 7d4cdf5417e7fc800b2c51c0adce91e7888d0359 Mon Sep 17 00:00:00 2001 From: simonbachmann Date: Sun, 18 Jun 2017 16:17:29 +0000 Subject: Changed from #ARGB to #RGBA color format --- doc/photo.n | 16 +++++++-------- generic/tkImgListFormat.c | 50 +++++++++++++++++++++++------------------------ tests/imgListFormat.test | 44 ++++++++++++++++++++--------------------- tests/imgPhoto.test | 12 ++++++------ 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/doc/photo.n b/doc/photo.n index ea52ec5..69d156b 100644 --- a/doc/photo.n +++ b/doc/photo.n @@ -530,8 +530,8 @@ The built-in handlers support these suboptions: The option is allowed when writing image data to a string with \fIimageName\fR \fBdata\fR. Specifies the format to use for the color string of each pixel. \fIformatType\fR may be one of: \fBrgb\fR to -encode pixel data in the form \fB#\fIRRGGBB\fR, \fBargb\fR to encode -pixel data in the form \fB#\fIAARRGGBB\fR or \fBlist\fR to encode +encode pixel data in the form \fB#\fIRRGGBB\fR, \fBrgba\fR to encode +pixel data in the form \fB#\fIRRGGBBAA\fR or \fBlist\fR to encode pixel data as a list with four elements. See \fBCOLOR FORMATS\fR below for details. The default is \fBrgb\fR. .VE 8.7 @@ -590,14 +590,14 @@ A Tcl list with three or four integers in the range 0 to 255, specifying the values for the red, green, blue and (optionally) alpha channels respectively. .IP \(bu 3 -\fB#\fR\fIARGB\fR format: a \fB#\fR followed by four hexadecimal digits, -where each digit is the value for the alpha, red, green and blue +\fB#\fR\fIRGBA\fR format: a \fB#\fR followed by four hexadecimal digits, +where each digit is the value for the red, green, blue and alpha channels respectively. Each digit will be expanded internally to -8-bits by multiplication by 0x11. +8 bits by multiplication by 0x11. .IP \(bu 3 -\fB#\fR\fIAARRGGBB\fR format: \fB#\fR followed by eight hexadecimal digits, -where two subsequent digits represent the value for the alpha, red, green -and blue channels respectively. +\fB#\fR\fIRRGGBBAA\fR format: \fB#\fR followed by eight hexadecimal digits, +where each pair of subsequent digits represents the value for the red, +green, blue and alpha channels respectively. .VE 8.7 .SH "COLOR ALLOCATION" .PP diff --git a/generic/tkImgListFormat.c b/generic/tkImgListFormat.c index 2c6c58a..20f2c4e 100644 --- a/generic/tkImgListFormat.c +++ b/generic/tkImgListFormat.c @@ -47,7 +47,7 @@ #define TK_PHOTO_MAX_COLOR_CHARS 99 /* - * "Names" for the different formats of a color string. + * Symbols for the different formats of a color string. */ enum ColorFormatType { @@ -56,8 +56,8 @@ enum ColorFormatType { COLORFORMAT_LIST, COLORFORMAT_RGB1, COLORFORMAT_RGB2, - COLORFORMAT_ARGB1, - COLORFORMAT_ARGB2 + COLORFORMAT_RGBA1, + COLORFORMAT_RGBA2 }; /* @@ -71,8 +71,8 @@ static const char *const colorFormatNames[] = { "list", "rgb-short", "rgb", - "argb-short", - "argb", + "rgba-short", + "rgba", NULL }; @@ -259,9 +259,9 @@ ParseFormatOptions( TCL_EXACT, &typeIndex) != TCL_OK || (typeIndex != COLORFORMAT_LIST && typeIndex != COLORFORMAT_RGB2 - && typeIndex != COLORFORMAT_ARGB2) ) { + && typeIndex != COLORFORMAT_RGBA2) ) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad color format " - "\"%s\": must be rgb, argb, or list", + "\"%s\": must be rgb, rgba, or list", Tcl_GetString(objv[index]))); Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_COLOR_FORMAT", NULL); @@ -565,7 +565,7 @@ StringReadDef( */ if (Tcl_ListObjGetElements(interp, rowListPtr[y], &curColCount, - &colListPtr) != TCL_OK) { + &colListPtr) != TCL_OK) { goto errorExit; } for (x = srcX; x < colCount; x++) { @@ -679,7 +679,7 @@ StringWriteDef( } /* - * We don't build lines as a list for #ARGB and #RGB. Since + * We don't build lines as a list for #RGBA and #RGB. Since * these color formats look like comments, the first element * of the list would get quoted with an additional {} . * While this is not a problem if the data is used as @@ -693,10 +693,10 @@ StringWriteDef( pixelPtr[greenOffset], pixelPtr[blueOffset]); Tcl_DStringAppend(&line, colorBuf, -1); break; - case COLORFORMAT_ARGB2: - sprintf(colorBuf, "#%02x%02x%02x%02x ", alphaVal, + case COLORFORMAT_RGBA2: + sprintf(colorBuf, "#%02x%02x%02x%02x ", pixelPtr[0], pixelPtr[greenOffset], - pixelPtr[blueOffset]); + pixelPtr[blueOffset], alphaVal); Tcl_DStringAppend(&line, colorBuf, -1); break; case COLORFORMAT_LIST: @@ -718,7 +718,7 @@ StringWriteDef( } if (opts.colorFormat != COLORFORMAT_LIST) { /* - * For the #XXX formats, we need to remvoe the last + * For the #XXX formats, we need to remove the last * whitespace. */ @@ -775,7 +775,7 @@ ParseColor( int charCount; /* - * Try to guess the color format + * Find out which color format we have */ specString = Tcl_GetStringFromObj(specObj, &charCount); @@ -899,7 +899,7 @@ ParseColorAsList( * * This function extracts color and alpha values from a string * starting with '#', followed by hex digits. It undestands both - * the #ARGB form and the #RBG (with optional suffix) + * the #RGBA form and the #RBG (with optional suffix) * * Results: * On success, writes red, green, blue and alpha values to the @@ -946,18 +946,18 @@ ParseColorAsHex( colorValue = strtoul(colorString + 1, NULL, 16); switch (colorStrLen - 1) { case 4: - /* #ARGB format */ - *alphaPtr = (unsigned char) ((colorValue >> 12) * 0x11); - *redPtr = (unsigned char) (((colorValue >> 8) & 0xf) * 0x11); - *greenPtr = (unsigned char) (((colorValue >> 4) & 0xf) * 0x11); - *bluePtr = (unsigned char) ((colorValue & 0xf) * 0x11); + /* #RGBA format */ + *redPtr = (unsigned char) ((colorValue >> 12) * 0x11); + *greenPtr = (unsigned char) (((colorValue >> 8) & 0xf) * 0x11); + *bluePtr = (unsigned char) (((colorValue >> 4) & 0xf) * 0x11); + *alphaPtr = (unsigned char) ((colorValue & 0xf) * 0x11); return TCL_OK; case 8: - /* #AARRGGBB format */ - *alphaPtr = (unsigned char) (colorValue >> 24); - *redPtr = (unsigned char) ((colorValue >> 16) & 0xff); - *greenPtr = (unsigned char) ((colorValue >> 8) & 0xff); - *bluePtr = (unsigned char) (colorValue & 0xff); + /* #RRGGBBAA format */ + *redPtr = (unsigned char) (colorValue >> 24); + *greenPtr = (unsigned char) ((colorValue >> 16) & 0xff); + *bluePtr = (unsigned char) ((colorValue >> 8) & 0xff); + *alphaPtr = (unsigned char) (colorValue & 0xff); return TCL_OK; default: Tcl_Panic("unexpected switch fallthrough"); diff --git a/tests/imgListFormat.test b/tests/imgListFormat.test index 02f4988..c9dca56 100644 --- a/tests/imgListFormat.test +++ b/tests/imgListFormat.test @@ -2,7 +2,7 @@ # ("list format") implementend in the file tkImgListFormat.c. # It is organized in the standard fashion for Tcl tests. # -# Copyright (c) ??? +# Copyright (c) 2017 Simon Bachmann # All rights reserved. # # Author: Simon Bachmann (simonbachmann@bluewin.ch) @@ -67,19 +67,19 @@ test imgListFormat-1.6 {ParseFormatOptions: bad -colorformat val #1} -setup { } -cleanup { imageCleanup } -returnCodes error -result \ - {bad color format "bogus": must be rgb, argb, or list} + {bad color format "bogus": must be rgb, rgba, or list} test imgListFormat-1.7 {ParseFormatOptions: bad -colorformat val #2} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat tkcolor} } -returnCodes error -result \ - {bad color format "tkcolor": must be rgb, argb, or list} + {bad color format "tkcolor": must be rgb, rgba, or list} test imgListFormat-1.8 {ParseFormatOptions: bad -colorformat #3} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat emptystring} } -returnCodes error -result \ - {bad color format "emptystring": must be rgb, argb, or list} + {bad color format "emptystring": must be rgb, rgba, or list} test imgListFormat-1.9 {ParseFormatOptions: bad -colorformat #4} -setup { image create photo photo1 } -body { @@ -87,26 +87,26 @@ test imgListFormat-1.9 {ParseFormatOptions: bad -colorformat #4} -setup { } -cleanup { imageCleanup } -returnCodes error -result \ - {bad color format "rgb-short": must be rgb, argb, or list} + {bad color format "rgb-short": must be rgb, rgba, or list} test imgListFormat-1.10 {ParseFormatOptions: bad -colorformat #5} -setup { image create photo photo1 } -body { - photo1 data -format {default -colorformat argb-short} + photo1 data -format {default -colorformat rgba-short} } -returnCodes error -result \ - {bad color format "argb-short": must be rgb, argb, or list} + {bad color format "rgba-short": must be rgb, rgba, or list} test imgListFormat-1.11 {valid colorformats} -setup { image create photo photo1 } -body { photo1 put white#78 set result {} lappend result [photo1 data -format {default -colorformat rgb}] - lappend result [photo1 data -format {default -colorformat argb}] + lappend result [photo1 data -format {default -colorformat rgba}] lappend result [photo1 data -format {default -colorformat list}] set result } -cleanup { imageCleanup unset result -} -result {{{#ffffff}} {{#78ffffff}} {{{255 255 255 120}}}} +} -result {{{#ffffff}} {{#ffffff78}} {{{255 255 255 120}}}} # GetBadOptMsg: only use case already tested with imgListFormat-1.4 @@ -195,7 +195,7 @@ test imgListFormat-4.5 {StringReadDef: correct compositing rule} -constraints { image create photo photo2 } -body { photo2 put #FF0000 -to 0 0 50 50 - photo2 put [photo1 data -format {default -colorformat argb}] -to 10 10 40 40 + photo2 put [photo1 data -format {default -colorformat rgba}] -to 10 10 40 40 list [photo2 get 0 0 -withalpha] [photo2 get 20 25 -withalpha] \ [photo2 get 49 49 -withalpha] } -cleanup { @@ -227,7 +227,7 @@ test imgListFormat-5.3 {StringWriteDef: non-option arg in format} -setup { test imgListFormat-5.4 {StringWriteDef: empty image} -setup { image create photo photo1 } -body { - photo1 data -format {default -colorformat argb} + photo1 data -format {default -colorformat rgba} } -cleanup { imageCleanup } -result {} @@ -266,7 +266,7 @@ test imgListFormat-5.7 {StringWriteDef: test some pixels #2} -constraints { set result {} image create photo photo1 -file $teapotPhotoFile } -body { - set imgData [photo1 data -format {default -colorformat argb}] + set imgData [photo1 data -format {default -colorformat rgba}] # note: with [lindex], the coords are inverted (y x) lappend result [lindex $imgData 0 0] lappend result [lindex $imgData 3 2] @@ -278,7 +278,7 @@ test imgListFormat-5.7 {StringWriteDef: test some pixels #2} -constraints { unset result unset imgData imageCleanup -} -result {{#ff135cc0} #ff135cc0 #ffa06d52 #ffe1c8ba #ff135cc0} +} -result {{#135cc0ff} #135cc0ff #a06d52ff #e1c8baff #135cc0ff} test imgListFormat-5.8 {StringWriteDef: test some pixels #3} -constraints { hasTranspTeapotPhoto } -setup { @@ -300,7 +300,7 @@ test imgListFormat-5.9 {StringWriteDef: test some pixels #4} -constraints { } -setup { image create photo photo1 -file $transpTeapotPhotoFile } -body { - set imgData [photo1 data -format {default -colorformat argb}] + set imgData [photo1 data -format {default -colorformat rgba}] set result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] @@ -309,7 +309,7 @@ test imgListFormat-5.9 {StringWriteDef: test some pixels #4} -constraints { unset result unset imgData imageCleanup -} -result {{#e1004eb9} #aaa14100 #afffca9f} +} -result {{#004eb9e1} #a14100aa #ffca9faf} test imgListFormat-5.10 {StringWriteDef: test some pixels #5} -constraints { hasTranspTeapotPhoto } -setup { @@ -364,10 +364,10 @@ test imgListFormat-6.4 {ParseColor: #XXX color, different forms} -setup { image create photo photo1 } -body { photo1 put {{#A123 #334455} {#012 #fffefd#00}} - photo1 data -format {default -colorformat argb} + photo1 data -format {default -colorformat rgba} } -cleanup { imageCleanup -} -result {{#aa112233 #ff334455} {#ff001122 #00fffefd}} +} -result {{#aa112233 #334455ff} {#001122ff #fffefd00}} test imgListFormat-6.5 {ParseColor: list format} -setup { image create photo photo1 } -body { @@ -399,7 +399,7 @@ test imgListFormat-6.8 {ParseColor: overall test} -setup { {snow@0.5 snow#80 snow#8 #fffffafafafa@0.5 #fffffabbfacc#8} {#fffffafffaff#80 #ffffaafaa@.5 #ffffaafaa#8 #ffffaafaa#80 #fee#8} {#fee#80 #fee@0.5 #fffafa@0.5 #fffafa#8 #fffafa#80} - {{0xff 250 0xfa 128} {255 250 250} #8fee #80fffafa snow}} + {{0xff 250 0xfa 128} {255 250 250} #fee8 #fffafa80 snow}} for {set y 0} {$y < 4} {incr y} { for {set x 0} {$x < 5} {incr x} { lappend result [photo1 get $x $y -withalpha] @@ -482,10 +482,10 @@ test imgListFormat-7.9 {ParseColorAsList: additional spaces in list} -setup { image create photo photo1 } -body { photo1 put { { { 1 2 3} {1 2 3} } { {1 2 3 } { 1 2 3 4 } } } - photo1 data -format {default -colorformat argb} + photo1 data -format {default -colorformat rgba} } -cleanup { imageCleanup -} -result {{#ff010203 #ff010203} {#ff010203 #04010203}} +} -result {{#010203ff #010203ff} {#010203ff #01020304}} test imgListFormat-7.10 {ParseColorAsList: list format, string rep} -setup { image create photo photo1 } -body { @@ -518,10 +518,10 @@ test imgListFormat-8.3 {ParseColorAsHex: RGB with suffix, 8 chars} -setup { } -cleanup { imageCleanup } -result {{#ffffff #abcdef}} -test imgListFormat-8.4 {ParseColor: valid #ARGB color} -setup { +test imgListFormat-8.4 {ParseColor: valid #RGBA color} -setup { image create photo photo1 } -body { - photo1 put {{#0d9bd502 #F7ac}} + photo1 put {{#9bd5020d #7acF}} list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] } -cleanup { imageCleanup diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index b643344..ceee0c0 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -1144,8 +1144,8 @@ test imgPhoto-4.96 {ImgPhotoCmd put: "default" handler is selected} -setup { lappend result [list [image width photo1] [image height photo1]] lappend result [list [image width photo2] [image height photo2]] lappend result [string equal \ - [photo1 data -format "default -colorformat argb"] \ - [photo2 data -format "default -colorformat argb"]] + [photo1 data -format "default -colorformat rgba"] \ + [photo2 data -format "default -colorformat rgba"]] set result } -cleanup { imageCleanup @@ -1312,11 +1312,11 @@ test imgPhoto-4.115 {ImgPhotoCmd data: rgb colorformat} -setup { } -body { photo1 data -format {default -colorformat rgb} } -result {{#ff0000 #008000} {#0000ff #ffffff}} -test imgPhoto-4.116 {ImgPhotoCmd data: argb colorformat} -setup { +test imgPhoto-4.116 {ImgPhotoCmd data: rgba colorformat} -setup { image create photo photo1 -data {{red green} {blue white}} } -body { - photo1 data -format {default -colorformat argb} -} -result {{#ffff0000 #ff008000} {#ff0000ff #ffffffff}} + photo1 data -format {default -colorformat rgba} +} -result {{#ff0000ff #008000ff} {#0000ffff #ffffffff}} test imgPhoto-4.117 {ImgPhotoCmd data: list colorformat} -setup { image create photo photo1 -data {{red#a green} {blue#c white#d}} } -body { @@ -1336,7 +1336,7 @@ test imgPhoto-4.118 {ImgPhotoCmd data: using data for new image set result {} # We don't test gif here, as there seems to be a problem with # data and gif format ("too many colors", probably a bug) - foreach fmt {ppm png {default -colorformat argb} \ + foreach fmt {ppm png {default -colorformat rgba} \ {default -colorformat list}} { set imgData [teapotTransp data -format $fmt] photo1 blank -- cgit v0.12