1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <stdlib.h> 18 19 int gray_to_rgb_process(const char** inputs, 20 const int* input_sizes, 21 int input_count, 22 char* output, 23 int output_size, 24 void* user_data) { 25 // Make sure we have exactly one input 26 if (input_count != 1) 27 return 0; 28 29 // Make sure sizes match up 30 if (input_sizes[0] != output_size/3) 31 return 0; 32 33 // Get the input and output pointers 34 const char* input_ptr = inputs[0]; 35 char* output_ptr = output; 36 if (!input_ptr || !output_ptr) 37 return 0; 38 39 // Run the conversion 40 int i; 41 for (i = 0; i < input_sizes[0]; ++i) { 42 *(output_ptr++) = *(input_ptr); 43 *(output_ptr++) = *(input_ptr); 44 *(output_ptr++) = *(input_ptr++); 45 } 46 47 return 1; 48 } 49 50 int rgba_to_rgb_process(const char** inputs, 51 const int* input_sizes, 52 int input_count, 53 char* output, 54 int output_size, 55 void* user_data) { 56 // Make sure we have exactly one input 57 if (input_count != 1) 58 return 0; 59 60 // Make sure sizes match up 61 if (input_sizes[0]/4 != output_size/3) 62 return 0; 63 64 // Get the input and output pointers 65 const char* input_ptr = inputs[0]; 66 char* output_ptr = output; 67 if (!input_ptr || !output_ptr) 68 return 0; 69 70 // Run the conversion 71 int i; 72 for (i = 0; i < input_sizes[0] / 4; ++i) { 73 *(output_ptr++) = *(input_ptr++); 74 *(output_ptr++) = *(input_ptr++); 75 *(output_ptr++) = *(input_ptr++); 76 ++input_ptr; 77 } 78 79 return 1; 80 } 81 82 int gray_to_rgba_process(const char** inputs, 83 const int* input_sizes, 84 int input_count, 85 char* output, 86 int output_size, 87 void* user_data) { 88 // Make sure we have exactly one input 89 if (input_count != 1) 90 return 0; 91 92 // Make sure sizes match up 93 if (input_sizes[0] != output_size/4) 94 return 0; 95 96 // Get the input and output pointers 97 const char* input_ptr = inputs[0]; 98 char* output_ptr = output; 99 if (!input_ptr || !output_ptr) 100 return 0; 101 102 // Run the conversion 103 int i; 104 for (i = 0; i < input_sizes[0]; ++i) { 105 *(output_ptr++) = *(input_ptr); 106 *(output_ptr++) = *(input_ptr); 107 *(output_ptr++) = *(input_ptr++); 108 *(output_ptr++) = 255; 109 } 110 111 return 1; 112 } 113 114 int rgb_to_rgba_process(const char** inputs, 115 const int* input_sizes, 116 int input_count, 117 char* output, 118 int output_size, 119 void* user_data) { 120 // Make sure we have exactly one input 121 if (input_count != 1) 122 return 0; 123 124 // Make sure sizes match up 125 if (input_sizes[0]/3 != output_size/4) 126 return 0; 127 128 // Get the input and output pointers 129 const char* input_ptr = inputs[0]; 130 char* output_ptr = output; 131 if (!input_ptr || !output_ptr) 132 return 0; 133 134 // Run the conversion 135 int i; 136 for (i = 0; i < output_size / 4; ++i) { 137 *(output_ptr++) = *(input_ptr++); 138 *(output_ptr++) = *(input_ptr++); 139 *(output_ptr++) = *(input_ptr++); 140 *(output_ptr++) = 255; 141 } 142 143 return 1; 144 } 145 146