165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn/*
265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Copyright (C) 2011 The Android Open Source Project
365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Licensed under the Apache License, Version 2.0 (the "License");
565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * you may not use this file except in compliance with the License.
665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * You may obtain a copy of the License at
765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *      http://www.apache.org/licenses/LICENSE-2.0
965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
1065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Unless required by applicable law or agreed to in writing, software
1165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * distributed under the License is distributed on an "AS IS" BASIS,
1265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * See the License for the specific language governing permissions and
1465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * limitations under the License.
1565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn */
1665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
1765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn#include <android/log.h>
1865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
19e5160e7e59f96aa457e7a4217197150086e8b7caAndreas Gampe#define ATTRIBUTE_UNUSED __attribute__((unused))
20e5160e7e59f96aa457e7a4217197150086e8b7caAndreas Gampe
2165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennint invert_process(const char** inputs,
2265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                   const int* input_sizes,
2365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                   int input_count,
2465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                   char* output,
2565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                   int output_size,
26e5160e7e59f96aa457e7a4217197150086e8b7caAndreas Gampe                   void* user_data ATTRIBUTE_UNUSED) {
2765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  // Make sure we have exactly one input
2865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  if (input_count != 1)
2965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    return 0;
3065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
3165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  // Make sure sizes match up
3265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  if (input_sizes[0] != output_size)
3365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    return 0;
3465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
3565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  // Get the input and output pointers
3665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  const char* input_ptr = inputs[0];
3765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  char* output_ptr = output;
3865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  if (!input_ptr || !output_ptr)
3965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    return 0;
4065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
4165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  // Run the inversion
4265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  int i;
4365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  for (i = 0; i < output_size; ++i)
4465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    *(output_ptr++) = 255 - *(input_ptr++);
4565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
4665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn  return 1;
4765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn}
4865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
49