Home | History | Annotate | Download | only in imageproc
      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 #define ATTRIBUTE_UNUSED __attribute__((unused))
     20 
     21 int gray_to_rgb_process(const char** inputs,
     22                         const int* input_sizes,
     23                         int input_count,
     24                         char* output,
     25                         int output_size,
     26                         void* user_data ATTRIBUTE_UNUSED) {
     27   // Make sure we have exactly one input
     28   if (input_count != 1)
     29     return 0;
     30 
     31   // Make sure sizes match up
     32   if (input_sizes[0] != output_size/3)
     33     return 0;
     34 
     35   // Get the input and output pointers
     36   const char* input_ptr = inputs[0];
     37   char* output_ptr = output;
     38   if (!input_ptr || !output_ptr)
     39     return 0;
     40 
     41   // Run the conversion
     42   int i;
     43   for (i = 0; i < input_sizes[0]; ++i) {
     44     *(output_ptr++) = *(input_ptr);
     45     *(output_ptr++) = *(input_ptr);
     46     *(output_ptr++) = *(input_ptr++);
     47   }
     48 
     49   return 1;
     50 }
     51 
     52 int rgba_to_rgb_process(const char** inputs,
     53                         const int* input_sizes,
     54                         int input_count,
     55                         char* output,
     56                         int output_size,
     57                         void* user_data ATTRIBUTE_UNUSED) {
     58   // Make sure we have exactly one input
     59   if (input_count != 1)
     60     return 0;
     61 
     62   // Make sure sizes match up
     63   if (input_sizes[0]/4 != output_size/3)
     64     return 0;
     65 
     66   // Get the input and output pointers
     67   const char* input_ptr = inputs[0];
     68   char* output_ptr = output;
     69   if (!input_ptr || !output_ptr)
     70     return 0;
     71 
     72   // Run the conversion
     73   int i;
     74   for (i = 0; i < input_sizes[0] / 4; ++i) {
     75     *(output_ptr++) = *(input_ptr++);
     76     *(output_ptr++) = *(input_ptr++);
     77     *(output_ptr++) = *(input_ptr++);
     78     ++input_ptr;
     79   }
     80 
     81   return 1;
     82 }
     83 
     84 int gray_to_rgba_process(const char** inputs,
     85                          const int* input_sizes,
     86                          int input_count,
     87                          char* output,
     88                          int output_size,
     89                          void* user_data ATTRIBUTE_UNUSED) {
     90   // Make sure we have exactly one input
     91   if (input_count != 1)
     92     return 0;
     93 
     94   // Make sure sizes match up
     95   if (input_sizes[0] != output_size/4)
     96     return 0;
     97 
     98   // Get the input and output pointers
     99   const char* input_ptr = inputs[0];
    100   char* output_ptr = output;
    101   if (!input_ptr || !output_ptr)
    102     return 0;
    103 
    104   // Run the conversion
    105   int i;
    106   for (i = 0; i < input_sizes[0]; ++i) {
    107     *(output_ptr++) = *(input_ptr);
    108     *(output_ptr++) = *(input_ptr);
    109     *(output_ptr++) = *(input_ptr++);
    110     *(output_ptr++) = 255;
    111   }
    112 
    113   return 1;
    114 }
    115 
    116 int rgb_to_rgba_process(const char** inputs,
    117                         const int* input_sizes,
    118                         int input_count,
    119                         char* output,
    120                         int output_size,
    121                         void* user_data ATTRIBUTE_UNUSED) {
    122   // Make sure we have exactly one input
    123   if (input_count != 1)
    124     return 0;
    125 
    126   // Make sure sizes match up
    127   if (input_sizes[0]/3 != output_size/4)
    128     return 0;
    129 
    130   // Get the input and output pointers
    131   const char* input_ptr = inputs[0];
    132   char* output_ptr = output;
    133   if (!input_ptr || !output_ptr)
    134     return 0;
    135 
    136   // Run the conversion
    137   int i;
    138   for (i = 0; i < output_size / 4; ++i) {
    139     *(output_ptr++) = *(input_ptr++);
    140     *(output_ptr++) = *(input_ptr++);
    141     *(output_ptr++) = *(input_ptr++);
    142     *(output_ptr++) = 255;
    143   }
    144 
    145   return 1;
    146 }
    147 
    148