sn9c2028.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. static const unsigned char sn9c2028_sof_marker[] = {
  24. 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
  25. 0x00,
  26. 0x00, /* seq */
  27. 0x00,
  28. 0x00,
  29. 0x00, /* avg luminance lower 8 bit */
  30. 0x00, /* avg luminance higher 8 bit */
  31. };
  32. static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
  33. unsigned char *m, int len)
  34. {
  35. struct sd *sd = (struct sd *) gspca_dev;
  36. int i;
  37. /* Search for the SOF marker (fixed part) in the header */
  38. for (i = 0; i < len; i++) {
  39. if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) ||
  40. (sd->sof_read > 5)) {
  41. sd->sof_read++;
  42. if (sd->sof_read == 11)
  43. sd->avg_lum_l = m[i];
  44. if (sd->sof_read == 12)
  45. sd->avg_lum = (m[i] << 8) + sd->avg_lum_l;
  46. if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
  47. PDEBUG(D_FRAM,
  48. "SOF found, bytes to analyze: %u."
  49. " Frame starts at byte #%u",
  50. len, i + 1);
  51. sd->sof_read = 0;
  52. return m + i + 1;
  53. }
  54. } else {
  55. sd->sof_read = 0;
  56. }
  57. }
  58. return NULL;
  59. }