ov2640_specialEffect.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Workaround - bug in cam library - enable bits are set without using bitwise OR logic -> only latest enable setting is used
  2. // Reference: https://esp32.com/viewtopic.php?f=19&t=14376#p93178
  3. /* The memory structure is as follows for
  4. byte_0 = enable_bits
  5. byte_0->bit0 = enable saturation and hue --> OK
  6. byte_0->bit1 = enable saturation --> OK
  7. byte_0->bit2 = enable brightness and contrast --> OK
  8. byte_0->bit3 = enable green -> blue spitial effect (Antique and blunish and greenish and reddish and b&w) enable
  9. byte_0->bit4 = anable gray -> red spitial effect (Antique and blunish and greenish and reddish and b&w) enable
  10. byte_0->bit5 = remove (UV) in YUV color system
  11. byte_0->bit6 = enable negative
  12. byte_0->bit7 = remove (Y) in YUV color system
  13. byte_1 = saturation1 0-255 --> ?
  14. byte_2 = hue 0-255 --> OK
  15. byte_3 = saturation2 0-255 --> OK
  16. byte_4 = reenter saturation2 in documents --> ?
  17. byte_5 = spital effect green -> blue 0-255 --> ?
  18. byte_6 = spital effect gray -> red 0-255 --> ?
  19. byte_7 = contrast lower byte 0-255 --> OK
  20. byte_8 = contrast higher byte 0-255 --> OK
  21. byte_9 = brightness 0-255 --> OK
  22. byte_10 = if byte_10==4 contrast effective --> ?
  23. */
  24. #include <stdint.h>
  25. #include "esp_camera.h"
  26. #include "ov2640_specialEffect.h"
  27. static const uint8_t special_effects_regs[8][5] = {
  28. {0x7C, 0x7D, 0x7C, 0x7D, 0x7D},
  29. {0x00, 0X00, 0x05, 0X80, 0X80}, /* no effect */
  30. {0x00, 0X40, 0x05, 0X80, 0X80}, /* negative */
  31. {0x00, 0X18, 0x05, 0X80, 0X80}, /* black and white */
  32. {0x00, 0X18, 0x05, 0X40, 0XC0}, /* reddish */
  33. {0x00, 0X18, 0x05, 0X40, 0X40}, /* greenish */
  34. {0x00, 0X18, 0x05, 0XA0, 0X40}, /* blue */
  35. {0x00, 0X18, 0x05, 0X40, 0XA6}, /* retro */
  36. };
  37. int ov2640_set_special_effect(sensor_t *sensor, int effect)
  38. {
  39. int ret = 0;
  40. effect++;
  41. if (effect <= 0 || effect > 7)
  42. {
  43. effect = 1;
  44. }
  45. sensor->status.special_effect = effect - 1;
  46. int registerValue = 0x06; // enable saturation, contrast, brightness
  47. registerValue |= special_effects_regs[effect][1];
  48. // sensor->set_reg(sensor, int reg, int mask, int value)
  49. sensor->set_reg(sensor, 0xFF, 0x01, 0x00); // Select DSP bank
  50. sensor->set_reg(sensor, special_effects_regs[0][0], 0xFF, 0x00);
  51. sensor->set_reg(sensor, special_effects_regs[0][1], 0x5E, registerValue);
  52. for (int i = 2; i < 5; i++)
  53. {
  54. sensor->set_reg(sensor, special_effects_regs[0][i], 0xFF, special_effects_regs[effect][i]);
  55. }
  56. return ret;
  57. }