sn9c2028.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * SN9C2028 common functions
  3. *
  4. * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu>
  5. *
  6. * Based closely upon the file gspca/pac_common.h
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. static const unsigned char sn9c2028_sof_marker[] = {
  20. 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
  21. 0x00,
  22. 0x00, /* seq */
  23. 0x00,
  24. 0x00,
  25. 0x00, /* avg luminance lower 8 bit */
  26. 0x00, /* avg luminance higher 8 bit */
  27. };
  28. static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
  29. unsigned char *m, int len)
  30. {
  31. struct sd *sd = (struct sd *) gspca_dev;
  32. int i;
  33. /* Search for the SOF marker (fixed part) in the header */
  34. for (i = 0; i < len; i++) {
  35. if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) ||
  36. (sd->sof_read > 5)) {
  37. sd->sof_read++;
  38. if (sd->sof_read == 11)
  39. sd->avg_lum_l = m[i];
  40. if (sd->sof_read == 12)
  41. sd->avg_lum = (m[i] << 8) + sd->avg_lum_l;
  42. if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
  43. PDEBUG(D_FRAM,
  44. "SOF found, bytes to analyze: %u."
  45. " Frame starts at byte #%u",
  46. len, i + 1);
  47. sd->sof_read = 0;
  48. return m + i + 1;
  49. }
  50. } else {
  51. sd->sof_read = 0;
  52. }
  53. }
  54. return NULL;
  55. }