MCPcopy Index your code
hub / github.com/processing/processing / convertToRGBA

Method convertToRGBA

core/src/processing/opengl/Texture.java:1001–1062  ·  view source on GitHub ↗

Reorders a pixel array in the given format into the order required by OpenGL (RGBA) and stores it into rgbaPixels. The width and height parameters are used in the YUV420 to RBGBA conversion. @param pixels int[] @param format int @param w int @param h int

(int[] pixels, int format, int w, int h)

Source from the content-addressed store, hash-verified

999 * @param h int
1000 */
1001 protected void convertToRGBA(int[] pixels, int format, int w, int h) {
1002 if (PGL.BIG_ENDIAN) {
1003 switch (format) {
1004 case ALPHA:
1005 // Converting from xxxA into RGBA. RGB is set to white
1006 // (0xFFFFFF, i.e.: (255, 255, 255))
1007 for (int i = 0; i< pixels.length; i++) {
1008 rgbaPixels[i] = 0xFFFFFF00 | pixels[i];
1009 }
1010 break;
1011 case RGB:
1012 // Converting xRGB into RGBA. A is set to 0xFF (255, full opacity).
1013 for (int i = 0; i< pixels.length; i++) {
1014 int pixel = pixels[i];
1015 rgbaPixels[i] = (pixel << 8) | 0xFF;
1016 }
1017 break;
1018 case ARGB:
1019 // Converting ARGB into RGBA. Shifting RGB to 8 bits to the left,
1020 // and bringing A to the first byte.
1021 for (int i = 0; i< pixels.length; i++) {
1022 int pixel = pixels[i];
1023 rgbaPixels[i] = (pixel << 8) | ((pixel >> 24) & 0xFF);
1024 }
1025 break;
1026 }
1027 } else {
1028 // LITTLE_ENDIAN
1029 // ARGB native, and RGBA opengl means ABGR on windows
1030 // for the most part just need to swap two components here
1031 // the sun.cpu.endian here might be "false", oddly enough..
1032 // (that's why just using an "else", rather than check for "little")
1033 switch (format) {
1034 case ALPHA:
1035 // Converting xxxA into ARGB, with RGB set to white.
1036 for (int i = 0; i< pixels.length; i++) {
1037 rgbaPixels[i] = (pixels[i] << 24) | 0x00FFFFFF;
1038 }
1039 break;
1040 case RGB:
1041 // We need to convert xRGB into ABGR,
1042 // so R and B must be swapped, and the x just made 0xFF.
1043 for (int i = 0; i< pixels.length; i++) {
1044 int pixel = pixels[i];
1045 rgbaPixels[i] = 0xFF000000 |
1046 ((pixel & 0xFF) << 16) | ((pixel & 0xFF0000) >> 16) |
1047 (pixel & 0x0000FF00);
1048 }
1049 break;
1050 case ARGB:
1051 // We need to convert ARGB into ABGR,
1052 // so R and B must be swapped, A and G just brought back in.
1053 for (int i = 0; i < pixels.length; i++) {
1054 int pixel = pixels[i];
1055 rgbaPixels[i] = ((pixel & 0xFF) << 16) | ((pixel & 0xFF0000) >> 16) |
1056 (pixel & 0xFF00FF00);
1057 }
1058 break;

Callers 1

setMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected