How do I detect if PDF image is using JPXDecode? Also how to I get the base color space of this image?

Q: How do I detect if PDF image is using JPXDecode?
Also how to I get the base color space for JPXDecode image?
---------------------------------
A: In case of JPXDecode, Image.GetColorSpace() always returns RGB.
This is because in this case the image filter always normalizes data
to RGB. If you are simply interested in the underlying color space of
JPX image you could use the following approach:

bool IsJPX(Image image) {
      Obj xobject = image.GetSDFObj();
  Obj f = xobject.FindObj("Filter");
  if (f == null) return false;
  if (f.IsName()) return f.GetName() == "JPXDecode";
  else if (f.IsArray()) {
    int sz = int(f.Size());
    for (int i=0; i<sz; ++i) {
      if (f.GetAt(i).IsName() && f->GetAt(i)->GetName() == "JPXDecode") {
        return true;
      }
    }
  }
  return false;
}

if (image.IsJPX()) {
  Obj xobject = image.GetSDFObj();
  Obj cs_obj = xobject.FindObj("ColorSpace");
  if (f != cs_obj) {
     ColorSpace cs = new ColorSpace(cs_obj);
     ColorSpace.Type type = cs.GetType();
  }
}